Monday, 15 June 2009

Java Certification Question 0005

Which of the following are true statements?
1) I/O in Java can only be performed using the Listener classes
2) The RandomAccessFile class allows you to move directly to any point a file.
3) The creation of a named instance of the File class creates a matching file in the underlying operating system only when the close method is called.
4) The characteristics of an instance of the File class such as the directory separator, depend on the current underlying operating system



Answer:
(Not on the official sub objectives but this topic does come up on the exam)
2) The RandomAccessFile class allows you to move directly to any point a file.
4) The characteristics of an instance of the File class such as the directory separator, depend on the current underlying operating system
The File class can be considered to represent information about a file rather than a real file object. You can create a file in the underlying operating system by passing an instance of a file to a stream such as FileOutputStream. The file will be created when you call the close method of the stream.

Sunday, 14 June 2009

Java Certification Question 0004

Which of the following statements are true?
1) The garbage collection algorithm in Java is vendor implemented
2) The size of primitives is platform dependent
3) The default type for a numerical literal with decimal component is a float.
4) You can modify the value in an Instance of the Integer class with the setValue method



Answer:
1) The garbage collection algorithm in Java is vendor implemented. Threading and garbage collection are two of the few areas that are platform dependent. This is one of the reasons why Java is not suitable for realtime programming. It is not a good idea use it to control your plane or nuclear power station. Once an instance of the Integer class has a value it cannot be changed.

Saturday, 13 June 2009

Java Certification Question 0003

Which of the following are valid statements?
1) System.out.println(1+1);
2) int i=2+'2';
3) c
4) byte b=255;


Answer:
1) System.out.println(1+1);
2) int i=2+'2';
Option 3 is not valid because single quotes are used to indicate a character constant and not a string. Several people have emailed me to say that option 3 will compile. When they eventually compiled the exact code they have agreed, it will not compile. Let me re-state that
String s="on"+'one'; Will NOT compile.
Option 4 will not compile because 255 is out of the range of a byte

Friday, 12 June 2009

Java Certification Question 0002

Which of the following are Java keywords?
1) NULL
2) new
3) instanceOf
4) wend


Answer:
2) new
The option NULL (note the upper case letter) is definitely not a keyword. There is some discussion as to if null is a keyword but for the purpose of the exam you should probably assume it is a keyword.
The option instanceOf is a bit of a misleading option that would probably not occur on the exam. The real keyword is instanceof (note that the of has no capital letter O). I had the incorrect version in an earlier version of this tutorial as it looks more likely to my eyes. The instanceof keyword looks like a method, but it is actually an operator.
The option wend is probably valid in some other language to indicate the end of a while loop, but Java has no such keyword.

Thursday, 11 June 2009

Java Certification Question 0001

Which of the following are legal statements?

1) float f=1/3;
2) int i=1/3;
3) float f=1.01;
4) double d=999d;

Answer:
1) float f=1/3;
2) int i=1/3;
4) double d=999d;
The fact that option 3 does not compile may be a surprise. The problem is because the default type for a number with a decimal component is a double and not a float. The additional trailing d in the option with 999 doesn't help, but it doesn't harm.