121 | Q | How is an interface? |
A | 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 | Q | What is an abstract class? |
A | 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 | Q | How will you define an interface? |
A | An interface is defined with the keyword interface. Eg: public interface MyInterface { } | |
124 | Q | How will you define an abstract class? |
A | An abstract class is defined with the keyword abstract Eg: public abstract class MyClass { } | |
125 | Q | What is any an anonymous class? |
A | An anonymous class is a local class with no name. | |
126 | Q | What is a JVM heap? |
A | 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 | Q | What is difference between string and StringTokenizer? |
A | 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 | Q | What is the difference between array and ArrayList ? |
A | Array is collection of same data type. Array size is fixed, It cannot be expanded. But ArrayList is a growable collection of objects. ArrayList is a part of Collections Framework and can work with only objects. | |
129 | Q | What is difference between java.lang .Class and java.lang.ClassLoader? What is the hierarchy of ClassLoader ? |
A | 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 | Q | What is daemon thread? | |
A | 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 | ||
131 | Q | What is a green thread? | |
A | 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 | Q | What is volatile variable? | |
A | 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 | Q | Why java does not support multiple inheritance? | |
A | Because the multiple inheritance causes the redundancy. Also we cannot solve diamond problem. | ||
134 | Q | What is diamond problem? | |
A | 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 | Q | How many JVM's we can run in a system? | |
A | Any number of JVMs can run in a system. Whenever we issue the command 'java' a new JVM will start. |
136 | Q | Why Java is not 100% pure object oriented language? | |
A | Because java uses primitives. | ||
137 | Q | Why ArrayList is faster than Vector? | |
A | Because Vector is synchronized. Synchronization reduces the performance. | ||
138 | Q | What is the security mechnaism used in java? | |
A | Java uses sand box security model. | ||
139 | Q | What is sandbox? | |
A | A 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. | ||
140 | Q | What is phantom memory? | |
A | Phantom memory is the memory that does not exist in reality. | ||
141 | Q | What is reflection? | |
A | Reflection is the process of finding out the different features of a class dynamically. | ||
142 | Q | What are the differences between JIT and HotSpot? | |
A | 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" |
143 | Q | What are the advantages and disadvantages of reference counting in garbage collection? | |
A | 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. | ||
144 | Q | How would you implement a thread pool? | |
A | 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. | ||
145 | Q | What is the difference between throw and throws clause? | |
A | 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. | ||
156 | Q | What is JAR file? | |
A | A 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 | ||
147 | Q | What is a classloader? | |
A | A class loader is an object that is responsible for loading classes. | ||
148 | Q | What is the difference between Comparable and Comparator ? | |
A | 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. | ||
149 | Q | What is the difference between List, Set and Map? | |
A | A 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. | ||
150 | Q | What is the difference between Exception and Error ? | |
A | Error is unrecoverable. |
151 | Q | What is meant by Open Source ? | |
A | 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. | ||
152 | Q | How do you send data from an applet to Servlet ? What are the steps involved in it ? | |
A | 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. | ||
153 | Q | What is polymorphism? | |
A | It is the ability of an object to behave differently on different situations for the same message. | ||
154 | Q | What is a class, member and local variable? | |
A | 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 | ||
155 | Q | How do I convert a numeric IP address like 66.29.36.130 into a hostname like www.javacertificate.net | |
A | String hostname = InetAddress.getByName("66.29.36.130").getHostName(); | ||
156 | Q | What is the difference between a constructor and a method? | |
A | A 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. | ||
157 | Q | What are the different inner classes types? | |
A | There are mainly four types available. They are Member classes, Nested top-level classes, Local classes, Anonymous classes | ||
158 | Q | What is Nested top-level classes? | |
A | 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 . | ||
159 | Q | What is Member classes? | |
A | 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. |