Java Interview Questions and Answers - Part 3

Primitive types can be passed by reference. 1. By storing the primitive type value in an array of single element and passing it...
A signature in java is a combination of elements in a list such as constructor and methods thereby distinguishing them from other constructors and methods...
A static nested class can not directly access non-static methods or fields of an instance of its enclosing class...
An instance variable can be declared as private to promote information hiding. So that no other object can access them...
Overridden methods of super class in subclass allow a class to inherit and behave close enough...
The java access specifier ‘protected’ is placed proceeding the member of the class and the access control is applicable only for that particular definition...
Every exception is represented by the instance of Throwable or its subclasses. An object can carry the information for the exception raising point to the exception handler which catches it...
When an exception is to be handled which are not java class library, a user defined exception can be thrown...
Once an application finds an exception, responds an exception by throwing another exception. It causes another exception. Knowing an exception that causes another exception is very useful...
The term exception lets the programmer to know that there is something exceptional has occurred in the program. Apart from Java exception class library, a custom exception can be created by the developer...
Primitive type wrapper classes or simply wrapper classes are available in java.lang package for providing object methods for all the eight primitive types. All the wrapper class objects are immutable...
In an application, a program continues to run until all of the threads have ended. Hence, the main thread to finish at last is not a requirement. It is a good programming practice to make it to run last to finish...
Java threads can be created graciously in two ways: implementing the Runnable interface and extending Thread class...
In multiple processor systems, a large algorithm will split the process into threads. So that different processors can handle different threads...
Enumeration is type safe. Where as final variables are not. Enumeration supports to have a blend of various values. Where as final variables does not support multiple values...
Yes it is possible for a method other than paint() or update() to output an applet’s window. It is mandatory to obtain a graphics context by invoking getGraphics() method...
The compiled Java source code is known as byte code. Java compiler generates the byte code...
Java strictly specifies the ranges for primitive values. The selection of values in integer or floating point types differs based on the requirement of an application...
The char data type in Java is a single 16-bit Unicode character. It represents a character that could be any one of the world languages...
The prefix operator ++ adds one to its operand / variable and returns the value before it is assigned to the variable. In other words, the increment takes place first and the assignment next...
The method indexOf() returns the first occurrence (index) of a given character or a combination as parameter in a given string...
The default access specifier is one which is not specified with a key word. If no access specifier (any one of private, protected, public) is mentioned it is known as the default access specifier...
There are two ways of affecting access levels. One, when the classes in the Java platform are used within the developer defined classes, the access levels determine the members of those class which can be used by the developer defined classes...
The event model is based on the Event Source and Event Listeners. Event Listener is an object that receives the messages / events. The Event Source is any object which creates the message / event...
The programmer assumes certain code while developing when handling exceptions. For example, a number is passed as parameter to a method and it is to be validated whether it is positive...
Java Native methods are useful when an application can not be written completely in Java language. For instance, when a Java application needs to modify an existing application which was developed in another language...
Using shift operators in Java we can 1. Integer division and multiplication is done faster...
Wrapper classes are used to represent primitive data types as objects. Dealing primitive types as objects is sometimes easier....
Array vs ArrayList: ArrayList is much better than Array, when the size need to be increased dynamically. Efficiency is possible with arrays. ArrayList permits null elements...
The automatic conversion of primitive int type into a wrapper class object is called autoboxing. It does not require to type cast the int value. The modification of primitive wrapper objects is done directly...
Java can communicate with ActiveX objects by using Bridge2Java from IBM. Bridge2Java is a tool for allowing the java applications for communicating with ActiveX objects...
CLASSPATH is an environment variable that communicates JVM and other java applications for finding the java language class libraries, including the developer’s class library. It is set by setenv command like...
1. Create an object of ByteArrayOutputStream class. ByteArrayOutputStream bStream = new ByteArrayOutputStream();..
1. Create a File object. File file = new File(“path and file name here”);...
Java spaces is a technology with powerful high-level tool for the development of distributed and collaborative applications. A simple API is provided based on the network shared space for developing sophisticated distributed applications...
The system properties are accessed by the method System.getProperties(). This method returns a Properties object...
The add() methods inserts an element at a given position of the vector...
Sets can have unique values. Lists can have duplicate values...
The unsynchronized collections and their modifications, iterations are termed as ‘fail-fast’ iterators. An iterator that implements Iterable interface...
The object’s current state can be persisted and retrieved by using the concept known as ‘serialization’. This is done on an object to a stream...
Xerces is a group of libraries for parsing, serializing, validating and manipulating XML...
Among various types of garbage collections, the System.gc() performs an explicit collection of garbage calls. The other garbage collection types are:...
Reflection feature in java allows an executing java program for introspecting upon itself. It also allows for manipulating internal properties of the program...
Time is measured in nanoseconds by using the method nanoTime() method. This method returns the current value of the most precise system timer available in nanoseconds...
The method start() invokes the run() method. If the run() method of two threads invoked separately, they will execute one after the other...
Java Isolates is an API. It provides a mechanism to manage Java application life cycles which are isolated from each other. They can potentially share the underlying implementation resources...
The following are the system properties that Java applets read by default with System.getProperty() method:...
The jvmstat is a technology for adding light weight performance, configuration instrumentation to the HotSpot JVM. The jvmstat provides...
A singleton implementation is done using action class in struts framework. It performs as a front controller and every request will go through it...
The ‘length’ is an instance constant which is the size of an array. While the ‘length()’ is a method that returns the no. of the characters in a string...