SlideShare a Scribd company logo
Core Java
Java Interview Questions & Answers - 1
What does this presentation Include?
These set of slides include basic Java Interview Questions and answers which can be
very helpful for a Software Engineer to attend an interview. I also have included a set of
bit complex Java Questions in ‘Java Interview Questions & Answers - 2’ presentation.
Introduction
1. What is a class and an object in OOP?
• An object is a real world entity which has a state and a behavior.
• In OOP object refers to a particular instance of a class.
• A Class is a Collection of Objects. It is a blue print which can be used to
create objects
2. What are the basic Fundamentals of OOP?
• Abstraction,
• Polymorphism
• Inheritance
• Encapsulation
3. Explain Abstraction
Through the process of abstraction, a programmer hides all but the relevant data
about an object in order to reduce complexity and increase efficiency.
OR
Hiding all the internal details and showing functionality is called abstraction.
4. Explain Polymorphism and state two ways
to implement polymorphism
Polymorphism is the ability of an object to take on many forms.
OR
One task performed in different ways.
Ways to implement it…
– Method Overloading
– Method Overriding
– When parent class reference is used to refer to a child class object
5. Explain Encapsulation and state how
encapsulation can be applied in a java
class
Binding and wrapping code and data together as a single unit is called as
encapsulation
How to apply in a java class?
Having all the fields/properties of the class private and implementing public
getters and setters to access them
6. Explain Inheritance and State two
advantages of using Inheritance
One object acquires properties and behaviors of a parent object
• Provides code reusability
• Used to achieve runtime polymorphism
• Code enhancement- built on what you have, without altering the present funct
ionality.
7. What are the main data types available in
java? State all the primitive data types
Primitive data types and reference/object data types
There are eight primitive data types in java
• short
• byte
• int
• long
• double
• float
• char
• boolean
8. What is static keyword mean in java?
Static says that it always operates within the class (belongs to the class) not in
specific objects.
9.What do you mean by operator precedence
in java?
Java has well-defined rules for specifying the order in which the operators in an
expression are evaluated when the expression has several operators.
For example, multiplication and division have a higher precedence than addition
and subtraction.
10. Can we override and overload main
method of a java application
We can overload main method by changing the no of arguments or the type of
the arguments but we cannot override main method.
11. State three features of a constructor in
java
• Constructor name must be as same as the class name
• Must not have an explicit return type
• Constructor need not to be invoked explicitly
• Java compiler provides a default constructor if you haven’t implemented any
constructors explicitly
12. What is constructor overloading?
A class having more than one constructor having changed each of its parameters
changed (no of parameters or type of parameters)
13. How can you call one constructor from an
other constructor
Using this() keyword
e.g:-
Employee(int a){
}
Employee(int a String b){
this(a);
}
14. State two ways to copy objects in java
Copy by constructor and using clone() method
15. What are the access modifiers in java?
• private
• Default
• protected
• public
16. What happens when fields of a class are
marked as protected?
Those fields can only be accessed from its subclasses
17. What is method overloading and how can
it be implemented?
If a class have multiple methods by same name but different parameters it is
known as method overloading
Can implement his by changing the types of the parameters or the number of the
parameters
18. Can method overloading be implemented
by changing the return type of a method? If n
ot why?
No. It gives a compile time error because there will be an ambiguity when calling
the methods
19. State three places where the ‘super’ key
word is used in java
• Super is used to refer the immediate parent class instance variable
e.g:- super.length
• Super() is used to invoke the immediate parent class constructor
• Super is used to invoke immediate parent class method e.g:- super.calculate()
20. What is runtime polymorphism?
Since in method overriding both the super class and the subclass methods have
the same method, compiler doesn’t figure out which method to be invoked during
compile time. In this case JVM decides which method to call during runtime. This
is called as runtime polymorphism
21. What is method overriding in java?
If subclass provides the specific implementation of a method that has been provi
ded in the parent class, it is known as method overriding.
22. Define rules of method overriding?
• Method must have the same name of the super class method
• Method must have the same parameter as in the parent class
• There must be an IS-A relationship
23. Can we override methods by changing
the return type?
Yes. We can override methods by changing their return type only if their return
type is a sub type.
24. Can we override static methods in java?
No. Static methods cannot be overridden thus the main method if a java program
also cannot be overridden
25. State two differences between HashMap
and HashTable
• HashMap permits one null key and any number of null values in it whereas
HashTable doesn’t allow null values
• HashTable is Synchronized (two thread cannot access the HashTable at the
same time) whereas HashMap is not synchronized
• HashMap is not thread safe but HashTable is thread safe
• HashMap are much faster than HashTable
26. What is an Exception and what is
Exception handling
Exception is an unexpected behavior of a program which could possibly quit the
program during runtime unexpectedly.
By handling the exceptions we allow the applications to run its normal flow.
27. State two Checked Exceptions
• IOException
• SQLEXception
28. State two unchecked exceptions
(runtime exceptions)
• ArithmeticException
• NumberformatException
• NullPointerException
• ArrayindexOutOfBoundsException

More Related Content

PPTX
Basics of Java
Sherihan Anver
 
PPTX
Java interview questions 2
Sherihan Anver
 
PPT
Most Asked Java Interview Question and Answer
TOPS Technologies
 
PPTX
Object+oriented+programming+in+java
Ye Win
 
PPT
Object Oriented Programming with Java
backdoor
 
DOCX
Basic java important interview questions and answers to secure a job
Garuda Trainings
 
DOCX
Core java notes with examples
bindur87
 
PPTX
oops concept in java | object oriented programming in java
CPD INDIA
 
Basics of Java
Sherihan Anver
 
Java interview questions 2
Sherihan Anver
 
Most Asked Java Interview Question and Answer
TOPS Technologies
 
Object+oriented+programming+in+java
Ye Win
 
Object Oriented Programming with Java
backdoor
 
Basic java important interview questions and answers to secure a job
Garuda Trainings
 
Core java notes with examples
bindur87
 
oops concept in java | object oriented programming in java
CPD INDIA
 

What's hot (20)

DOCX
Java questions for viva
Vipul Naik
 
PDF
Java Reflection
Hamid Ghorbani
 
PDF
Java inheritance
Hamid Ghorbani
 
PPT
Java Basics
Dhanunjai Bandlamudi
 
DOC
Java interview questions
G C Reddy Technologies
 
PPT
Core Java interview questions-ppt
Mayank Kumar
 
PDF
Java Interview Questions by NageswaraRao
JavabynataraJ
 
PPT
Core java
kasaragaddaslide
 
PPT
Java Tutorial
Singsys Pte Ltd
 
ODP
OOP java
xball977
 
PPTX
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
PDF
Java Threads
Hamid Ghorbani
 
PDF
20 most important java programming interview questions
Gradeup
 
PDF
Basic Java Programming
Math-Circle
 
DOCX
Interview Questions and Answers for Java
Garuda Trainings
 
PPTX
C# interview
Thomson Reuters
 
PPTX
Object oriented programming in java
Elizabeth alexander
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PPT
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 
PPT
Java Basics
shivamgarg_nitj
 
Java questions for viva
Vipul Naik
 
Java Reflection
Hamid Ghorbani
 
Java inheritance
Hamid Ghorbani
 
Java interview questions
G C Reddy Technologies
 
Core Java interview questions-ppt
Mayank Kumar
 
Java Interview Questions by NageswaraRao
JavabynataraJ
 
Core java
kasaragaddaslide
 
Java Tutorial
Singsys Pte Ltd
 
OOP java
xball977
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
 
Java Threads
Hamid Ghorbani
 
20 most important java programming interview questions
Gradeup
 
Basic Java Programming
Math-Circle
 
Interview Questions and Answers for Java
Garuda Trainings
 
C# interview
Thomson Reuters
 
Object oriented programming in java
Elizabeth alexander
 
Polymorphism in java
Elizabeth alexander
 
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 
Java Basics
shivamgarg_nitj
 
Ad

Viewers also liked (20)

DOC
Qtp Faq
G.C Reddy
 
DOC
Web Dictionary
G.C Reddy
 
PPT
Collection Framework in java
CPD INDIA
 
PDF
Java Programming - 01 intro to java
Danairat Thanabodithammachari
 
PPTX
Core java online training
Glory IT Technologies Pvt. Ltd.
 
ODP
Toolbarexample
yugandhar vadlamudi
 
PPT
02basics
Waheed Warraich
 
DOCX
Java Exception handling
Garuda Trainings
 
PDF
Java quick reference v2
Christopher Akinlade
 
PDF
Yaazli International Spring Training
Arjun Sridhar U R
 
PDF
Yaazli International Hibernate Training
Arjun Sridhar U R
 
PPT
09events
Waheed Warraich
 
PDF
Yaazli International AngularJS 5 Training
Arjun Sridhar U R
 
PPTX
Exception handling in java
yugandhar vadlamudi
 
PDF
Yaazli International Web Project Workshop
Arjun Sridhar U R
 
PPTX
For Loops and Variables in Java
Pokequesthero
 
DOC
Non ieee dot net projects list
Mumbai Academisc
 
PDF
Java Basic Operators
Shahid Rasheed
 
ODP
Singleton pattern
yugandhar vadlamudi
 
Qtp Faq
G.C Reddy
 
Web Dictionary
G.C Reddy
 
Collection Framework in java
CPD INDIA
 
Java Programming - 01 intro to java
Danairat Thanabodithammachari
 
Core java online training
Glory IT Technologies Pvt. Ltd.
 
Toolbarexample
yugandhar vadlamudi
 
02basics
Waheed Warraich
 
Java Exception handling
Garuda Trainings
 
Java quick reference v2
Christopher Akinlade
 
Yaazli International Spring Training
Arjun Sridhar U R
 
Yaazli International Hibernate Training
Arjun Sridhar U R
 
09events
Waheed Warraich
 
Yaazli International AngularJS 5 Training
Arjun Sridhar U R
 
Exception handling in java
yugandhar vadlamudi
 
Yaazli International Web Project Workshop
Arjun Sridhar U R
 
For Loops and Variables in Java
Pokequesthero
 
Non ieee dot net projects list
Mumbai Academisc
 
Java Basic Operators
Shahid Rasheed
 
Singleton pattern
yugandhar vadlamudi
 
Ad

Similar to Java interview questions 1 (20)

PDF
Java_Question-Bank.docx-1.pdf
Nguyen Huu Thuong
 
PDF
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
PDF
Android interview questions
satish reddy
 
PDF
Android interview questions
satish reddy
 
PDF
__ Java Technical round questions .pdf soo
Rajkumar751652
 
DOCX
Corejavainterviewquestions.doc
Joyce Thomas
 
PDF
Top 100 Java Interview Questions with Detailed Answers
Whizlabs
 
PDF
Java interview questions and answers
kavinilavuG
 
DOC
Core java interview questions
Vinay Kumar
 
PPTX
Java J2EE Interview Questions Part-1
javatrainingonline
 
PPTX
Java J2EE Interview Questions Part-1
Mindsmapped Consulting
 
PDF
Core Java Interview Questions with Answers.pdf
SudhanshiBakre1
 
PDF
java-2marks-qzcvhsvnmdjdvjndcsdcuestions-with-answer.pdf
vijaybabu0905
 
DOC
Java interview faq's
Deepak Raj
 
DOCX
Java Core Parctical
Gaurav Mehta
 
PDF
Java interview questions
rithustutorials
 
DOC
Core java questions
Dinesh Reddy G
 
DOC
Core java questions
Dinesh Reddy G
 
DOC
Faqs in java
prathap kumar
 
Java_Question-Bank.docx-1.pdf
Nguyen Huu Thuong
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
Android interview questions
satish reddy
 
Android interview questions
satish reddy
 
__ Java Technical round questions .pdf soo
Rajkumar751652
 
Corejavainterviewquestions.doc
Joyce Thomas
 
Top 100 Java Interview Questions with Detailed Answers
Whizlabs
 
Java interview questions and answers
kavinilavuG
 
Core java interview questions
Vinay Kumar
 
Java J2EE Interview Questions Part-1
javatrainingonline
 
Java J2EE Interview Questions Part-1
Mindsmapped Consulting
 
Core Java Interview Questions with Answers.pdf
SudhanshiBakre1
 
java-2marks-qzcvhsvnmdjdvjndcsdcuestions-with-answer.pdf
vijaybabu0905
 
Java interview faq's
Deepak Raj
 
Java Core Parctical
Gaurav Mehta
 
Java interview questions
rithustutorials
 
Core java questions
Dinesh Reddy G
 
Core java questions
Dinesh Reddy G
 
Faqs in java
prathap kumar
 

Recently uploaded (20)

PDF
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
Solar Panel Installation Guide – Step By Step Process 2025.pdf
CRMLeaf
 
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Presentation about variables and constant.pptx
safalsingh810
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Role Of Python In Programing Language.pptx
jaykoshti048
 

Java interview questions 1

  • 1. Core Java Java Interview Questions & Answers - 1
  • 2. What does this presentation Include? These set of slides include basic Java Interview Questions and answers which can be very helpful for a Software Engineer to attend an interview. I also have included a set of bit complex Java Questions in ‘Java Interview Questions & Answers - 2’ presentation. Introduction
  • 3. 1. What is a class and an object in OOP? • An object is a real world entity which has a state and a behavior. • In OOP object refers to a particular instance of a class. • A Class is a Collection of Objects. It is a blue print which can be used to create objects
  • 4. 2. What are the basic Fundamentals of OOP? • Abstraction, • Polymorphism • Inheritance • Encapsulation
  • 5. 3. Explain Abstraction Through the process of abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency. OR Hiding all the internal details and showing functionality is called abstraction.
  • 6. 4. Explain Polymorphism and state two ways to implement polymorphism Polymorphism is the ability of an object to take on many forms. OR One task performed in different ways. Ways to implement it… – Method Overloading – Method Overriding – When parent class reference is used to refer to a child class object
  • 7. 5. Explain Encapsulation and state how encapsulation can be applied in a java class Binding and wrapping code and data together as a single unit is called as encapsulation How to apply in a java class? Having all the fields/properties of the class private and implementing public getters and setters to access them
  • 8. 6. Explain Inheritance and State two advantages of using Inheritance One object acquires properties and behaviors of a parent object • Provides code reusability • Used to achieve runtime polymorphism • Code enhancement- built on what you have, without altering the present funct ionality.
  • 9. 7. What are the main data types available in java? State all the primitive data types Primitive data types and reference/object data types There are eight primitive data types in java • short • byte • int • long • double • float • char • boolean
  • 10. 8. What is static keyword mean in java? Static says that it always operates within the class (belongs to the class) not in specific objects.
  • 11. 9.What do you mean by operator precedence in java? Java has well-defined rules for specifying the order in which the operators in an expression are evaluated when the expression has several operators. For example, multiplication and division have a higher precedence than addition and subtraction.
  • 12. 10. Can we override and overload main method of a java application We can overload main method by changing the no of arguments or the type of the arguments but we cannot override main method.
  • 13. 11. State three features of a constructor in java • Constructor name must be as same as the class name • Must not have an explicit return type • Constructor need not to be invoked explicitly • Java compiler provides a default constructor if you haven’t implemented any constructors explicitly
  • 14. 12. What is constructor overloading? A class having more than one constructor having changed each of its parameters changed (no of parameters or type of parameters)
  • 15. 13. How can you call one constructor from an other constructor Using this() keyword e.g:- Employee(int a){ } Employee(int a String b){ this(a); }
  • 16. 14. State two ways to copy objects in java Copy by constructor and using clone() method
  • 17. 15. What are the access modifiers in java? • private • Default • protected • public
  • 18. 16. What happens when fields of a class are marked as protected? Those fields can only be accessed from its subclasses
  • 19. 17. What is method overloading and how can it be implemented? If a class have multiple methods by same name but different parameters it is known as method overloading Can implement his by changing the types of the parameters or the number of the parameters
  • 20. 18. Can method overloading be implemented by changing the return type of a method? If n ot why? No. It gives a compile time error because there will be an ambiguity when calling the methods
  • 21. 19. State three places where the ‘super’ key word is used in java • Super is used to refer the immediate parent class instance variable e.g:- super.length • Super() is used to invoke the immediate parent class constructor • Super is used to invoke immediate parent class method e.g:- super.calculate()
  • 22. 20. What is runtime polymorphism? Since in method overriding both the super class and the subclass methods have the same method, compiler doesn’t figure out which method to be invoked during compile time. In this case JVM decides which method to call during runtime. This is called as runtime polymorphism
  • 23. 21. What is method overriding in java? If subclass provides the specific implementation of a method that has been provi ded in the parent class, it is known as method overriding.
  • 24. 22. Define rules of method overriding? • Method must have the same name of the super class method • Method must have the same parameter as in the parent class • There must be an IS-A relationship
  • 25. 23. Can we override methods by changing the return type? Yes. We can override methods by changing their return type only if their return type is a sub type.
  • 26. 24. Can we override static methods in java? No. Static methods cannot be overridden thus the main method if a java program also cannot be overridden
  • 27. 25. State two differences between HashMap and HashTable • HashMap permits one null key and any number of null values in it whereas HashTable doesn’t allow null values • HashTable is Synchronized (two thread cannot access the HashTable at the same time) whereas HashMap is not synchronized • HashMap is not thread safe but HashTable is thread safe • HashMap are much faster than HashTable
  • 28. 26. What is an Exception and what is Exception handling Exception is an unexpected behavior of a program which could possibly quit the program during runtime unexpectedly. By handling the exceptions we allow the applications to run its normal flow.
  • 29. 27. State two Checked Exceptions • IOException • SQLEXception
  • 30. 28. State two unchecked exceptions (runtime exceptions) • ArithmeticException • NumberformatException • NullPointerException • ArrayindexOutOfBoundsException