Firstly, some minor corrections and additions to the Java profiling section. The corrections mainly concern a couple of typos that crept into the variable names of the examples. Readers should be reassured that the code, like that of the site in general, is copied and pasted from working, live profiling code. But things such as variable names are occasionally changed or shortened for the purposes of making it clearer on the site, and that seems to be where the errors crept in. I've also taken the opportunity to add a few links to other sections of the site (such as the section on threading, sleep() and yield()) that were added since the profiling tutorial was written.
Readers interested in Java profiling may also be interested in the first page of an upcoming section on Java and memory. This first page looks at how to find out the memory usage of a Java object. The technique involves using the Java Instrumentation framework introduced in version 5 of the language to query the JVM directly for the size of an object. Although slightly fiddly to set up, the technique has the advantage that there's less guesswork involved than if we were to just estimate an object's size (although future pages in the section will nonetheless look at estimation).
The Javamex companion blog. This blog includes both technical articles relating to the programming information that you'll find on the Javamex site, plus information covering the IT industry more generally.
Thursday, December 25, 2008
Wednesday, December 10, 2008
RSS feeds of Java tutorials
The Javamex web site now publishes various RSS feeds containing links to articles published recently or on particular topics of frequent interest. The available feeds are as follows:
- Main RSS feed: all Java programming articles published in the past 3 months
- Java threading feed: recent articles on multithreading and concurrency (including both "classical" thread programming and the Java 5+ concurrency libraries)
- Java Web programming feed: articles on topics such as Servlets and AJAX programming
- Java collections and algorithms feed: articles covering the Java collections framework itself, plus other algorithm-related frameworks such as compression
- Java performance feed: performance and profiling-related articles
- Java Regular expressions feed
Friday, December 5, 2008
New section: using threads in Java
The first articles in this new section look primarily at how to use "raw" threads in Java. As well as the basics such as how to create a thread and stop or interrupt it, the section looks at more advanced threading topics such as:
How threads work
A look at threads "under the hood": an examination of some of the details of thread scheduling, and the implications of different scheduling algorithms for Java threads and the methods that control them.
Thread priorities
How they work (or rather, how they don't work...) on specific operating systems. Did you know, for example:
sleep() and yield()
Information on the limitations and behaviour of sleep() under different load, sleep granularity, and bugs in the Windows implementation. And finally, find out what yield() actually does...!
Suggestions welcome!
As with all sections of the Javamex site, suggestions are very welcome here for new topics or specific questions you'd like to see answered. Updates and additions will be added periodically. Corrections are also very welcome since, particularly in the case of the some of the threading topics, I have tried to pull together information which is elusive or described in contradictory ways in different sources!
How threads work
A look at threads "under the hood": an examination of some of the details of thread scheduling, and the implications of different scheduling algorithms for Java threads and the methods that control them.
Thread priorities
How they work (or rather, how they don't work...) on specific operating systems. Did you know, for example:
- on Linux, setPriority() has no effect pre Java 6, and that even then you need to run as rootand use a special command-line flag?
- on Windows, the implementation of setPriority() changed between Sun's Java 5 and Java 6 implementations?
- on Windows, thread priorities have little effect on threads competing for CPU?
sleep() and yield()
Information on the limitations and behaviour of sleep() under different load, sleep granularity, and bugs in the Windows implementation. And finally, find out what yield() actually does...!
Suggestions welcome!
As with all sections of the Javamex site, suggestions are very welcome here for new topics or specific questions you'd like to see answered. Updates and additions will be added periodically. Corrections are also very welcome since, particularly in the case of the some of the threading topics, I have tried to pull together information which is elusive or described in contradictory ways in different sources!
Labels:
Java,
multithreading,
parallelism,
scheduling,
threading,
threads
Wednesday, November 19, 2008
What is the Java equivalent of...?
If you're a C/C++ programmer who has more recently moved into Java, you may welcome a new section of the Javamex site loosely entitled What is the Java equivalent of...?
The section aims to examine Java equivalents of some of those awkward little features of C/C++ that people tend to miss or not know how to achieve when they migrate to Java. For example:
What is the Java equivalent of unsigned? In C/C++, you can tell the compiler to treat an integer variable as unsigned by adding the unsigned modifier to its declaration. In Java, integer primitives are generally unsigned. But as we see, bitwise operations generally only require the right shift operator to be modified (so that Java uses >>> where C/C++ uses >> to operate on unsigned values). And for arithmetic operations, judicious use of the AND operator can often get us round the problem.
What is the Java equivalent of const? In C/C++, this operator tells the compiler not to allow the variable in question (or the value it points to) to be modified. We discuss the nearest Java equivalents, which actually depend on the circumstances.
The section on memory management in Java vs C/C++ looks at equivalents of operators such as new and malloc(), and their opposites. We see that in general, C/C++ puts more burden on the programmer to deal with memory management issues. Possible C/C++ bugs relating to memory management include allocating memory on the stack and then letting it "escape" the function; such bugs are not possible in Java. But there are issues that do crop up in Java that we sometimes need to be aware of, such as how garbage collection object finalization works, or how to deal with a "raw" block of memory (one typical use of malloc() in C/C++).
If you have a suggestion for a new topic in the Java equivalents section, please leave an appropriate comment on this blog. Corrections or suggestions for the existing articles are always welcome too!
The section aims to examine Java equivalents of some of those awkward little features of C/C++ that people tend to miss or not know how to achieve when they migrate to Java. For example:
What is the Java equivalent of unsigned? In C/C++, you can tell the compiler to treat an integer variable as unsigned by adding the unsigned modifier to its declaration. In Java, integer primitives are generally unsigned. But as we see, bitwise operations generally only require the right shift operator to be modified (so that Java uses >>> where C/C++ uses >> to operate on unsigned values). And for arithmetic operations, judicious use of the AND operator can often get us round the problem.
What is the Java equivalent of const? In C/C++, this operator tells the compiler not to allow the variable in question (or the value it points to) to be modified. We discuss the nearest Java equivalents, which actually depend on the circumstances.
The section on memory management in Java vs C/C++ looks at equivalents of operators such as new and malloc(), and their opposites. We see that in general, C/C++ puts more burden on the programmer to deal with memory management issues. Possible C/C++ bugs relating to memory management include allocating memory on the stack and then letting it "escape" the function; such bugs are not possible in Java. But there are issues that do crop up in Java that we sometimes need to be aware of, such as how garbage collection object finalization works, or how to deal with a "raw" block of memory (one typical use of malloc() in C/C++).
If you have a suggestion for a new topic in the Java equivalents section, please leave an appropriate comment on this blog. Corrections or suggestions for the existing articles are always welcome too!
Tuesday, October 28, 2008
Section on Java Servlets
The newly updated section on writing Java Servlets, looks at issues such as the following:
Comments and suggestions for extra material are always welcome, of course!
- some of the "mechanics" of getting start with Servlets, such as getting the appropriate version of the JDK and some Servlet hosting tips such as the features and quotas that you should be looking out for in a Servlet hosting package
- the anatomy of an example Servlet
- dealing with HTTP sessions, and why you should use the Java Session API to handle them;
- dealing with "raw" cookies when you need them;
- deciding if you need to modify your Servlet to work with keep-alive connections: in some configurations, you may be beneficial to add some code to set the Content-Length header; we discuss how to find out if this is necessary.
Comments and suggestions for extra material are always welcome, of course!
Tuesday, August 12, 2008
Improvements to section on 'volatile'
The site's section on the Java volatile keyword has been expanded to include information such as:
- a tabular comparison of volatile and synchronized
- the definition of volatile and its significante under Java 5
- clearer guidance on when to use volatile.
Saturday, August 9, 2008
New section on sorting
A new section on sorting has been added to the Java Collections section of the web site. The section currently contains information on:
- Intrudction on sorting
- Simple sorting of strings (sorting a list or array of "naturally sortable" objects)
- The Comparable interface, used to dictate the "natural sort order" of objects
- The false economy of compreTo optimisations
- Comparators, used to dicate the sort order for a particular sort, or for classes whose sort order can't otherwise be specified.
- An analysis of Java's sort algorithm, including a look at its performance.
Subscribe to:
Posts (Atom)