SlideShare a Scribd company logo
JAVA Interview Questions Part-1
JAVA J2EE Training
1) What is the difference between a JDK and a JVM?
JDK is Java Development Kit which is for development purpose and it
includes execution environment also but JVM is purely a run time
environment and hence you will not be able to compile source using JVM.
2) Which are the different segments of memory JVM uses?
a. Stack Segment - contains local variables and Reference variables
(variables that hold the address of an object in the heap).
b. Heap Segment - contains all created objects in runtime, objects only plus
their object attributes (instance variables).
c. Code Segment - The segment where the actual compiled Java byte codes
resides when loaded.
3) What is Java bytecode?
Java bytecode is the instruction set of the Java virtual machine. Each
bytecode is composed by one, or two bytes that represent the instruction,
along with zero or more bytes for passing parameters.
4) What is the base class of all classes?
Java.lang.object
5) What is a pointer? Does Java support pointers?
Pointer means a reference handle to a memory location. Java doesn't
support
the use of pointers as their improper handling causes memory leaks and
compromises the reliability.
6) Does java supports multiple inheritance?
Java doesn’t support multiple inheritance.
7) What is the difference between path and class path?
Path and Class Path are operating system level environment variables. Path
is used define where the system can find executables (.exe) files and class
path is used to specify the location .class files.
8) What is difference between abstract class and interface?
A class is called abstract when it contains at least one abstract method. It can
also contain n numbers of concrete method. Interface can contain only
abstract (non implemented) methods.
The abstract class can have public, private, protect or default variables and
also constants. In interface the variable is by default public final. In nutshell
the interface doesn’t have any variables it only has constants.
A class can extend only one abstract class but a class can implement
multiple interfaces.
If an interface is implemented its compulsory to implement all of its
methods but if an abstract class is extended its not compulsory to implement
all methods.
The problem with an interface is, if you want to add a new feature (method)
in its contract, then you MUST implement those methods in all of the classes
which implement that interface. However, in the case of an abstract class,
the method can be simply implemented in the abstract class and the same
can be called by its subclass.
9) What is the difference between StringBuffer and String class?
A string buffer implements a mutable sequence of characters. A string
buffer
is like a String, but can be modified. At any point in time it contains some
particular sequence of characters, but the length and content of the
sequence
can be changed through certain method calls.
The String class represents character strings. All string literals in Java
programs, such as "abc" are constant and implemented as instances of this
class; their values cannot be changed after they are created.
10) Can static method access instance variables?
Though Static methods cannot access the instance variables directly, they
can access them using instance handler.
11) Difference between implicit and explicit type casting?
An explicit conversion is where you use some syntax to tell the program to
do a conversion whereas in case of implicit type casting you need not
provide the target data type explicitly.
12) What is the difference between final, finally and
finalize()?
final
It is a modifier which can be applied to a class, method or variable. It
is not possible to inherit the final class, override the final method
and change the final variable.
finally
It is an exception handling code section. It gets executed whether an
exception is raised or not by the try block code segment.
finalize()
It is a method of Object class.
It is executed by the JVM just before garbage collecting object to give a
final chance for resource releasing activity.
13) Difference between Abstract and Concrete Class?
Abstract classes are only meant to be sub classed and not meant to be
instantiated whereas concrete classes are meant to be instantiated.
14) Difference between Public, Private, Default and
Protected?
Private: Not accessible outside object scope.
Public: Accessible from anywhere.
Default: Accessible from anywhere within same package.
Protected: Accessible from object and the sub class objects.
15) Explain Autoboxing?
Autoboxing is the automatic conversion that the Java compiler makes
between the primitive types and their corresponding object wrapper
classes.
16) When do you get ClassCastException?
As we downcast objects, The ClassCastException is thrown in case code has
attempted to cast an object to a subclass of which it is not an instance.
17) Does garbage collection guarantee that a program will not
run out of memory?
Garbage collection does not guarantee that a program will not run out of
memory. It is possible for programs to use up memory resources faster
than
they are garbage collected. It is also possible for programs to create objects
that are not subject to garbage collection
18) What is a daemon thread? Give an Example?
These are threads that normally run at a low priority and provide a basic
service to a program or programs when activity on a machine is reduced.
Garbage collector thread is daemon thread.
19) Can a null element be added to a TreeSet or HashSet?
A null element can be added only if the set contains is on size 1 because
when a second element is added then as per set definition a check is made
to
check duplicate value and comparison with null element will throw
NullPointerException. HashSet is based on HashMap and can contain null
element.
20) What is the difference between collections class vs
collections interface?
Collections class is a utility class having static methods for doing operations
on objects of classes which implement the Collection interface. For
example, Collections has methods for finding the max element in a
Collection.
21) What is comparator interface used for?
The purpose of comparator interface is to compare objects of the same
class
to identify the sorting order. Sorted Collection Classes (TreeSet, TreeMap)
have been designed such to look for this method to identify the sorting
order,
that is why class need to implement Comparator interface to qualify its
objects to be part of Sorted Collections.
22) Can we add heterogeneous elements into TreeMap?
No, Sorted collections don't allow addition of heterogeneous elements as
they are not comparable.
23) What is the difference between an Inner Class and a Sub-
Class?
An Inner class is a class which is nested within another class. An Inner class
has access rights for the class which is nesting it and it can access all
variables and methods defined in the outer class.
A sub-class is a class which inherits from another class called super class.
Sub-class can access all public and protected methods and fields of its super
class.
24) What is data encapsulation and what’s its significance?
Encapsulation is a concept in Object Oriented Programming for combining
properties and methods in a single unit.
Encapsulation helps programmers to follow a modular approach for software
development as each object has its own set of methods and variables and
serves its functions independent of other objects. Encapsulation also serves
data hiding purpose.
25) What is the difference between continue and break
statement?
break and continue are two important keywords used in Loops. When a
break keyword is used in a loop, loop is broken instantly while when
continue keyword is used, current iteration is broken and loop continues
with next iteration.
26) Which types of exceptions are caught at compile time?
Checked exceptions can be caught at the time of program compilation.
Checked exceptions must be handled by using try catch block in the code in
order to successfully compile the code.
27) Can we use a default constructor of a class even if an
explicit constructor is defined?
Java provides a default no argument constructor if no explicit constructor is
defined in a Java class. But if an explicit constructor has been defined,
default constructor can’t be invoked and developer can use only those
constructors which are defined in the class.
28) Can we override a method by using same method name
and arguments but different return types?
The basic condition of method overriding is that method name, arguments
as
well as return type must he exactly same as is that of the method being
overridden. Hence using a different return type doesn’t override a method.
29) How destructors are defined in Java?
In Java, there are no destructors defined in the class as there is no need to
do
so. Java has its own garbage collection mechanism which does the job
automatically by destroying the objects when no longer referenced.
30) How objects are stored in Java?
In java, each object when created gets a memory space from a heap. When
an object is destroyed by a garbage collector, the space allocated to it from
the heap is re-allocated to the heap and becomes available for any new
objects.
31) What is the order of call of constructors in inheritance?
In case of inheritance, when a new object of a derived class is created, first
the constructor of the super class is invoked and then the constructor of
the
derived class is invoked.
32) How to create an immutable object in Java? Does all
property of immutable object needs to be final?
To create a object immutable You need to make the class final and all its
member final so that once objects gets crated no one can modify its state.
You can achieve same functionality by making member as non final but
private and not modifying them except in constructor. Also its NOT
necessary to have all the properties final since you can achieve same
functionality by making member as non final but private and not modifying
them except in constructor.
33) What is difference between Enumeration and Iterator
interface?
Enumeration is twice as fast as Iterator and uses very less memory.
Enumeration is very basic and fits to basic needs. But Iterator is much safer
as compared to Enumeration because it always denies other threads to
modify the collection object which is being iterated by it.
Iterator takes the place of Enumeration in the Java Collections Framework.
Iterators allow the caller to remove elements from the underlying collection
that is not possible with Enumeration. Iterator method names have been
improved to make it’s functionality clear.
34) What is difference between Comparable and Comparator
interface?
Comparable and Comparator interfaces are used to sort collection or array of
objects.
Comparable interface is used to provide the natural sorting of objects and we
can use it to provide sorting based on single logic.
Comparator interface is used to provide different algorithms for sorting and
we can choose the comparator we want to use to sort the given collection of
objects.
35) Difference between throw and throws?
throw is used to explicitly throw an exception especially custom exceptions,
whereas throws is used to declare that the method can throw an exception.
We cannot throw multiple exceptions using throw statement but we can
declare that a method can throw multiple exceptions using throws and
comma separator.
36) What are the disadvantages of using arrays?
Arrays are of fixed size and have to reserve memory prior to use. Hence if
we don't know size in advance arrays are not recommended to use.
Arrays can store only homogeneous elements.
Arrays store its values in contentious memory location. Not suitable if the
content is too large and needs to be distributed in memory.
There is no underlying data structure for arrays and no ready made method
support for arrays, for every requirement we need to code explicitly.
37) How substring() method of String class create memory
leaks?
Substring method would build a new String object keeping a reference to the
whole char array, to avoid copying it. Hence you can inadvertently keep a
reference to a very big character array with just a one character string.
38) What is the difference between yield() and sleep()?
When a object invokes yield() it returns to ready state. But when an object
invokes sleep() method enters to not ready state.
39) Why threads block or enter to waiting state on I/O?
Threads enters to waiting state or block on I/O because other threads can
execute while the I/O operations are performed.
40) What is the difference between System.out ,System.err
and System.in?
System.out and System.err both represent the monitor by default and hence
can be used to send data or results to the monitor. But System.out is used to
display normal messages and results whereas System.err is used to display
error messages and System.in represents InputStream object, which by
default represents standard input device, i.e., keyboard.
41) Why Char array is preferred over String for storing
password?
String is immutable in java and stored in String pool. Once it’s created it
stays in the pool until unless garbage collected, so even though we are done
with password it’s available in memory for longer duration and there is no
way to avoid it. It’s a security risk because anyone having access to memory
dump can find the password as clear text.
42) Why String is popular HashMap key in Java?
Since String is immutable, its hashcode is cached at the time of creation and
it doesn’t need to be calculated again. This makes it a great candidate for key
in a Map and it’s processing is fast than other HashMap key objects. This is
why String is mostly used Object as HashMap keys.
43) Difference between Checked and Unchecked exceptions ?
Checked exceptions and the exceptions for which compiler throws an errors
if they are not checked whereas unchecked exceptions and caught during run
time only and hence can't be checked.
44) Does Constructor creates the object?
New operator in Java creates objects. Constructor is the later step in object
creation. Constructor's job is to initialize the members after the object has
reserved memory for itself.
45) Can constructors be synchronized in Java ?
No. Java doesn't allow multi thread access to object constructors so
synchronization is not even needed.
46) Difference between Array List and Linked List ?
Linked List and Array List are two different implementations of the List
interface. Linked List implements it with a doubly-linked list. Array List
implements it with a dynamically resizing array.
47) How can we create objects if we make the constructor
private?
We can do so through a static public member method or static block.
48) Similarity and Difference between static block and static
method ?
Both belong to the class as a whole and not to the individual objects. Static
methods are explicitly called for execution whereas Static block gets
executed when the Class gets loaded by the JVM.
49) What restrictions are placed on method overriding?
Overridden methods must have the same name, argument list, and return
type. The overriding method may not limit the access of the method it
overrides. The overriding method may not throw any exceptions that may
not be thrown by the overridden method.
50) Difference Between this() and super() ?
1. this is a reference to the current object in which this keyword is used
whereas super is a reference used to access members specific to the parent
Class.
2. this is primarily used for accessing member variables if local variables
have same name, for constructor chaining and for passing itself to some
method whereas super is primarily used to initialize base class members
within derived class constructor.

More Related Content

What's hot (18)

Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
Khaled AlGhazaly
 
Core Java
Core JavaCore Java
Core Java
Prakash Dimmita
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 
Advance Java
Advance JavaAdvance Java
Advance Java
Vidyacenter
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
Kernel Training
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
Niyitegekabilly
 
Core java
Core javaCore java
Core java
Shivaraj R
 
Swing api
Swing apiSwing api
Swing api
Ravi_Kant_Sahu
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
vivek shah
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
Math-Circle
 
Core Java Introduction | Basics
Core Java Introduction  | BasicsCore Java Introduction  | Basics
Core Java Introduction | Basics
Hùng Nguyễn Huy
 
Core java online training
Core java online trainingCore java online training
Core java online training
Glory IT Technologies Pvt. Ltd.
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.net
Janbask ItTraining
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Veerabadra Badra
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java Basics
Victer Paul
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
Kernel Training
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
vivek shah
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
Math-Circle
 
Core Java Introduction | Basics
Core Java Introduction  | BasicsCore Java Introduction  | Basics
Core Java Introduction | Basics
Hùng Nguyễn Huy
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.net
Janbask ItTraining
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Java - OOPS and Java Basics
Java - OOPS and Java BasicsJava - OOPS and Java Basics
Java - OOPS and Java Basics
Victer Paul
 

Viewers also liked (18)

Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
javatrainingonline
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
javatrainingonline
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
Exception handling
Exception handlingException handling
Exception handling
Sandeep Rawat
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
Sandeep Rawat
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
Khurshid Asghar
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
ROHIT JAISWAR
 
Core java course syllabus
Core java course syllabusCore java course syllabus
Core java course syllabus
Papitha Velumani
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
Lavanya Arunachalam A
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
mahir jain
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Java lab 2
Java lab 2Java lab 2
Java lab 2
AVC College of Engineering
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
AravindSankaran
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
Naveen Sagayaselvaraj
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
Laura Popovici
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Ad

Similar to Java J2EE Interview Questions Part-1 (20)

20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
Gradeup
 
Core java interview questions1
Core java interview questions1Core java interview questions1
Core java interview questions1
Lahari Reddy
 
Core java questions
Core java questionsCore java questions
Core java questions
Dinesh Reddy G
 
Core java questions
Core java questionsCore java questions
Core java questions
Dinesh Reddy G
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
G C Reddy Technologies
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
Gaurav Mehta
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
Java interview faq's
Java interview faq'sJava interview faq's
Java interview faq's
Deepak Raj
 
__ Java Technical round questions .pdf soo
__ Java Technical round questions .pdf soo__ Java Technical round questions .pdf soo
__ Java Technical round questions .pdf soo
Rajkumar751652
 
Faqs in java
Faqs in javaFaqs in java
Faqs in java
prathap kumar
 
Core java interview faq
Core java interview faqCore java interview faq
Core java interview faq
Kumaran K
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
Sherihan Anver
 
java basic .pdf
java basic .pdfjava basic .pdf
java basic .pdf
Satish More
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
satish reddy
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
satish reddy
 
JAVA INTERVIEW QUESTIONS.pdf java developer engineer
JAVA INTERVIEW QUESTIONS.pdf java developer engineerJAVA INTERVIEW QUESTIONS.pdf java developer engineer
JAVA INTERVIEW QUESTIONS.pdf java developer engineer
MinElectroneum
 
JAVA TECHNICAL INTERVIEW.pdf java developer engineer
JAVA TECHNICAL INTERVIEW.pdf java developer engineerJAVA TECHNICAL INTERVIEW.pdf java developer engineer
JAVA TECHNICAL INTERVIEW.pdf java developer engineer
MinElectroneum
 
Top 100 Java Interview Questions and Answers.pdf
Top 100 Java Interview Questions and Answers.pdfTop 100 Java Interview Questions and Answers.pdf
Top 100 Java Interview Questions and Answers.pdf
MinElectroneum
 
Core java questions
Core java questionsCore java questions
Core java questions
Pradheep Ayyanar
 
Java Core
Java CoreJava Core
Java Core
Gaurav Mehta
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
Gradeup
 
Core java interview questions1
Core java interview questions1Core java interview questions1
Core java interview questions1
Lahari Reddy
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
Gaurav Mehta
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
Java interview faq's
Java interview faq'sJava interview faq's
Java interview faq's
Deepak Raj
 
__ Java Technical round questions .pdf soo
__ Java Technical round questions .pdf soo__ Java Technical round questions .pdf soo
__ Java Technical round questions .pdf soo
Rajkumar751652
 
Core java interview faq
Core java interview faqCore java interview faq
Core java interview faq
Kumaran K
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
Sherihan Anver
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
satish reddy
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
satish reddy
 
JAVA INTERVIEW QUESTIONS.pdf java developer engineer
JAVA INTERVIEW QUESTIONS.pdf java developer engineerJAVA INTERVIEW QUESTIONS.pdf java developer engineer
JAVA INTERVIEW QUESTIONS.pdf java developer engineer
MinElectroneum
 
JAVA TECHNICAL INTERVIEW.pdf java developer engineer
JAVA TECHNICAL INTERVIEW.pdf java developer engineerJAVA TECHNICAL INTERVIEW.pdf java developer engineer
JAVA TECHNICAL INTERVIEW.pdf java developer engineer
MinElectroneum
 
Top 100 Java Interview Questions and Answers.pdf
Top 100 Java Interview Questions and Answers.pdfTop 100 Java Interview Questions and Answers.pdf
Top 100 Java Interview Questions and Answers.pdf
MinElectroneum
 
Ad

Recently uploaded (20)

Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
IBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - IntroductionIBM Rational Unified Process For Software Engineering - Introduction
IBM Rational Unified Process For Software Engineering - Introduction
Gaurav Sharma
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free DownloadWondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Bonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdfBonk coin airdrop_ Everything You Need to Know.pdf
Bonk coin airdrop_ Everything You Need to Know.pdf
Herond Labs
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 

Java J2EE Interview Questions Part-1

  • 1. JAVA Interview Questions Part-1 JAVA J2EE Training
  • 2. 1) What is the difference between a JDK and a JVM? JDK is Java Development Kit which is for development purpose and it includes execution environment also but JVM is purely a run time environment and hence you will not be able to compile source using JVM. 2) Which are the different segments of memory JVM uses? a. Stack Segment - contains local variables and Reference variables (variables that hold the address of an object in the heap). b. Heap Segment - contains all created objects in runtime, objects only plus their object attributes (instance variables). c. Code Segment - The segment where the actual compiled Java byte codes resides when loaded. 3) What is Java bytecode? Java bytecode is the instruction set of the Java virtual machine. Each bytecode is composed by one, or two bytes that represent the instruction, along with zero or more bytes for passing parameters.
  • 3. 4) What is the base class of all classes? Java.lang.object 5) What is a pointer? Does Java support pointers? Pointer means a reference handle to a memory location. Java doesn't support the use of pointers as their improper handling causes memory leaks and compromises the reliability. 6) Does java supports multiple inheritance? Java doesn’t support multiple inheritance. 7) What is the difference between path and class path? Path and Class Path are operating system level environment variables. Path is used define where the system can find executables (.exe) files and class path is used to specify the location .class files.
  • 4. 8) What is difference between abstract class and interface? A class is called abstract when it contains at least one abstract method. It can also contain n numbers of concrete method. Interface can contain only abstract (non implemented) methods. The abstract class can have public, private, protect or default variables and also constants. In interface the variable is by default public final. In nutshell the interface doesn’t have any variables it only has constants. A class can extend only one abstract class but a class can implement multiple interfaces. If an interface is implemented its compulsory to implement all of its methods but if an abstract class is extended its not compulsory to implement all methods. The problem with an interface is, if you want to add a new feature (method) in its contract, then you MUST implement those methods in all of the classes which implement that interface. However, in the case of an abstract class, the method can be simply implemented in the abstract class and the same can be called by its subclass.
  • 5. 9) What is the difference between StringBuffer and String class? A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented as instances of this class; their values cannot be changed after they are created. 10) Can static method access instance variables? Though Static methods cannot access the instance variables directly, they can access them using instance handler. 11) Difference between implicit and explicit type casting? An explicit conversion is where you use some syntax to tell the program to do a conversion whereas in case of implicit type casting you need not provide the target data type explicitly.
  • 6. 12) What is the difference between final, finally and finalize()? final It is a modifier which can be applied to a class, method or variable. It is not possible to inherit the final class, override the final method and change the final variable. finally It is an exception handling code section. It gets executed whether an exception is raised or not by the try block code segment. finalize() It is a method of Object class. It is executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity. 13) Difference between Abstract and Concrete Class? Abstract classes are only meant to be sub classed and not meant to be instantiated whereas concrete classes are meant to be instantiated.
  • 7. 14) Difference between Public, Private, Default and Protected? Private: Not accessible outside object scope. Public: Accessible from anywhere. Default: Accessible from anywhere within same package. Protected: Accessible from object and the sub class objects. 15) Explain Autoboxing? Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. 16) When do you get ClassCastException? As we downcast objects, The ClassCastException is thrown in case code has attempted to cast an object to a subclass of which it is not an instance.
  • 8. 17) Does garbage collection guarantee that a program will not run out of memory? Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection 18) What is a daemon thread? Give an Example? These are threads that normally run at a low priority and provide a basic service to a program or programs when activity on a machine is reduced. Garbage collector thread is daemon thread. 19) Can a null element be added to a TreeSet or HashSet? A null element can be added only if the set contains is on size 1 because when a second element is added then as per set definition a check is made to check duplicate value and comparison with null element will throw NullPointerException. HashSet is based on HashMap and can contain null element.
  • 9. 20) What is the difference between collections class vs collections interface? Collections class is a utility class having static methods for doing operations on objects of classes which implement the Collection interface. For example, Collections has methods for finding the max element in a Collection. 21) What is comparator interface used for? The purpose of comparator interface is to compare objects of the same class to identify the sorting order. Sorted Collection Classes (TreeSet, TreeMap) have been designed such to look for this method to identify the sorting order, that is why class need to implement Comparator interface to qualify its objects to be part of Sorted Collections. 22) Can we add heterogeneous elements into TreeMap? No, Sorted collections don't allow addition of heterogeneous elements as they are not comparable.
  • 10. 23) What is the difference between an Inner Class and a Sub- Class? An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class. A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class. 24) What is data encapsulation and what’s its significance? Encapsulation is a concept in Object Oriented Programming for combining properties and methods in a single unit. Encapsulation helps programmers to follow a modular approach for software development as each object has its own set of methods and variables and serves its functions independent of other objects. Encapsulation also serves data hiding purpose. 25) What is the difference between continue and break statement? break and continue are two important keywords used in Loops. When a break keyword is used in a loop, loop is broken instantly while when continue keyword is used, current iteration is broken and loop continues with next iteration.
  • 11. 26) Which types of exceptions are caught at compile time? Checked exceptions can be caught at the time of program compilation. Checked exceptions must be handled by using try catch block in the code in order to successfully compile the code. 27) Can we use a default constructor of a class even if an explicit constructor is defined? Java provides a default no argument constructor if no explicit constructor is defined in a Java class. But if an explicit constructor has been defined, default constructor can’t be invoked and developer can use only those constructors which are defined in the class.
  • 12. 28) Can we override a method by using same method name and arguments but different return types? The basic condition of method overriding is that method name, arguments as well as return type must he exactly same as is that of the method being overridden. Hence using a different return type doesn’t override a method. 29) How destructors are defined in Java? In Java, there are no destructors defined in the class as there is no need to do so. Java has its own garbage collection mechanism which does the job automatically by destroying the objects when no longer referenced. 30) How objects are stored in Java? In java, each object when created gets a memory space from a heap. When an object is destroyed by a garbage collector, the space allocated to it from the heap is re-allocated to the heap and becomes available for any new objects.
  • 13. 31) What is the order of call of constructors in inheritance? In case of inheritance, when a new object of a derived class is created, first the constructor of the super class is invoked and then the constructor of the derived class is invoked. 32) How to create an immutable object in Java? Does all property of immutable object needs to be final? To create a object immutable You need to make the class final and all its member final so that once objects gets crated no one can modify its state. You can achieve same functionality by making member as non final but private and not modifying them except in constructor. Also its NOT necessary to have all the properties final since you can achieve same functionality by making member as non final but private and not modifying them except in constructor.
  • 14. 33) What is difference between Enumeration and Iterator interface? Enumeration is twice as fast as Iterator and uses very less memory. Enumeration is very basic and fits to basic needs. But Iterator is much safer as compared to Enumeration because it always denies other threads to modify the collection object which is being iterated by it. Iterator takes the place of Enumeration in the Java Collections Framework. Iterators allow the caller to remove elements from the underlying collection that is not possible with Enumeration. Iterator method names have been improved to make it’s functionality clear. 34) What is difference between Comparable and Comparator interface? Comparable and Comparator interfaces are used to sort collection or array of objects. Comparable interface is used to provide the natural sorting of objects and we can use it to provide sorting based on single logic. Comparator interface is used to provide different algorithms for sorting and we can choose the comparator we want to use to sort the given collection of objects.
  • 15. 35) Difference between throw and throws? throw is used to explicitly throw an exception especially custom exceptions, whereas throws is used to declare that the method can throw an exception. We cannot throw multiple exceptions using throw statement but we can declare that a method can throw multiple exceptions using throws and comma separator. 36) What are the disadvantages of using arrays? Arrays are of fixed size and have to reserve memory prior to use. Hence if we don't know size in advance arrays are not recommended to use. Arrays can store only homogeneous elements. Arrays store its values in contentious memory location. Not suitable if the content is too large and needs to be distributed in memory. There is no underlying data structure for arrays and no ready made method support for arrays, for every requirement we need to code explicitly.
  • 16. 37) How substring() method of String class create memory leaks? Substring method would build a new String object keeping a reference to the whole char array, to avoid copying it. Hence you can inadvertently keep a reference to a very big character array with just a one character string. 38) What is the difference between yield() and sleep()? When a object invokes yield() it returns to ready state. But when an object invokes sleep() method enters to not ready state. 39) Why threads block or enter to waiting state on I/O? Threads enters to waiting state or block on I/O because other threads can execute while the I/O operations are performed. 40) What is the difference between System.out ,System.err and System.in? System.out and System.err both represent the monitor by default and hence can be used to send data or results to the monitor. But System.out is used to display normal messages and results whereas System.err is used to display error messages and System.in represents InputStream object, which by default represents standard input device, i.e., keyboard.
  • 17. 41) Why Char array is preferred over String for storing password? String is immutable in java and stored in String pool. Once it’s created it stays in the pool until unless garbage collected, so even though we are done with password it’s available in memory for longer duration and there is no way to avoid it. It’s a security risk because anyone having access to memory dump can find the password as clear text. 42) Why String is popular HashMap key in Java? Since String is immutable, its hashcode is cached at the time of creation and it doesn’t need to be calculated again. This makes it a great candidate for key in a Map and it’s processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys. 43) Difference between Checked and Unchecked exceptions ? Checked exceptions and the exceptions for which compiler throws an errors if they are not checked whereas unchecked exceptions and caught during run time only and hence can't be checked.
  • 18. 44) Does Constructor creates the object? New operator in Java creates objects. Constructor is the later step in object creation. Constructor's job is to initialize the members after the object has reserved memory for itself. 45) Can constructors be synchronized in Java ? No. Java doesn't allow multi thread access to object constructors so synchronization is not even needed. 46) Difference between Array List and Linked List ? Linked List and Array List are two different implementations of the List interface. Linked List implements it with a doubly-linked list. Array List implements it with a dynamically resizing array. 47) How can we create objects if we make the constructor private? We can do so through a static public member method or static block.
  • 19. 48) Similarity and Difference between static block and static method ? Both belong to the class as a whole and not to the individual objects. Static methods are explicitly called for execution whereas Static block gets executed when the Class gets loaded by the JVM. 49) What restrictions are placed on method overriding? Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method. 50) Difference Between this() and super() ? 1. this is a reference to the current object in which this keyword is used whereas super is a reference used to access members specific to the parent Class. 2. this is primarily used for accessing member variables if local variables have same name, for constructor chaining and for passing itself to some method whereas super is primarily used to initialize base class members within derived class constructor.