Core Java Technology Section Index | Page 6
How do I configure a default handler for exceptions that happen in all threads?
The setDefaultUncaughtExceptionHandler() method of Thread, introduced in JDK 5.0, allows you to configure this behavior by letting you attach an implementation of Thread.UncaughtExceptionHandler. more
How do I make a copy of an array?
The arraycopy method of System allows you to do this but... starting in Java 6, there is a new copyOf() method added to the Arrays class that is slightly more flexible.
Where can I find Java 6, aka Mustang?
Early access versions of Mustang are available at https://mustang.dev.java.net/.
How do I set the execute attribute of a file?
Assuming you are on a platform that supports the attribute, you can call the setExecutable() method of File. Of course, you'll need to wait for Java 6 to do this. Prior versions of standard Java d...more
How can I accept a password from the console without an echo? - Java 6
How can I accept a password from the console without an echo?
How do I print high-order characters to the console? Whenever I use System.out.println(), it chops off anything above seven bits.
System.out is an OutputStream. You need to work with a Writer object. With Java 6, you would use the printf() method of the new Console class, which is returned by the console() method of System.more
How do I use Java to ping a host?
Starting with Java 5, there is an isReachable() method in the InetAddress class. You can specify either a timeout or the NetworkInterface to use. For more information on the underlying Internet Co...more
What's a BOM?
BOM stands for Byte Order Mark and could be the initial bytes of a UTF-encoded stream, typically used to indicate endianess of the stream. Prior to Java 6, if present, your program needed to handl...more
Is null a keyword?
Simple answer. No. See http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html for a complete set of keywords. true and false are not keywords either. They are reserved words in t...more
Using Reflection, how do I find out if a field is enumerated ?
The java.lang.reflect.Field class has an isEnumConstant() method for just such a check.
How do I access environment variables? -- 10.31.05
How do I access environment variables?
How do I loop through a set of enum values in 1.5+?
public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
for (Suit suit : Suit.values()) {
System.out.println(suit);
}
How do you clear a system property?
Prior to JDK 1.5, you couldn't. With 1.5, you can use the clearProperty method of System. Provided you have write PropertyPermission on the key, this will succeed.
With what precision can you measure time intervals?
The nanoTime() method of System allows you to measure time in nanoseconds, provided this level of precision is available on the current platform. Mechanical overflow will happen if you try to test...more
How can I get the number of active Groups within a ThreadGroup?
ThreadGroups activeGroupCount() returns the number of active groups within the ThreadGroup instance it was called upon. Once the number of active groups is obtained ThreadGroups enumerate(ThreadG...more