160 | Q | What is Local inner classes ? | |
A | Local inner classes are class declared inside a block of code. They are visible only within the block of their declaration. | ||
161 | Q | Can a top level class be private or protected? | |
A | No. A top level class can not be private or protected. It can have either "public" or no modifier. | ||
162 | Q | How will you invoke any external process in Java? | |
A | By using Runtime.getRuntime().exec(….) | ||
163 | Q | What is a package? | |
A | To group set of classes into a single unit is known as packaging. Packages provides wide namespace visibility. | ||
164 | Q | What is the use of assert keyword | |
A | Assert keyword validates certain expressions. It replaces the if block effectively and throws an AssertionError on failure. The assert keyword should be used only for critical arguments (means without that the method does nothing). | ||
165 | Q | What is composition? | |
A | Holding the reference of the other class within some other class is known as composition. |
166 | Q | What is aggregation? | |
A | 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 | ||
167 | Q | What are the methods in Object? | |
A | clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString | ||
168 | Q | What is the relationship between synchronized and volatile keyword? | |
A | The JVM is guaranteed to treat reads and writes of data of 32 bits or less as atomic. For long or double variable, programmers should take care in multi-threading environment. Either put these variables in a synchronized method or block, or declare them volatile. | ||
169 | Q | What factors are used to decide using synchronized or volatile? | |
A | You can make a variable synchronized or volatile under the following cases: 1) if you are not updating many variables often in a multithread environment, consider using volatile. 2) If you are updating many variables, consider using synchronized, because using volatile might be slower. | ||
170 | Q | What are the drawbacks of inheritance? | |
A | Since inheritance inherits everything from the super class and interface, it may make the subclass too clustering and sometimes error-prone when dynamic overriding or dynamic overloading in some situation. In addition, the inheritance may make peers hardly understand your code if they don't know how your super-class acts. | ||
171 | Q | What is the difference between static synchronized and synchronized methods? | |
A | Both are synchronized methods. One is instance method, the other is class method. Method with static modifier is a class method. That means the method belongs to class itself and can be accessed directly with class name and is also called Singleton design. The method without static modifier is an instance method. That means the instance method belongs to its object. Every instance of the class gets its own copy of its instance method. | ||
172 | Q | What is the purpose of the Runtime class? | |
A | The purpose of the Runtime class is to provide access to the Java runtime system. | ||
173 | Q | What is the purpose of the System class? | |
A | The purpose of the System class is to provide access to system resources. | ||
174 | Q | Does the code in finally block get executed if there is an exception and a return statement in a catch block? | |
A | If an exception occurs and there is a return statement in catch block, the finally block is still executed. The finally block will not be executed when the System.exit(1) statement is executed earlier or the system shut down earlier or the memory is used up earlier before the thread goes to finally block. | ||
175 | Q | Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ? | |
A | 3 processes will start. | ||
176 | Q | What are the restrictions placed on the values of each case of a switch statement? | |
A | At compile time, each case values of switch statement must evaluate to a an int value. | ||
177 | Q | If aaaa is an array then why aaaa.length why not aaaa.length()? | |
A | Because length is a property not a method. | ||
178 | Q | What is dynamic typing? | |
A | Dynamic typing means type errors are detected at run time by checking the actual data types of the values against the required data types | ||
179 | Q | What is static typig? | |
A | Static typing means type errors are detected at compile time by checking the inferred data type is a subtype of the required type | ||
180 | Q | What is HashMap and Map? | |
A | Map is Interface and HashMap is class that implements that. |
181 | Q | What is an Object and how do you allocate memory to it? | ||
A | Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it. | |||
182 | Q | What is UNICODE? | ||
A | Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other. | |||
183 | Q | What is adapter class? | ||
A | An adapter class provides a default implementation of all methods in an event listener interface. Adapter classes are useful when you want to process only some of the events that are handled by a particular event listener interface. You can define a new class by extending one of the adapter classes and implementing only those events relevant to us. | |||
185 | Q | What is the difference between TCP/IP and UDP? | ||
A | 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. | |||
186 | Q | What is Inter-Thread communication?. | ||
A | Exchange of information between two threads. | |||
187 | Q | What is a policy?. | ||
A | It's an abstract class for representing the system security policy for a Java application environment (specifying which permissions are available for code from various sources). Java security properties file resides in <JAVA-HOME>/lib/security/java.security directory. | |||
188 | Q | What is a thread group? | ||
A | A thread group is a data structure that controls the state of collection of thread as a whole managed by the particular runtime environment. | |||
189 | Q | Why is UTFDataFormatException thrown by DataOutputStream.writeUTF() when serializing a String? | ||
A | 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. | |||
190 | Q | Why is OutOfMemoryError thrown after writing a large number of objects into an ObjectOutputStream? | ||
A | 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. | |||
191 | Q | How can I get the serialVersionUID of a class? | ||
A | By running the serialver tool with the name of the class as the command line argumet, as shown in the example that follows: serialver java.lang.String | |||
192 | Q | What is serialVersionUID ? | ||
A | The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this identifier number to ensure that a loaded class corresponds to a serialized object. | |||
193 | Q | What is abstraction? | ||
A | An abstraction is an idea, concept, or word which defines the phenomena which make up the concrete events or things which the abstraction refers to, the referents. |
194 | Q | What is encapsulation? | |
A | Encapsulation describes the ability of an object to hide its data and methods from the rest of the world | ||
195 | Q | What is inheritance? | |
A | Inheritance is the ability to create new classes based on existing classes. It is useful to reuse existing code. |