June 30, 1998

Check if file exists

Question: Is there a way for me to check if a file exists before writing to the file using Java? Answer: You can determine if a file exists by calling the exists() method in the java.io.File class. A File instance represents a file on your local file system and allows

Dynamic class casting

Question: Does java have dynamic_cast? If so, how is itused? Answer: All class casts of nonprimitive types in Java are dynamic and performed at runtime.In C++ the dynamic_cast operator will producea null pointer if a type conversion cannot be performed. In Java, the cast operation will throw a ClassCastException. Where

Calculating # of days between two dates

Question: I need help to calculate the number of days between two dates. This may seem like a trivial question, but for the life of me, I cannot find away for the Calendar or Date class to achieve this. Answer: This is actually not a trivial question. The Java time


Question: How do I go about using exponents in Java? For example, how would I do 6 to the power of 3? Answer: You want to look at the documentation for thejava.lang.Math class, which contains many commonly used math functions. To raise a number to a given power, you would

Image loading

Question: I’m having trouble reshaping a frame to the size of a loaded image. I start out by saying: int fx = image.getWidth(this); int fy = image.getHeight(this);then I try to apply it to the frame this.resize(fx, fy); But, to my misfortune, the frame totally collapsesto nothing but the title bar.