You are on page 1of 9

1. What is a transient variable? A transient variable is a variable that may not be serialized.

For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable cant be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null. 2. Which containers use a border Layout as their default layout? The Window, Frame and Dialog classes use a border layout as their default layout. 3. Why do threads block on I/O? Threads block on I/O (that is enters the waiting state) so that other threads may execute while the I/O Operation is performed. 4. How are Observer and Observable used? Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects. 5. What is synchronization and why is it important? With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often leads to significant errors. 6. Can a lock be acquired on a class? Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.. Q: What are mutex and semaphore? What is the difference between them? A: A mutex is a synchronization object that allows only one process or thread to access a critical code block. A semaphore on the other hand allows one or more processes or threads to access a critical code block. A semaphore is a multiple mutex. 3) How is JavaBeans differ from Enterprise JavaBeans? The JavaBeans architecture is meant to provide a format for general-purpose components. On the other hand, the Enterprise JavaBeans architecture provides a format for highly specialized business logic components.

4) In what ways do design patterns help build better software? Design patterns helps software developers to reuse successful designs and architectures. It helps them to choose design alternatives that make a system reusuable and avoid alternatives that compromise reusability through proven techniques as design patterns. 5) Describe 3-Tier Architecture in enterprise application development. In 3-tier architecture, an application is broken up into 3 separate logical layers, each with a welldefined set of interfaces. The presentation layer typically consists of a graphical user interfaces. The business layer consists of the application or business logic, and the data layer contains the data that is needed for the application. What is Collection API? Answer: The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces. Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap. Example of interfaces: Collection, Set, List and Map. Can we compare String using equality operator (==) operator? We can compare String using equality operator. But we mostly use equals() method because of following reasons:

The equality operator is used to compare primitives values only where as equals method() should be used to compare objects. The equality operator can invoke subtle issue while comparing primitive to Object. Where as equals() method is used to perform character based comparison. equals() return true if two String represent to the same object or when both strings contents are exactly same but equality() perator returns true if two String object represents to same object but return false if two different String object contains same contents

What is intern() method in Java? The intern() method is of String class. The intern() method is supposed to return the String from the String pool if the String is found in String pool, otherwise a new string object will be added in String pool and the reference of this String is returned. Example: String str1 = "hello"; String str2 = "hello"; String str3 = "hello".intern();

if ( s1 == s2 ){ System.out.println("str1 and str2 are same"); } if ( str1 == str3 ){ System.out.println("str1 and str3 are same" ); } We are assuming that str1 and str3 are same will be printed as str3 is interned, and str1 and str2 are same will not be printed. Actual output is: both lines are printed. Which make clear that by default String constants are interned? When is class garbage collected? Java uses the garbage collector to free memory which is occupied by those objects which is no more reference by any of the program. An object becomes eligible for Garbage Collection when no live thread can access it. There are many ways to make a class reachable and thus prevent it from being eligible for Garbage Collection:

Objects of that class are still reachable. Class object representing the class is still reachable. ClassLoader that loaded the class is still reachable. Other classes loaded by the ClassLoader are still reachable.

When all of the above are false, then the ClassLoader together with all classes it loaded are eligible for Garbage Collection. What is the difference between a Choice and a List? The between Choice and list are following:

Choice class presents a pop-up menu of choices whereas List is a collection of different visible item. Choice is displayed in a compact form, to see the list of available choices we need to scroll down whereas list displays the entire available items. Choice allows selecting only one items but List supports the selection of one or more List items. Lists typically allow duplicate elements selection. List allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all.

What is JCA in java? Java Cryptography Architecture term from Sun for implementing security functions for the Java platform. It provides a platform and gives architecture and APIs for encryption and decryption. JCA is used by the developer to combine the application with the security measure. A

programmer uses the JCA to meet the security measure. It helps in performing the third partly security rules. It uses the hash table, encryption message digest, etc to implement the security. What is JPA in java? The Java Persistence API is enabling us to create the persistence layer for desktop and web applications. Java Persistence deals in following:

Java Persistence API Query language Java Persistence Criteria API Object mapping metadata

What is difference between eager and lazy loading? The difference between eager and loading are:

Eager loading means to load the data before the requirement whereas lazy loading mean that load the data only when required. Eager loading fetch the data in one query whereas lazy loading fetch the data when needed by triggering the sub query.

What is JMS in Java? Java Message Service (JMS) is used for creating the communication interface between two clients by using the message passing services. This helps the application to interact with other components irrespective of components location whether they rely on same system or connect to the main system through LAN or internet. What is shallow cloning and deep cloning? Shallow copy: in this object is copied without its contained objects. Shallow clone only copies the top level structure of the object not the lower levels. It is an exact bit copy of all the attributes. Deep copy: In this object is copied along with the objects it refers to. Deep clone copies all the levels of the object from top to the bottom recursively. What is the difference between applications and applets? The differences between an Applet and an application are as follows:

Applets can be embedded in HTML pages and downloaded over the Internet whereas Applications have no special support in HTML for embedding or downloading.

Application starts execution with its main method whereas applet starts execution with its init method. Application must be run on local machine whereas applet needs no explicit installation on local machine. Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser. Application can run with or without graphical user interface whereas applet must run within a graphical user interface.

What are Class loaders? Class loader enables the program to load the class at run time. This is located in the java.lang package. Using Class Loader we can also load the customize classes which is required for the application execution. The class loaders in Java are organized in a tree. When JVM is started three class loaders are used:

Bootstrap class loader: the core java libraries. It is written in native code. Extensions class loader: loads the code in the extension directories. It is implemented by ExtClassLoader class. System class loader: code found on the java.class.path which map to the system class path variables. It is implemented by AppClassLoader class. All user classes by default are load by the system class loader.

What is the Comparable interface? The Comparable interface is used to sort collections and arrays of objects using the collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered. All classes implementing the Comparable interface must implement the compareTo() method that has the return type as an integer. The signature of the compareTo() method is as follows: int i = object1.compareTo(object2)

If object1 < object2: The value of i returned will be negative. If object1 > object2: The value of i returned will be positive. If object1 = object2: The value of i returned will be zero.

What is Single Threaded Model in Servlets? Single Thread Model is a marker interface which contains no methods and variable in it.

When using Single thread model with Servlet, it make sure that that only one thread can be executed at a time. It avoids running of two or more thead simultaneously. If we wants to make single threaded we can implement this interface in the following fashion.

public class SingleThreadedTest implements SingleThreadModel { //some code } What are the different Authentication Options available in Servets? Authentication options available in Servlets: There are four different options for authentication in servlet: 1. Basic Authentication: Username and password provided by the client to authenticate the user. 2. Form-based authentication- In this the login form is made by the programmer by using HTML. 3. Digest Authentication- It is similar to basic authentication but in this the passwords are encrypted using Hash formula. This makes digest more secured. 4. Client certificate Authentication- It requires that each client accessing the resource has a certificate that it send to authenticate itself. This requires SSL protocol. What is the disadvantage of garbage collector? Garbage Collector runs in its own thread which affects the performance of the system. It increases the workload of JVM because it constantly monitor the object which is not referenced.. The two main disadvantages of garbage collector are:

TIME: to collect all those no referenced object JVM spends a considerable amount of time by scanning the entire heap. Mark and sweep: some time it is difficult to implement mark and sweep in the application.

Does java support global variable? No, java does not support global variable because of the following reasons:

Globally accessible: global variables are globally accessible. Referential transparency: global variable breaks the referential transparency and also a global variable generate problem in the namespace. Object oriented: As JAVA is object oriented language so where each variable is declared inside the class. To use this variable, object should be initialized.

Explain different layout manager in Java. There are following types of layouts are used to organize or to arrange objects:

Border Layout: Have five areas for holding components: north, east, west, south and center. Flow Layout: Default layout manager, lays out the components from left to right Card Layout: Different components at different times are laid out, Controlled by a combo box. Grid Layout: Group of components are laid out I equal size and displays them in certain rows and columns. Grid Bag Layout: Flexible layout for placing components within a grid of cells.

What is chained exceptions in java? When in a program the first exception causes another exception that is termed as Chained Exception. Chained exceptions helps in finding the root cause of the exception that occurs during applications execution. The constructors that support chained exceptions in Throwable classes are:

Throwable initCause(Throwable) Throwable(Throwable) Throwable(String, Throwable) Throwable getCause()

When is the main thread stop in java? When we execute the java program, it call the main() method because main() method is the first thread in the program. This main() method or thread invokes the other thread which is required for the complete execution of the program. The main thread should be the last thread in the program to end. so to make main() method to be last we make sure when we called to another function by giving execution control to that must return the control back to the main() method. What are the ways to create child threads? There are two ways to create java threads:

Implementing the Runnable interface: this overcomes the limitation of inheriting from only one parent class Thread. Using Runnable interface, lays a path to ground work of a class that utilizes threads Extending Thread class: It inherits the methods and data members, fields from the class tread. In this process only one class can be inherited from the parent class Thread. The advantage is a class can extend Thread class and also implements the Runnable

interface, if required. The Runnable interface is set for implementing a thread and the class that implements the interface performs all the work. Why bytecode is important to Java? The compiled Java source code is known as byte code. We need bytecode due to following reasons:

Is independent of the input language. Plays an important role in the execution speed of the application. Can run on any platform irrespective of system architecture. Can be used for internet applications where security is important Enable us to load classes which are required for the execution of the application. allows the web applications to run on various platforms, on various browsers on different infrastructures.

What is an Iterator and explain traversing through a collector using Iterator? We can access each element in the Collection by using Iterators irrespective of how they are organized in the collector. Iterator can be implemented a different way for every Collection. To use an iterator to traverse through the contents of a collection we do:

Obtain an iterator by calling the collections iterator() method to the start of the collection. Set up a loop that makes a call to hasNext(). Have the loop iterate as long as hasNext()returns true. Within the loop, obtain each element by calling next(). remove() method is used to remove the current element in the iteration.

What is Race condition? Race Condition: it is the situation when two threads raise the request for the same resource allocation, but the manner in which resources are allocated are significant, is called race conditions.

Race condition is created in program in order to run the parallel execution of program by using multiple threads in a same period. A race condition occurs when two threads operate on same object without proper synchronization and there operation interleaves on each other. The risk of Race condition is higher in Java.

What is difference between Java and JavaScript? The difference between java and java scripts are:

Java is an Object Oriented Programming Language and capable of running on multiple operating systems with the help of interpreter whereas Java Script is the object oriented scripting language and it is embedded in HTML and runs directly on the browser. JVM is used to executed java program on different program whereas Java Script code is not compiled they are directly run on the browser. Java language is used to develop the software whereas java script is used providing interactivity to the simple HTML pages.

What is the difference between factory and abstract factory pattern? The differences between factory and abstract factory are following:

Factory pattern is a single method but abstract factory is an object. The Abstract Factory pattern is one level of abstraction higher than the factory pattern. Factory pattern generally returns the common parent class or method whereas the abstract factory pattern returns the one of the several factories.

What is Singleton? Singleton in Java is a class with just one instance in whole Java application.

This make sure that only one instance of a class is created. getInstance() method is used to get single instance of the class. It creates a global point to access all object

What is the difference between JAR and WAR files? The differences between JAR and WAR files are:

JAR files (Java Archive) allows combining many files into one whereas WAR files (Web Application Archive) stores XML, java classes, and JavaServer pages for Web Application purposes. JAR is used to hold Java classes in a library whereas in WAR files are stored in lib directory of the application. In this EJB module which contains enterprise java beans class files and EJB deployment descriptor are packed as JAR files with .jar extension whereas in WAR web modules which contains Servlet class files, JSP Files, GIF and HTML files are packaged as JAR file with .war extension.

You might also like