JAVA Interview Questions
|
Previous |
1 |
2 |
3 |
4 |
Next |
Sample JAVA Programs |
|
|
| 151. What is internationalization? |
| Internationalization is the process of
designing an application to that it can be adapted to various languages and regions without changes.
|
| 152. What is anonymous class ? |
| An anonymous class is a type of inner class that don't have any name. |
| 153. What is the difference between URL and URLConnection? |
| A URL represents the
location of a resource, and a URLConnection represents a link for accessing or communicating with the resource at the location.
|
| 154. What are the two important TCP Socket classes? |
| ServerSocket and Socket. ServerSocket is useful for two-way
socket communication. Socket class help us to read and write through the sockets. getInputStream() and getOutputStream() are the two
methods available in Socket class.
|
| 155. Strings are immutable. But String s="Hello"; String s1=s+"World" returns HelloWorld how ? |
|
Here actually a new object is created with the value of HelloWorld.
|
| 156. What is classpath?
|
|
Classpath is the path where Java looks for loading class at run time and compile time.
|
| 157. What is path?
|
|
It is an the location where the OS will look for finding out the executable files and commands.
|
| 158. What is java collections? |
|
Java collections is a set of classes, that allows operations on a collection of classes.
|
| 159. Can we compile a java program without main? |
|
Yes, we can. In order to compile a java program, we don't require any main method. But to execute a java program we must have a
main in it (unless it is an applet or servlet). Because main is the starting point of a java program.
|
| 160. What is a java compilation unit. |
|
A compilation unit is a java source file.
|
| 161. What are the restrictions when overriding a method ? |
|
Overridden methods must have the same name, argument list, and return type
(i.e., they must have the exact signature of the method we are going to override, including return type.)
The overriding method cannot be less visible than the method it overrides( i.e., a public method cannot be override to private).
The overriding method may not throw any exceptions that may not be thrown by the overridden method
|
| 162. What is static initializer block? What is its use? |
|
A static initializer block is a block of code that declares with the static keyword.
It normally contains the block of code that must execute at the time of class loading.
The static initializer block will execute only once at the time of loading the class only.
|
| 163. 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
|
| 164. What is daemon thread?
|
|
Theards which are running on the background are called deamon 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.
|
| 165. 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.
|
| 166. 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.
|
| 167. Why java does not support multiple inheritance?
|
|
Because the multiple inheritance causes the redundancy. Also we cannot solve diamond problem.
|
| 168. 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.
|
| 169. 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.
|
| 170. Why java is not 100% pure object oriented language? |
|
Because java uses primitives.
|
| 171. Why ArrayList is faster than Vector? |
|
A Because Vector is synchronized. Synchronization reduces the performance.
|
| 172. What is the security mechnaism used in java? |
|
Java uses sand box security model.
|
| 173. What is sandbox? |
|
sandbox is a security mechanism for safely running programs. The sandbox typically provides a tightly-controlled set of resources
for guest programs to run in, such as scratch space on disk and memory.
|
| 174. What is phantom memory? |
|
Phantom memory is the memory that does not exist in reality.
|
| 175. What is reflection? |
|
Reflection is the process of finding out the different features of a class dynamically.
|
| 176. What are the differences between JIT and HotSpot? |
|
The Hotspot VM is a collection of techniques, the most important of which is called adaptive optimization.
The original JVMs interpreted byte codes one at a time. Second-generation JVMs added a JIT compiler, which
compiles each method to native code upon first execution, then executes the native code. Thereafter, whenever
the method is called, the native code is executed. The adaptive optimization technique used by Hotspot is
a hybrid approach, one that combines byte code interpretation and run-time compilation to native code.
Hotspot, unlike a regular JIT compiling VM, doesn't do "premature optimization".
|
| 177. What are the advantages and disadvantages of reference counting in garbage collection?
|
|
An advantage of this scheme is that it can run in small chunks of time closely linked with the execution of the program.
These characteristic makes it particularly suitable for real-time environments where the program can't be interrupted for
very long time. A disadvantage of reference counting is that it does not detect cycles. A cycle is two or more objects
that refer to one another. Another disadvantage is the overhead of incrementing and decrementing the reference count each time.
Because of these disadvantages, reference counting currently is out of favor.
|
| 178. How would you implement a thread pool? |
|
The ThreadPool class is a generic implementation of a thread pool, which takes the following input
Size of the pool to be constructed and name of the class which implements Runnable (which has a visible default constructor)
and constructs a thread pool with active threads that are waiting for activation. once the threads have finished processing
they come back and wait once again in the pool.
|
| 179. What is the difference between throw and throws clause?
|
|
throw is used to throw an exception manually, where as throws is used in the case of checked exceptions, to tell the compiler that
we haven't handled the exception, so that the exception will be handled by the calling function.
|
| 180. What is JAR file? |
|
JAR file (short for Java Archive) is a ZIP file used to distribute a set of Java classes. It is used to store compiled Java classes
and associated metadata that can constitute a program
|
| 181. What is a classloader? |
|
A class loader is an object that is responsible for loading classes.
|
| 182. What is the difference between Comparable and Comparator ? |
|
The Comparable is for natural ordering and Comparator
is for custom ordering. But we can override the compareTo method of comparable interface to give a custom ordering.
|
| 183. What is the difference between List, Set and Map? |
|
Set is a collection that has no duplicate elements. A List is a collection that has an order associated with its elements.
A map is a way of storing key/value pairs. The way of storing a Map is similar to two-column table.
|
| 184. What is meant by Open Source ? |
|
In general, open source refers to any program whose source code is made available for use or modification as users or other
developers see fit. Open source software is usually developed as a public collaboration and made freely available.
|
| 185. How do you send data from an applet to Servlet ? What are the steps involved in it ?
|
You can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection to the web server.
The server then passes this information to the servlet in the normal way.
Basically, the applet pretends to be a web browser, and the servlet doesn't know the difference. As far as the servlet
is concerned, the applet is just another HTTP client.
|
| 186. What is polymorphism? |
|
It is the ability of an object to behave differently on different situations for the same message.
|
| 187. What is a class, member and local variable? |
|
Variables declared within a method are local variables. Variables declared within the class are member variables.
Variables declared within the class with static modifier are class variables.
|
| 188. How do I convert a numeric IP address like 66.29.36.130 into a hostname like www.javacertificate.net |
|
String hostname = InetAddress.getByName("66.29.36.130").getHostName();
|
| 189. What is the difference between a constructor and a method? |
|
constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself,
has no return type, and is invoked using the new operator. We cannot invoke a constructor directly. A method is an ordinary member
function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.
|
| 190. What are the different inner classes types? |
|
There are mainly four types available. They are Member classes, Nested top-level classes, Local classes, Anonymous classes
|
| 192. What is Nested top-level classes? |
|
A class declared within a class with static modifier is called nested top level class. Any class outside the declaring class can
access the nested top level class with the declaring class dot nested top level class. Top-level inner classes have access to
static variables only .
|
| 193. What is Member classes? |
|
A class declared inside a class without static modifier is called member class. Member classes are just like any other member
methods or member variables.
|
| 194. What is Local inner classes ?
|
|
Local inner classes are class declared inside a block of code. They are visible only within the block of their declaration.
|
| 195. What is aggregation? |
|
It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite
method through its reference, then it is called aggregation
|
| 197. What is the purpose of the Runtime class? |
|
The purpose of the Runtime class is to provide access to the Java runtime system.
|
| 198. What is the difference between TCP/IP and UDP? |
|
TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding
reaching the message to the destination. UDP is a one-way communication only between the client and the server and it is not a
reliable and there is no confirmation regarding reaching the message to the destination.
|
| 199. Why is UTFDataFormatException thrown by DataOutputStream.writeUTF() when serializing a String? |
|
DataOutputStream.writeUTF() does not support writing out strings larger than 64K. The first two bytes of a UTF string in the
stream are the length of the string. If a java.lang.String is larger than 64K, it needs to be stored in the stream by an
alternative method rather than depending on the default method of storing a String in the stream, writeUTF.
|
| 200. Why is OutOfMemoryError thrown after writing a large number of objects into an ObjectOutputStream?
|
|
The ObjectOutputStream maintains a table mapping objects written into the stream to a handle. The first time an
object is written to a stream, its contents are written into the stream; subsequent writes of the object result
in a handle to the object being written into the stream. This table maintains references to objects that might
otherwise be unreachable by an application, thus, resulting in an unexpected situation of running out of memory.
A call to the ObjectOutputStream.reset() method resets the object/handle table to its initial state, allowing
all previously written objects to be eligible for garbage collection.
|
|
Previous |
1 |
2 |
3 |
4 |
Next |
Sample JAVA Programs |
Back to Top |