SlideShare une entreprise Scribd logo
1  sur  29
25 Java Interview
Questions
What are the main features of Java?
 Object Oriented
 Simple
 Platform Independent
 Secured
 Robust
 Portable
 Multithreaded
 Distributed
What are the fundamental principles
of object oriented programming?
 Inheritance
 Abstraction
 Polymorphism
 Encapsulation
What do you mean by inheritance in
java?
 Inheritance is one of the Key principle of object oriented programming.
Through inheritance, one class can inherit the properties of another class.
The class from which properties are inherited is called super class and the
class to which properties are inherited is called sub class
What is constructor overloading? What
is the use of constructor overloading?
 A class can Have any number of constructors. These constructors will have
different list of arguments. It is called constructor overloading. Constructor
overloading provides different way to instantiate a class
What is polymorphism in java?
 Polymorphism refers to any entity whether it is a method or a constructor or
an operator which takes many forms or can be used for multiple tasks.
What is the method overloading in
java?
 If a class has more than one method with same name but with different list of
arguments, then it is called method overloading.
What is the method overriding?
 If a super class method is modified in the sub class then it is called method
overriding.
Does java supports multiple
inheritance?
 Java supports multiple inheritance but only through interfaces. That means a
class can implement more than one interfaces but can not extend more than
one class.
What is the difference between
constructor and method?
 Constructor is a special member of a class which is used to create the objects
to the class. It is special because it will have same name as class. It will have
no return type.
 Method is ordinary member of a class which is used to implement some
behavior of a class. It will have it’s own name and return type.
Can we overload the main() method?
 Yes, we can overload a main() method. A class can have any number of main()
methods. But, one of those must be in the form “public static void
main(String[] args)” in order to start the execution.
How the exceptions are handled in java? OR
Explain try, catch and finally blocks in java?
 Java has it’s own mechanism to handle the exceptions. In Java, exceptions
are handled using three blocks – try, catch and finally blocks.
 try block – The code to be monitored for exceptions will be kept in this block.
 catch block – If any exceptions occurred in try block, those exceptions will be
caught by this block.
 finally block – This block will be always executed whether exception is
raised or not and raised exceptions are caught or not.
What are PATH and CLASSPATH?
 PATH and CLASSPATH are two environment variables which need to be set in
order to compile and run the java programs.
What is multithreaded programming?
 Multithreaded programming is one of the key features of java which allows
multiple threads to execute their task simultaneously
What is the difference between error
and exception in java?
What are the differences between
static and non-static methods?
Static method is common to all instances of a class. Static methods are stored in
the class memory. Where as non-static methods are stored in the object memory.
Each instance of a class will have their own copy of non-static methods.
What are the differences between method
overloading and method overriding?
What are the different ways of
creating threads in java?
 There are two ways to create the threads in java
 a) By extending java.lang.Thread class.
 b) By implementing java.lang.Runnable interface.
What is static binding and dynamic binding
in java?
What is garbage collection in java?
Removing unwanted objects or abandoned objects from the memory is called
garbage collection. Garbage collection is done automatically in java. You need
not to remove the unwanted objects explicitly. Garbage collector thread does
this for you. click here to see how garbage collector thread works in java.
What is the difference between ArrayList
and Vector Class?
1) Thread Safety
This is the main difference between ArrayList and Vector class. ArrayList class is
not thread safety where as Vector class is thread safety. Vector class is a
synchronized class. Only one thread can enter into Vector object at any moment
of time during execution. Where as ArrayList class is not synchronized. Multiple
threads can access ArrayList object simultaneously. Below diagram clearly shows
that.
What is the difference between ArrayList
and Vector Class?
 Performance
ArrayList has better performance compared to Vector. It is because, Vector class
is synchronized. It makes the threads to wait for object lock to enter into vector
object. Where as ArrayList class is not synchronized. Threads need not to wait for
object lock to access ArrayList object. This makes ArrayList faster than the
Vector class.
What is cloning in java?
 Cloning is a process of creating an exact copy of an existing object in the
memory. Cloning may be shallow or deep. In java, clone() method is used to
create a clone of an object
What are differences between final, finally
and finalize in java?
 final is a keyword which is used to make a variable or a method or a class as
“unchangeable“. In simple terms,
 A variable which is declared as final, it’s value can not be changed once it is
initialized.
finally Block :
 finally is a block which is used for exception handling along with try and catch
blocks. finally block is always executed whether exception is raised or not and
raised exception is handled or not. Most of time, this block is used to close
the resources like database connection, I/O resources etc.
finalize() Method :
 finalize() method is a protected method of java.lang.Object class. It is
inherited to every class you create in java. This method is called by garbage
collector thread before an object is removed from the memory. finalize()
method is used to perform some clean up operations on an object before it is
removed from the memory.
What are checked and unchecked
exceptions in java?
Checked Exceptions :
 Checked exceptions are the exceptions which are known during compile time. These are the exceptions that are checked at compile time. They are also
called compile time exceptions.
 These exceptions must be handled either using try-catch blocks or using throws clause. If not handled properly, they will give compile time error.
 All sub classes of java.lang.Exception except sub classes of RunTimeException are checked exceptions.
 The following example throws checked exception. But it is not handled, so it gives compile time error.
 public class CheckedException
 {
 public static void main(String[] args)
 {
 Class.forName("AnyClassName");

 //Compile time error because
 //above statement throws ClassNotFoundException which is a checked exception
 //this statement must be enclosed within try-catch block or declare main method with throws clause
 }
 }
Unchecked Exceptions :
 Unchecked exceptions are the exceptions which are known at run time. They
can not be known at compile time because they occur only at run time. That’s
why they are also called Run Time Exceptions.
 All the sub classes of RunTimeException and all sub classes of Error class are
unchecked exceptions.
 If any statement in the program throws unchecked exceptions and you are not
handling them either using try-catch blocks or throws clause, then it does not
give compile time error. Compilation will be successful but program may fail
at run time. Therefore, to avoid premature termination of the program, you
have to handle them properly.

Contenu connexe

Tendances

Java classes and objects interview questions
Java classes and objects interview questionsJava classes and objects interview questions
Java classes and objects interview questions
Dhivyashree Selvarajtnkpm
 
Core java interview questions1
Core java interview questions1Core java interview questions1
Core java interview questions1
Lahari Reddy
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10
Terry Yoast
 

Tendances (20)

The smartpath information systems java
The smartpath information systems javaThe smartpath information systems java
The smartpath information systems java
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
Java interview
Java interviewJava interview
Java interview
 
OCA Java SE 8 Exam Chapter 5 Class Design
OCA Java SE 8 Exam Chapter 5 Class DesignOCA Java SE 8 Exam Chapter 5 Class Design
OCA Java SE 8 Exam Chapter 5 Class Design
 
Questions of java
Questions of javaQuestions of java
Questions of java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
Java classes and objects interview questions
Java classes and objects interview questionsJava classes and objects interview questions
Java classes and objects interview questions
 
Java interface
Java interface Java interface
Java interface
 
OCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 ExceptionsOCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 Exceptions
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
 
Core java interview questions1
Core java interview questions1Core java interview questions1
Core java interview questions1
 
Advanced java interview questions
Advanced java interview questionsAdvanced java interview questions
Advanced java interview questions
 
Java Concurrency Starter Kit
Java Concurrency Starter KitJava Concurrency Starter Kit
Java Concurrency Starter Kit
 
Java Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJava Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRao
 
Chapter 9 java
Chapter 9 javaChapter 9 java
Chapter 9 java
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10
 
Class test 1 sample questions
Class test 1 sample questionsClass test 1 sample questions
Class test 1 sample questions
 
Probable questions for semester exam
Probable questions for semester examProbable questions for semester exam
Probable questions for semester exam
 

Similaire à 25 java interview questions

1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
venud11
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
Gaurav Maheshwari
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
yearninginjava
 

Similaire à 25 java interview questions (20)

1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdf
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Viva file
Viva fileViva file
Viva file
 
Java tips
Java tipsJava tips
Java tips
 
Java interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council PuneJava interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council Pune
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
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
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
 
50+ java interview questions
50+ java interview questions50+ java interview questions
50+ java interview questions
 
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods EncapsulationOCA Java SE 8 Exam Chapter 4 Methods Encapsulation
OCA Java SE 8 Exam Chapter 4 Methods Encapsulation
 
Java mcq
Java mcqJava mcq
Java mcq
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdet
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

25 java interview questions

  • 2. What are the main features of Java?  Object Oriented  Simple  Platform Independent  Secured  Robust  Portable  Multithreaded  Distributed
  • 3. What are the fundamental principles of object oriented programming?  Inheritance  Abstraction  Polymorphism  Encapsulation
  • 4. What do you mean by inheritance in java?  Inheritance is one of the Key principle of object oriented programming. Through inheritance, one class can inherit the properties of another class. The class from which properties are inherited is called super class and the class to which properties are inherited is called sub class
  • 5. What is constructor overloading? What is the use of constructor overloading?  A class can Have any number of constructors. These constructors will have different list of arguments. It is called constructor overloading. Constructor overloading provides different way to instantiate a class
  • 6. What is polymorphism in java?  Polymorphism refers to any entity whether it is a method or a constructor or an operator which takes many forms or can be used for multiple tasks.
  • 7. What is the method overloading in java?  If a class has more than one method with same name but with different list of arguments, then it is called method overloading.
  • 8. What is the method overriding?  If a super class method is modified in the sub class then it is called method overriding.
  • 9. Does java supports multiple inheritance?  Java supports multiple inheritance but only through interfaces. That means a class can implement more than one interfaces but can not extend more than one class.
  • 10. What is the difference between constructor and method?  Constructor is a special member of a class which is used to create the objects to the class. It is special because it will have same name as class. It will have no return type.  Method is ordinary member of a class which is used to implement some behavior of a class. It will have it’s own name and return type.
  • 11. Can we overload the main() method?  Yes, we can overload a main() method. A class can have any number of main() methods. But, one of those must be in the form “public static void main(String[] args)” in order to start the execution.
  • 12. How the exceptions are handled in java? OR Explain try, catch and finally blocks in java?  Java has it’s own mechanism to handle the exceptions. In Java, exceptions are handled using three blocks – try, catch and finally blocks.  try block – The code to be monitored for exceptions will be kept in this block.  catch block – If any exceptions occurred in try block, those exceptions will be caught by this block.  finally block – This block will be always executed whether exception is raised or not and raised exceptions are caught or not.
  • 13. What are PATH and CLASSPATH?  PATH and CLASSPATH are two environment variables which need to be set in order to compile and run the java programs.
  • 14. What is multithreaded programming?  Multithreaded programming is one of the key features of java which allows multiple threads to execute their task simultaneously
  • 15. What is the difference between error and exception in java?
  • 16. What are the differences between static and non-static methods? Static method is common to all instances of a class. Static methods are stored in the class memory. Where as non-static methods are stored in the object memory. Each instance of a class will have their own copy of non-static methods.
  • 17. What are the differences between method overloading and method overriding?
  • 18. What are the different ways of creating threads in java?  There are two ways to create the threads in java  a) By extending java.lang.Thread class.  b) By implementing java.lang.Runnable interface.
  • 19. What is static binding and dynamic binding in java?
  • 20. What is garbage collection in java? Removing unwanted objects or abandoned objects from the memory is called garbage collection. Garbage collection is done automatically in java. You need not to remove the unwanted objects explicitly. Garbage collector thread does this for you. click here to see how garbage collector thread works in java.
  • 21. What is the difference between ArrayList and Vector Class? 1) Thread Safety This is the main difference between ArrayList and Vector class. ArrayList class is not thread safety where as Vector class is thread safety. Vector class is a synchronized class. Only one thread can enter into Vector object at any moment of time during execution. Where as ArrayList class is not synchronized. Multiple threads can access ArrayList object simultaneously. Below diagram clearly shows that.
  • 22. What is the difference between ArrayList and Vector Class?  Performance ArrayList has better performance compared to Vector. It is because, Vector class is synchronized. It makes the threads to wait for object lock to enter into vector object. Where as ArrayList class is not synchronized. Threads need not to wait for object lock to access ArrayList object. This makes ArrayList faster than the Vector class.
  • 23. What is cloning in java?  Cloning is a process of creating an exact copy of an existing object in the memory. Cloning may be shallow or deep. In java, clone() method is used to create a clone of an object
  • 24. What are differences between final, finally and finalize in java?  final is a keyword which is used to make a variable or a method or a class as “unchangeable“. In simple terms,  A variable which is declared as final, it’s value can not be changed once it is initialized.
  • 25. finally Block :  finally is a block which is used for exception handling along with try and catch blocks. finally block is always executed whether exception is raised or not and raised exception is handled or not. Most of time, this block is used to close the resources like database connection, I/O resources etc.
  • 26. finalize() Method :  finalize() method is a protected method of java.lang.Object class. It is inherited to every class you create in java. This method is called by garbage collector thread before an object is removed from the memory. finalize() method is used to perform some clean up operations on an object before it is removed from the memory.
  • 27. What are checked and unchecked exceptions in java?
  • 28. Checked Exceptions :  Checked exceptions are the exceptions which are known during compile time. These are the exceptions that are checked at compile time. They are also called compile time exceptions.  These exceptions must be handled either using try-catch blocks or using throws clause. If not handled properly, they will give compile time error.  All sub classes of java.lang.Exception except sub classes of RunTimeException are checked exceptions.  The following example throws checked exception. But it is not handled, so it gives compile time error.  public class CheckedException  {  public static void main(String[] args)  {  Class.forName("AnyClassName");   //Compile time error because  //above statement throws ClassNotFoundException which is a checked exception  //this statement must be enclosed within try-catch block or declare main method with throws clause  }  }
  • 29. Unchecked Exceptions :  Unchecked exceptions are the exceptions which are known at run time. They can not be known at compile time because they occur only at run time. That’s why they are also called Run Time Exceptions.  All the sub classes of RunTimeException and all sub classes of Error class are unchecked exceptions.  If any statement in the program throws unchecked exceptions and you are not handling them either using try-catch blocks or throws clause, then it does not give compile time error. Compilation will be successful but program may fail at run time. Therefore, to avoid premature termination of the program, you have to handle them properly.