HOME      BLOG       FORUMS      CONTACT       ABOUT

Core Java interview questions – Part 8

121. What is an interface?
An interface is a collection of method declarations and constants. In java interfaces are used to achieve multiple inheritance. It sets a behavioral protocol to all implementing classes.

122. What is an abstract class?
An abstract class is an incomplete class. An abstract class is defined with the keyword abstract . We cannot create an object of the abstract class because it is not complete. It sets a behavioral protocol for all its child classes.

123. How will you define an interface?
An interface is defined with the keyword interface. Eg:
public interface MyInterface { }

124. How will you define an abstract class?
An abstract class is defined with the keyword abstract Eg:
public abstract class MyClass { }

125. What is any an anonymous class?
An anonymous class is a local class with no name.

126. What is a JVM heap?
The heap is the runtime data area from which memory for all class instances and arrays is allocated. The heap may be of a fixed size or may be expanded. The heap is created on virtual machine start-up.

127. What is difference between string and StringTokenizer?
StringTokenizer as its name suggests tokenizes a String supplied to it as an argument to its constructor and the character based on which tokens of that string are to be made. The default tokenizing character is space ” “.

128. What is the difference between array and ArrayList ?
Array is collection of same data type. Array size is fixed, It cannot be expanded. But ArrayList is a grow able collection of objects. ArrayList is a part of Collections Framework and can work with only objects.

129. What is difference between java.lang .Class and java.lang.ClassLoader? What is the hierarchy of ClassLoader ?
Class ‘java.lang.Class’ represent classes and interfaces in a running Java application. JVM construct ‘Class’ object when class in loaded. Where as a ClassLoader is also a class which loads the class files into memory in order for the Java programs to execute properly. The hierarchy of ClassLoaders is:

Bootstrap ClassLoaders
Extensive ClassLoaders
System Classpath ClassLoaders
Application ClassLoaders

130. What is daemon thread?
Threads which are running on the background are called demon threads. daemon thread is a thread which doesn’t give any chance to run other threads once it enters into the run state it doesn’t give any chance to run other threads. Normally it will run forever, but when all other non-daemon threads are dead, daemon thread will be killed by JVM

131. What is a green thread?
Native threads can switch between threads preemptively. Green threads switch only when control is explicitly given up by a thread ( Thread.yield(), Object.wait(), etc.) or a thread performs a blocking operation (read(), etc.). On multi-CPU machines, native threads can run more than one thread simultaneously by assigning different threads to different CPUs. Green threads run on only one CPU. Native threads create the appearance that many Java processes are running: each thread takes up its own entry in the process table. One clue that these are all threads of the same process is that the memory size is identical for all the threads – they are all using the same memory. The process table is not infinitely large, and processes can only create a limited number of threads before running out of system resources or hitting configured limits.

132. What is volatile variable?
A volatile variable is not allowed to have a local copy of a variable that is different from the value currently held in “main” memory. Volatile modifier requests the JVM to always access the shared copy of the variable so the its most current value is always read.

133. Why java does not support multiple inheritance?
Because the multiple inheritance causes the redundancy. Also we cannot solve diamond problem.

134. What is diamond problem?
The diamond problem is an ambiguity that can occur when a class multiply inherits from two classes that both descend from a common super class

135. How many JVM’s we can run in a system?
Any number of JVMs can run in a system. Whenever we issue the command ‘java’ a new JVM will start.


Tags: , , ,

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply