Java interview questions and answers for freshers and experienced

Java Interview questions for freshers as well 1 to 3 year experienced on advance and basic Java, J2ME, J2ee, Servlet, JSP, Struts, Spring, hibernate framework with examples that cover the essentials of java j2ee means all type of java questions covered under this page and also a form is given at the end of this page for those user who want more Interview questions and answer on core and advanced java just need to fill the form and send us we will send all the answers to them and it for both freshers and experienced condidate and also chat option is given in right hand side for directly chat with expert for answers

Top Most common Java Interview Questions and Answers

Questions : 1 What is JVM (Java Virtual Machine) ?
Answers : 1

JVM stands for Java Virtual Machine. Its an abstract computer or virtual computer which runs the compiled java programs. Actually JVM is a software implementation which stands on the top of the real hardware platform and operating system. It provides abstraction between the compiled java program and the hardware and operating system. So the compiled program does not have to worry about what hardware and operating system he has to run in, its all handled by the JVM and thus attaining portability. All Java programs are compiled in to bytecodes. JVM can only understand and execute Java bytecodes. we can visualize Java bytecodes as machine language for JVM. Java compiler takes the .java files and compiles it to a bytecode file with .class file extension. Compiler generates one class file for one source file.

   
Questions : 2 What is JIT (Just-in-Time) Compilation ?
Answers : 2

advertisements

When JVM compiles the class file he does not compile the full class file in one shot. Compilation is done on function basis or file basis. Advantage gained from this is that heavy parsing of original source code is avoided. Depending on need basis the compilation is done. This typ of compilation is termed as JIT or Just-in- Time compilation.

   
Questions : 3 How do you implement inheritance in Java?
Answers : 3

nheritance is implemented by using EXTEND” keyword.

   
Questions : 4 How can we implement polymorphism in Java ?
Answers : 4

Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. There are two types of polymorphism:-
Method Polymorphism through overloading.
Object polymorphism by inheritance / interfaces.

   
Questions : 5 What are packages ?
Answers : 5

Packages group related classes and interfaces together and thus avoiding any name conflicts. From OOPs point of view packages are useful for grouping related classes together. Classes are group together in a package using package” keyword.

   
Questions : 6 What is the use if instanceof” keyword ?
Answers : 6

instanceof ” keyword is used to check what is the type of object. F

   
Questions : 7 What are Native methods in Java ?
Answers : 7

There may be times when we want to call subroutines which are written in some other language other than Java like C++, VB6 etc.

   
Questions : 8 Explain in depth Garbage collector ?
Answers : 8

Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. This frees the programmer from having to keep track of when to free allocated memory, thereby preventing many potential bugs. Thus making programmers more productive as they can now put more effort in coding rather than worrying about memory management.

The only disadvantage of garbage collector is it adds overheads. Because the JVM (Java virtual machine) has to keep a constant track of the objects which are not referenced and then free these unreferenced objects on fly. This whole process has a slight impact on the application performance. But garbage collector has a good algorithm and it runs in its own thread thus having a least impact on the application performance but still it has some impact.

   
Questions : 9 How can we force the garbage collector to run?
Answers : 9

Garbage collector can be run forcibly using System.gc()” or Runtime.gc()”

   
Questions : 10 Whats the use of JAVAP tool ?
Answers : 10

javap disassembles compiled Java files and spits out representation of the Java program. This is a useful option when the original source code is not available.

   
Questions : 11 What are applets ?
Answers : 11

Applets are small applications that are accessed from web server automatically installed, and run from the browser. Once an applet arrives on the client it has limited access to resources thus ensuring security for the end user. An applet is controlled by the software that runs it. Usually, the underlying software is a browser, but it can also be applet viewer. If you run the applet source code from eclipse it runs inside an applet viewer. All applets should inherit from applet class.
Below are sequences of events which occur in applet:-
The init Method: The init method is called when the applet is first loaded. Init method can be used to initialize color, fonts or any type of one type operation needed for the applet.
The start Method: The start method is called when user visits a browser with an applet on it. In start method applet spawns a thread in which it runs the paint method.
paint() is called every time when applet has to re-display everything. paint() event can occur due to various reasons some of the reasons are :-.

   
Questions : 12 In which package is the applet class located?
Answers : 12

Applet classes are located in " java.applet "package.

   
Questions : 13 How can you copy one array in to a different array?
Answers : 13

System.arraycopy(myOldArray, 0, myNewArray, 0, length);+

   
Questions : 14 Can you explain the core collection interfaces?
Answers : 14

There are six interfaces and come under two different inheritance group one which comes under the collection interface root and the other in the map interface root.

Collection
Its the base of all collection classes. It provides a unified way to manipulate collection objects. Collection has group of object called as elements. These elements can be accessed and manipulated using Iterator. List
In List interface the elements are arranged sequentially. Elements can be inserted in to any location and you can also insert duplicate elements. In order to access the elements you need to use the ListIterator”. Using ListIterator” you can move back and forth which makes it unique as compared to other iterators.
Set
It represents a collection but no duplicates are allowed in this case.
SortedSet
It extends the Set interface and sorts the set in ascending order.
Map
Map stores association between keys and value pairs. So given a key you can easily find the value. One thing important to note is they do not implement iterable interface. But yes you can obtain a collection view of the map which allows you loop using for loop.
SortedMap
t Extends Map so that the keys are maintained in ascending order.

   
Questions : 15 whats the main difference between ArrayList / HashMap and Vector / Hashtable?
Answers : 15

Vector / HashTable are synchronized which means they are thread safe. Cost of thread safe is performance degradation. So if you are sure that you are not dealing with huge number of threads then you should use ArrayList / HashMap.But yes you can still
synchronize List and Maps using Collections provided methods :-
List OurList = Collections.synchronizedList (OurList);
Map OurMap = Collections.synchronizedMap (OurMap);

   
Questions : 16 what is a StringBuffer class and how does it differs from String class?
Answers : 16

StringBuffer is a peer class of String that provides almost all functionality of strings. String represents fixed-length, immutable character sequences. Comparatively StringBuffer represents mutable, growable and writeable character sequences. But StringBuffer does not create new instances as string so its more efficient when it comes to intensive concatenation operation.

   
Questions : 17 What is JAVAdoc utility?
Answers : 17

Javadoc parses comments in JAVA source files and produced HTML pages for the same. Below is the syntax for the same javadoc [ options ] [ packagenames ] [ sourcefiles ] [ @files ] Arguments can be in any order. Options Command-line options that is doctitle, windowtitle, header, bottom etc
Packagenames: -
A series of names of packages, separated by spaces, such as java.lang java.lang.reflect java.awt. You must separately specify each package you want to document. Javadoc uses -sourcepath to look for these package names. Javadoc does not recursively traverse subpackages.
sourcefiles :-
A series of source file names, separated by spaces, each of which can begin with a path and contain a wildcard such as asterisk (*). The path that precedes the source file name determines where javadoc will look for it. (Javadoc does not use -sourcepath to look for these source file names.)
@files: - One or more files that contain packagenames and sourcefiles in any order, one name per line.

   
Questions : 18 How much subclasses you can maximum in Inheritance?
Answers : 18

In one of our old JAVA projects we had an inheritance depth of five. Believe us we never liked that code. Its bad to have a huge inheritance depth. A maintainable inheritance depth should be maximum 5. Anything above that is horrible. There is no limit as such specified anywhere that there is some limit on the inheritance sub classing . But depending on environments you will get stack over flow error.

   

Next Page 1 | Next Page 2 | Next Page 3

Objective Questions

Which is the most suitable Java collection class for storing various companies and their stock prices?

• A. Hashtable
• B. HashMap
• C. LinkedHashMap
• D. HashSet
• E. TreeMap

Download Good eBooks PDF On Java

JSP Questions And Answers

Threads Questions And Answers

EJB Questions And Answers

Servlets Questions And Answers

Struts Questions And Answers

Spring Questions And Answers

I/O: EXPLORING Examples

Event handling Questions

java Objective Questions Answers


Ask your interview questions on java

Write Your comment or Questions if you want the answers on java from java Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---