Ebook QA QE 1 L2 Core Java Extended
Ebook QA QE 1 L2 Core Java Extended
Course(s):
Core Java
▪ Explain the fundamentals of Java language
- Classes and Objects
- Methods and Variables
Joe has to develop a feature where users can add multiple items to
the cart and delete items from the cart. However, a senior developer
will be assisting Joe to complete this task. During pair programming,
Joe was asked to write a program that does the basic operations
similar to a calculator to get started.
When two data types are compatible with each other, the value of one
data type that is assigned to the other is called type casting.
Type Casting
Duration: 20 min.
Problem Statement:
Write a program which will take a string as input and will convert it into other primitive data
types.
Assisted Practice: Guidelines
2. Write a program in Java to take an input from user and convert the input variable into other data types.
The access modifiers specify the accessibility of a data member, class, constructor, or method.
public
protected
No modifier
private
Types of Access Modifiers
Default Public
Private Protected
Duration: 20 min.
Problem Statement:
Write a program to demonstrate how and when access modifiers are used.
Assisted Practice: Guidelines
2. Write a program in Java to create variables with different access modifiers and
Start
If condition
is false
Exit
while Loop
while(condition)
Continually executes a block of statements as long {
conditional code ;
as a given statement is true }
If condition
is true
Has the following syntax:
code block
If condition
while (expression) { is false
statement(s)
}
do…while Loop
code block
Evaluates its expression at the bottom of the loop,
instead of the top If condition
is true
Condition
do {
statement(s)
} while (expression);
If condition
is false
for Loop
Init
Duration: 15 min.
Problem Statement:
Duration: 15 min.
Problem Statement:
Duration: 20 min.
Problem Statement:
A class is a user defined template or prototype that defines objects of the same type. All
objects in the class will exhibit the same properties.
Modifiers
Class Name
Class Declaration
Keywords
Body
Class Initialization
Class initialization consists of a block of code preceded by the “static” keyword. Every time a class is loaded, Java
invokes this code.
class Demo {
static {
// ...initialization code here...
}
}
class Demo {
{
// ...initialization code here...
}
}
JVM Architecture
JVM Memory
JVM Native
Method PC
Heap Language Method
Area Registers
Stacks Stacks
Native Native
Execution
Method Method
Engine
Interface Libraries
Ways to Instantiate a Class
New Keyword
New Instance
Clone() method
Deserialization
newInstance() method of
constructor class
Difference between Class Referencing and Object Creation
▪ For example: A mobile phone has several contacts, each contact representing an actual
person.
▪ Object: Person
Static Blocks:
• Used for static initializations of a class
• Executed when a static member is invoked in a class
• Executed before constructors
Instance Blocks:
• Executed when an object is created in a class
class student
{
static int rollno ;
static String name;
static{ rollno = 28; name = “John";
}
public static void main(String args[]){}
}
What Are Constructors?
Constructors are blocks of code executed while initializing an object. Constructors are used to
assign value to class variables when creating an object.
There are three types of constructors such as Default, No-Arg, and Parameterized.
Default Constructor:
If user does not implement any constructor, then default constructor is inserted in the
class by Java compiler.
class Demo
Java {
class Demo{}
Compiler Demo(){}
}
Types of Constructors
No-Arg Constructor:
These constructors have no arguments.
class Demo
{
public Demo(){}
public static void main(String arg[]){
new Demo();
}
}
Types of Constructors
Parameterized Constructor:
These constructors have arguments or parameters.
Duration: 20 min.
Problem Statement:
Explain Classes, Objects, and Constructors using an example.
Assisted Practice: Guidelines
▪ A mechanism in which one class acquires all the properties and behaviors of the parent
class
▪ Used for method overriding and code reusability
IS-A Relationship
1 2
Duration: 15 min.
Problem Statement:
Explain types of inheritance using examples.
Assisted Practice: Guidelines
A collection is a group or single unit of individual objects. Java Collection Framework defines
several classes and interfaces to represent objects as a single unit.
Search
Sort
Common operations
using Java collections Insert
Delete
Update
Collection Hierarchy
Interface
Iterable Class
Extends
Implements
Collection
LinkedList Deque
LinkedHashSet
Stack TreeSet
Legacy Classes vs. Collection Framework
Legacy classes comprises classes and Collections are used to store and
interfaces supported by older versions of manipulate group of objects.
Java.
● Contains an ordered list of homogeneous elements, where elements are added and
Queue removed at the rear and front end respectively
● LinkedList, Priority queue, ArrayQueue implement this interface
Collections Methods
size() clear()
add(Object o) isEmpty()
addAll(Collection c) iterator()
remove(Object o) equals(Object o)
removeAll(Collection c) toArray()
contains(Object o) toArray(Object[] a)
containsAll(Collection c) retainAll(Collection c)
What Are Generics?
Generics ensure type safety in Java by making bugs detectable during compile time. Type Erasure
feature in Java Generics erases extra information added to source code.
Types of Generics:
Duration: 30 min.
Problem Statement:
Write a program to demonstrate working of Collections and Generics.
Assisted Practice: Guidelines
Exception Handling is a mechanism to handle run time errors that disrupt the normal flow of
an application.
Several factors can cause an exception during runtime, such as an invalid input data, a
nonexistent file, or an interrupted network connection.
Keywords Used for Exception Handling
try A block that contains a set of statements where an exception may occur
finally block contains a set of statements that will always execute whether or not there is an
exception
Need of Handling Errors and Exception
Errors Exception
ArrayIndexOutOfBoundsException Thrown to notify that an array has been accessed with an illegal index
NumberFormatException Thrown when the conversion from string to numeric format fails
NoSuchFieldException Thrown when the class does not contain the specified field or variable
Basic Try-Catch Block
Duration: 15 min.
Problem Statement:
Demonstrate how a basic try-catch block is used for Exception Handling.
Assisted Practice: Guidelines
Duration: 20 min.
Problem Statement:
Explain throw and throws using an example.
Assisted Practice: Guidelines
Duration: 30 min.
Problem Statement:
Implement try with parameters in a program.
Assisted Practice: Guidelines
Duration: 30 min.
Problem Statement:
Implement multiple catch with exception class hierarchy in a program.
Assisted Practice: Guidelines
Duration: 30 min.
Problem Statement:
Demonstrate the use of finally block in a program.
Assisted Practice: Guidelines