30 Java Interview Questions

30 Java Interview Questions - 30 Java Interview Questions...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
30 Java Interview Questions * Q1. How could Java classes direct program messages to the system console, but error messages, say to a file? A. The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed: Stream st = new Stream(new FileOutputStream("output.txt")); System.setErr(st); System.setOut(st); * Q2. What's the difference between an interface and an abstract class? A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class. * Q3. Why would you use a synchronized block vs. synchronized method? A. Synchronized blocks place locks for shorter periods than synchronized methods. * Q4. Explain the usage of the keyword transient? A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers). * Q5. How can you force garbage collection? A. You can't force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately. * Q6. How do you know if an explicit object casting is needed? A. If you assign a superclass object to a variable of a subclass's data type, you need to do explicit casting. For example: Object a; Customer b; b = (Customer) a; When you assign a subclass to a variable having a supeclass type, the casting is
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/15/2011 for the course ECO 2023 taught by Professor Mr.raza during the Summer '10 term at FAU.

Page1 / 4

30 Java Interview Questions - 30 Java Interview Questions...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online