Core Java Technology Section Index | Page 4
Are there any predefined file filters for a JFileChooser?
Apart from the accept all filter, until Java 6, there were no predefined filters. Java 6 introduces the FileNameExtensionFilter, allowing you to define one or more types of files for the user to s...more
How can I make a read-only file writable?
Pre-Java 6, you had to either use native code or fork off a platform specific command in a sub-process. With Java 6, there is a setWritable() method.
How do you use the @Override annotation?
Use this annotation to tell the compiler that the method is supposed to be overriding a method in the superclass. If by chance it doesn't, the compiler tells you. This allows you to catch typos li...more
What's with this new IOError class, when is it thrown?
The Console class has methods to read console input with readLine() and readPassword(). These methods throw IOError instead of IOException. My best guess at why the difference is becasue IOError i...more
What are the differences between instance methods and class methods?
What are the differences between instance methods and class methods?
How do you use the ternary operator?
How do you use the ternary operator?
java.lang.OutOfMemoryError: Java heap space What does this error mean and how can I correct it?
It means that the JVM has run out of all the memory that has been allocated to it. You can change the amount of memory allocated for use by your JVM using the -Xms and -Xmx command line parameter...more
I have an interface that is implemented by 100 classes, if I add a method to the interface will my classes compile? How can I fix any errors?
I have an interface that is implemented by 100 classes, if I add a method to the interface will my classes compile? How can I fix any errors?
Java doesn't allow operator overloading yet + is overloaded for class String. Is it possible to overload operators? Why doesn't Java allow operator overloading?
It is true that Java does not allow operator overloading. It is also true that an exception was made for String, although this is out of the control of developers as it is a built in feature of J...more
What is the main use of the ResourceBundle class? Can it be used instead of the Properties class? If so what are the advantages?
ResourceBundle is a property file handler with locales support, it allows you to support multiple languages in your application. There's a full explaination on what ResourceBundle is and how it h...more
Can Java handle nested switch statements?
Nested switch statements are allowed. Just make sure you remember to have all the break statements in the correct places. E.g:
int i;
int j;
switch(i){
case 0: System.out....more
Is it possible to get a file's creation date in Java?
It is not possible to obtain this information on *nix machines since this information is not stored about the files, only file modification date is stored. Therefore java has no methods for obtai...more
If you have a series of objects with a circular reference, can they be garbage collected?
Yes. If the objects are only reachable from themselves and nowhere else, they are a candidate for garbage collection.
What are the differences between a shallow clone of an object and a deep clone?
By default, cloning yields a shallow copy. By shallow, we mean the object is copied, but the contained objects are not. What a deep copy does it copy the cloned object, as well as all the objects...more
What is the difference between variable arity and vararg methods?
Basically nothing. It is just semantics. A method's arity is the number of arguments it takes. The arity of the main() method of a class is one since it takes one argument, a String[].more