JavaLanguage Section Index | Page 33
Where is Java?
The island of Java is in Indonesia and contains the country's capital, Jakarta.
How do I deprecate a class or method?
Place the @deprecated tag in the javadoc for the class or method, with a reason why you are deprecting the class or method:
/**
* @deprecated As of version 3.5, replaced by
* fooBar
* @see #f...more
What is a deprecated API?
As classes evolve, their API change. To signal to developers that they are using an antiquated feature, class designers can flag classes or methods as deprecated. When used, the compiler will warn...more
Can I override a method that doesn't throw exceptions with one that does?
Overriding methods cannot change the signature of the overridden method. All exceptions are included in the signature of the method except for RunTimeException and it's subclasses. So, the only e...more
Can I restart a stopped thread?
In short, no. Once a thread is stopped, it cannot be restarted. Keep in mind though that the use of the stop() method of Thread is deprecated and should be avoided.
How can I dynamically invoke a method, where I have the method name in a String?
Using the Java Reflection API permits you to dynamically invoke methods from string names at a significant performance penalty.
To find the method to invoke, you would create an array of argument...more
How can I record audio from my Java program?
Support for audio recording is not part of the core Java libraries. Instead, you need to use the Java Media Framework (http://java.sun.com/products/java-media/jmf).more
How do I have one thread wait for another thread to finish before continuing?
You can wait for a thread to finish by calling its join() method. For instance, in the following code, the current thread will wait until thread2 finishes before printing Done.
thread2.start();
/...more
What happened to the private protected modifier?
This was accidently added to to the Java 1.0.2 version and removed from subsequent releases. It had the same behavior of the protected modifier in C++, keeping access to subclasses, but not packag...more
What is a final class?
When you declare a class to be final, it can never be subclassed. This is usually done for security or performance reasons.
public final class Math {
// ...
}
What is a final method?
When you declare a method to be final, it can never be overridden in subclasses. This is usually done for security or performance reasons, providing additional information to the JIT compiler or H...more
What is the identifier length limit with Java?
From a language specification perspective, there is no limit. From a class file perspective, there is a 64K byte limit to names. For ASCII identifiers, that would be 65535. For identifiers beyond ...more
Why do I not have to import the classes in the java.lang package?
The classes in the java.lang package are so important that the compiler implicitly imports all the classes there. This ensures classes in the unnamed package are not accidently used instead of the...more
Why does "float f = 3.5;" generate a compile-time error?
The constant value 3.5 is recognized by the compiler to be a double rather than a float. You must place an f after the 3.5 for it to be recognized as a floating point constant value:
float f = 3....more
Why doesn't the String.replace() actually replace anything?
In Java, Strings are immutable. Since the string cannot be modified in place, the replace() method returns a new String constructed from a modified copy of the original String's value.more