SlideShare a Scribd company logo
Java/J2EE Programming Training
Review Sessions
Page 2Classification: Restricted
Agenda
• How to prepare for a typical Java interview?
• Typical interview questions…
Interview Tips
Classification: Restricted Page 2
• How to prepare for a typical Java interview?
• Typical interview questions…
Give few reasons for using Java / Advantages of Java
over other programming languages
Classification: Restricted Page 3
• Built-in support for multi-threading, socket communication, and memory
management (automatic garbage collection).
• Object Oriented (OO).
• Better portability than other languages across operating systems
• Supports Web based applications (Applet, Servlet, and JSP), distributed
applications (sockets, RMI, EJB etc.) and network protocols (HTTP, JRMP
etc) with the help of extensive standardized APIs (Application Programming
Interfaces).
Classification: Restricted Page 4
Which package is imported implicitly by all Java programs?
The java.lang package is imported implicitly.
What are static blocks or static initializers?
Classification: Restricted Page 5
• When a class is loaded, all blocks that are declared static and don’t have
function name (i.e. static initializers) are executed even before the
constructors are executed. As the name suggests they are typically used to
initialize static fields.
Classification: Restricted Page 6
Difference between constructors and other regular methods?
• Constructors must have the same name as the class name and cannot
return a value.
• The constructors are called only once per creation of an object while regular
methods can be called many times
Can you call one constructor from another?
Classification: Restricted Page 7
Yes, by using this()
public Pet(int id) {
this.id = id; // “this” means this object
}
public Pet (int id, String type) {
this(id); // calls constructor public Pet(int id)
this.type = type; // ”this” means this object
}
How to call superclass constructor?
Classification: Restricted Page 8
By using super keyword
public SpecialPet(int id) {
super(id); //must be the very first statement in the constructor.
}
You can also use super.myMethod() to call the superclass’s myMethod. This
can be called at any line.
What happens if you do not provide a constructor?
Classification: Restricted Page 9
Java runtime provides a default constructor
Advantages of OOP?
Classification: Restricted Page 10
• Encapsulation
• Polymorphism
• Inheritance
• Abstraction
Classification: Restricted Page 11
Difference between inheritance and
composition/aggregation?
• The ‘is a’ relationship is expressed with inheritance and ‘has a’
relationship is expressed with composition. Both inheritance and
composition allow you to place sub-objects inside your new class. Two of
the main techniques for code reuse are class inheritance and object
composition
• Example: ScienceStudent is a Student; Student has an Address.
Difference between abstract class and interface?
Classification: Restricted Page 12
Refer previous session slides
• Abstract classes have executable methods and abstract methods. Interfaces
have no implementation code. All methods are abstract.
• One class can only subclass one abstract class. A class can implement any
number of interfaces
Why multiple inheritance is not allowed?
• Diamond problem
Classification: Restricted Page 13
Difference between Method Overloading vs Overriding?
Classification: Restricted Page 14
• Please refer lecture slides
Difference between Comparable and Comparator interface?
Classification: Restricted Page 15
• Please refer lecture slides
Difference between == and equals()?
Classification: Restricted Page 16
??
Explain the non-final methods toString(), hashCode()
and equals() of Object class
Classification: Restricted Page 17
• Refer lecture
Difference between String and StringBuffer/StringBuilder
Classification: Restricted Page 18
• Please refer lecture
Explain the different access modifiers..
Classification: Restricted Page 19
• Public
• Private
• Default
• Protected
Code output?
Classification: Restricted Page 20
Code output?
c. Autoboxing will convert a short to a Short, but not to an Integer.
Classification: Restricted Page 21
Code output?
Classification: Restricted Page 22
Code output?
a. "j" will be converted to an Integer automatically when it is
passed to compareTo().
Classification: Restricted Page 23
Code output?
Classification: Restricted Page 24
Code output?
d. "i" will not be converted to an Integer automatically
because there is no assignment nor casting there.
Classification: Restricted Page 25
What is the output?
Classification: Restricted Page 26
What is the output?
It will print “a”. The g() in Bar is not overriding the g() in Foo. It is
just overloading the name "g". When determining which method to
call, autoboxing is not considered first so only the g() in Foo is
applicable and thus is used.
Classification: Restricted Page 27
True or False
Classification: Restricted Page 28
“X extends Y” is correct if and only if X is a class and Y is an interface.
True or False
Classification: Restricted Page 29
“X extends Y” is correct if and only if X is a class and Y is an interface.
False
Question
Classification: Restricted Page 30
Question
B and D
Classification: Restricted Page 31
What is the output?
Classification: Restricted Page 32
What is the output?
Compilation error on lines that print f.a and f.b
Classification: Restricted Page 33
Which of these is not correct?
Classification: Restricted Page 34
Which of these is not correct?
All are correct
Classification: Restricted Page 35
What is the output?
Classification: Restricted Page 36
What is the output?
Compilation error… cannot invoke countGold from
static context
Classification: Restricted Page 37
What is the difference between a List and a Set?
Classification: Restricted Page 38
Set:
HashSet: Default Set …must implement equals and hashCode
LinkedHashSet: Maintains the elements in the order in which they were
entered
TreeSet: Maintains in ascending order/sorted
TreeSet<Student> ts = new TreeSet<Student>();
Comparable: Default comparison logic…. Student implements Comparable…
override compareTo()
Comparator: Multiple Comparator classes by implementing Comparator
and overriding compare()
What is the difference between a List and a Set?
Classification: Restricted Page 39
• List, by default characteristic maintains order; a set does not.
• A set does not entertain duplicate members; whereas a List does
Thank You

More Related Content

What's hot (20)

PDF
Object Oriented Concepts in Real Projects
EPAM
 
PDF
Java basic data types
3trg
 
PPTX
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Simplilearn
 
PPTX
Java Data Types and Variables
sasi saseenthiran
 
PPT
Data types
myrajendra
 
PDF
Data types in Java
Play Store
 
PDF
Value Types
Michael Barker
 
PDF
OntoLex-TEI: Inspiration from Global WordNet
PretaLLOD
 
PDF
Unit 2
Amar Jukuntla
 
PPTX
Unusual C# - OOP
Medhat Dawoud
 
PPT
Primitive data types in java
Umamaheshwariv1
 
PPTX
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 
PPTX
Why Java is not a purely object oriented language?
NexSoftsys
 
PDF
332 ch07
YaQ10
 
PDF
Handout for Dublin Core Metadata Initiative Abstract Model
Jenn Riley
 
PPTX
Session 11 - OOP's with Java - Packaging and Access Modifiers
PawanMM
 
PDF
Java data types, variables and jvm
Madishetty Prathibha
 
PPTX
Classes And Objects
rahulsahay19
 
PDF
Ballerina philosophy
Ballerina
 
PPTX
Data types IN JAVA
garishma bhatia
 
Object Oriented Concepts in Real Projects
EPAM
 
Java basic data types
3trg
 
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Simplilearn
 
Java Data Types and Variables
sasi saseenthiran
 
Data types
myrajendra
 
Data types in Java
Play Store
 
Value Types
Michael Barker
 
OntoLex-TEI: Inspiration from Global WordNet
PretaLLOD
 
Unusual C# - OOP
Medhat Dawoud
 
Primitive data types in java
Umamaheshwariv1
 
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
Simplilearn
 
Why Java is not a purely object oriented language?
NexSoftsys
 
332 ch07
YaQ10
 
Handout for Dublin Core Metadata Initiative Abstract Model
Jenn Riley
 
Session 11 - OOP's with Java - Packaging and Access Modifiers
PawanMM
 
Java data types, variables and jvm
Madishetty Prathibha
 
Classes And Objects
rahulsahay19
 
Ballerina philosophy
Ballerina
 
Data types IN JAVA
garishma bhatia
 

Similar to Review Session and Attending Java Interviews (20)

PPSX
Review Session and Attending Java Interviews
Hitesh-Java
 
PPTX
Object Oriented Programming
RatnaJava
 
PPTX
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
PPSX
Object Class
Hitesh-Java
 
PPTX
Proposals for new function in Java SE 9 and beyond
Barry Feigenbaum
 
PPTX
Java OOPs
DeeptiJava
 
PPTX
Session 14 - Object Class
PawanMM
 
PPTX
Objects and classes in OO Programming concepts
researchveltech
 
DOC
11review(inheritance andpolymorphism)
IIUM
 
PPT
InheritanceAndPolymorphismprein Java.ppt
gayatridwahane
 
PPT
06 InheritanceAndPolymorphism.ppt
ParikhitGhosh1
 
PPT
inner-classes-abstract-classevgdddfs.ppt
aspirantu846
 
PPTX
OOP with Java - Part 3
RatnaJava
 
PPT
Core Java- An advanced review of features
vidyamittal
 
PPTX
Java J2EE Interview Questions Part-1
javatrainingonline
 
PPTX
Java J2EE Interview Questions Part-1
Mindsmapped Consulting
 
ODP
Java for newcomers
Amith jayasekara
 
PPTX
Object Class
RatnaJava
 
DOC
Java interview questions
G C Reddy Technologies
 
PPTX
L03 Software Design
Ólafur Andri Ragnarsson
 
Review Session and Attending Java Interviews
Hitesh-Java
 
Object Oriented Programming
RatnaJava
 
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
Object Class
Hitesh-Java
 
Proposals for new function in Java SE 9 and beyond
Barry Feigenbaum
 
Java OOPs
DeeptiJava
 
Session 14 - Object Class
PawanMM
 
Objects and classes in OO Programming concepts
researchveltech
 
11review(inheritance andpolymorphism)
IIUM
 
InheritanceAndPolymorphismprein Java.ppt
gayatridwahane
 
06 InheritanceAndPolymorphism.ppt
ParikhitGhosh1
 
inner-classes-abstract-classevgdddfs.ppt
aspirantu846
 
OOP with Java - Part 3
RatnaJava
 
Core Java- An advanced review of features
vidyamittal
 
Java J2EE Interview Questions Part-1
javatrainingonline
 
Java J2EE Interview Questions Part-1
Mindsmapped Consulting
 
Java for newcomers
Amith jayasekara
 
Object Class
RatnaJava
 
Java interview questions
G C Reddy Technologies
 
L03 Software Design
Ólafur Andri Ragnarsson
 
Ad

More from RatnaJava (11)

PPTX
Collections - Lists & sets
RatnaJava
 
PPTX
Collections - Sorting, Comparing Basics
RatnaJava
 
PPTX
Collections Array list
RatnaJava
 
PPTX
Exception Handling
RatnaJava
 
PPTX
OOPs with Java - Packaging and Access Modifiers
RatnaJava
 
PPTX
OOP with Java - Abstract Classes and Interfaces
RatnaJava
 
PPTX
OOP with Java - continued
RatnaJava
 
PPTX
Data Handling and Function
RatnaJava
 
PPTX
Introduction to Java Part-3
RatnaJava
 
PPTX
Introduction to Java Part-2
RatnaJava
 
PPTX
Introduction to Java
RatnaJava
 
Collections - Lists & sets
RatnaJava
 
Collections - Sorting, Comparing Basics
RatnaJava
 
Collections Array list
RatnaJava
 
Exception Handling
RatnaJava
 
OOPs with Java - Packaging and Access Modifiers
RatnaJava
 
OOP with Java - Abstract Classes and Interfaces
RatnaJava
 
OOP with Java - continued
RatnaJava
 
Data Handling and Function
RatnaJava
 
Introduction to Java Part-3
RatnaJava
 
Introduction to Java Part-2
RatnaJava
 
Introduction to Java
RatnaJava
 
Ad

Recently uploaded (20)

PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 

Review Session and Attending Java Interviews

  • 2. Page 2Classification: Restricted Agenda • How to prepare for a typical Java interview? • Typical interview questions…
  • 3. Interview Tips Classification: Restricted Page 2 • How to prepare for a typical Java interview? • Typical interview questions…
  • 4. Give few reasons for using Java / Advantages of Java over other programming languages Classification: Restricted Page 3 • Built-in support for multi-threading, socket communication, and memory management (automatic garbage collection). • Object Oriented (OO). • Better portability than other languages across operating systems • Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI, EJB etc.) and network protocols (HTTP, JRMP etc) with the help of extensive standardized APIs (Application Programming Interfaces).
  • 5. Classification: Restricted Page 4 Which package is imported implicitly by all Java programs? The java.lang package is imported implicitly.
  • 6. What are static blocks or static initializers? Classification: Restricted Page 5 • When a class is loaded, all blocks that are declared static and don’t have function name (i.e. static initializers) are executed even before the constructors are executed. As the name suggests they are typically used to initialize static fields.
  • 7. Classification: Restricted Page 6 Difference between constructors and other regular methods? • Constructors must have the same name as the class name and cannot return a value. • The constructors are called only once per creation of an object while regular methods can be called many times
  • 8. Can you call one constructor from another? Classification: Restricted Page 7 Yes, by using this() public Pet(int id) { this.id = id; // “this” means this object } public Pet (int id, String type) { this(id); // calls constructor public Pet(int id) this.type = type; // ”this” means this object }
  • 9. How to call superclass constructor? Classification: Restricted Page 8 By using super keyword public SpecialPet(int id) { super(id); //must be the very first statement in the constructor. } You can also use super.myMethod() to call the superclass’s myMethod. This can be called at any line.
  • 10. What happens if you do not provide a constructor? Classification: Restricted Page 9 Java runtime provides a default constructor
  • 11. Advantages of OOP? Classification: Restricted Page 10 • Encapsulation • Polymorphism • Inheritance • Abstraction
  • 12. Classification: Restricted Page 11 Difference between inheritance and composition/aggregation? • The ‘is a’ relationship is expressed with inheritance and ‘has a’ relationship is expressed with composition. Both inheritance and composition allow you to place sub-objects inside your new class. Two of the main techniques for code reuse are class inheritance and object composition • Example: ScienceStudent is a Student; Student has an Address.
  • 13. Difference between abstract class and interface? Classification: Restricted Page 12 Refer previous session slides • Abstract classes have executable methods and abstract methods. Interfaces have no implementation code. All methods are abstract. • One class can only subclass one abstract class. A class can implement any number of interfaces
  • 14. Why multiple inheritance is not allowed? • Diamond problem Classification: Restricted Page 13
  • 15. Difference between Method Overloading vs Overriding? Classification: Restricted Page 14 • Please refer lecture slides
  • 16. Difference between Comparable and Comparator interface? Classification: Restricted Page 15 • Please refer lecture slides
  • 17. Difference between == and equals()? Classification: Restricted Page 16 ??
  • 18. Explain the non-final methods toString(), hashCode() and equals() of Object class Classification: Restricted Page 17 • Refer lecture
  • 19. Difference between String and StringBuffer/StringBuilder Classification: Restricted Page 18 • Please refer lecture
  • 20. Explain the different access modifiers.. Classification: Restricted Page 19 • Public • Private • Default • Protected
  • 22. Code output? c. Autoboxing will convert a short to a Short, but not to an Integer. Classification: Restricted Page 21
  • 24. Code output? a. "j" will be converted to an Integer automatically when it is passed to compareTo(). Classification: Restricted Page 23
  • 26. Code output? d. "i" will not be converted to an Integer automatically because there is no assignment nor casting there. Classification: Restricted Page 25
  • 27. What is the output? Classification: Restricted Page 26
  • 28. What is the output? It will print “a”. The g() in Bar is not overriding the g() in Foo. It is just overloading the name "g". When determining which method to call, autoboxing is not considered first so only the g() in Foo is applicable and thus is used. Classification: Restricted Page 27
  • 29. True or False Classification: Restricted Page 28 “X extends Y” is correct if and only if X is a class and Y is an interface.
  • 30. True or False Classification: Restricted Page 29 “X extends Y” is correct if and only if X is a class and Y is an interface. False
  • 32. Question B and D Classification: Restricted Page 31
  • 33. What is the output? Classification: Restricted Page 32
  • 34. What is the output? Compilation error on lines that print f.a and f.b Classification: Restricted Page 33
  • 35. Which of these is not correct? Classification: Restricted Page 34
  • 36. Which of these is not correct? All are correct Classification: Restricted Page 35
  • 37. What is the output? Classification: Restricted Page 36
  • 38. What is the output? Compilation error… cannot invoke countGold from static context Classification: Restricted Page 37
  • 39. What is the difference between a List and a Set? Classification: Restricted Page 38 Set: HashSet: Default Set …must implement equals and hashCode LinkedHashSet: Maintains the elements in the order in which they were entered TreeSet: Maintains in ascending order/sorted TreeSet<Student> ts = new TreeSet<Student>(); Comparable: Default comparison logic…. Student implements Comparable… override compareTo() Comparator: Multiple Comparator classes by implementing Comparator and overriding compare()
  • 40. What is the difference between a List and a Set? Classification: Restricted Page 39 • List, by default characteristic maintains order; a set does not. • A set does not entertain duplicate members; whereas a List does