0% found this document useful (0 votes)
2 views

Module3 Definition

The document provides an overview of exceptions in Java, including their types (checked and unchecked), and the purpose of try-catch blocks for handling exceptions. It also explains key concepts such as the String and Object classes, garbage collection, immutability, collections, wrapper classes, maps, threads, synchronization, and thread properties. Additionally, it discusses thread life cycle, race conditions, and deadlocks.

Uploaded by

garrgoh7
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module3 Definition

The document provides an overview of exceptions in Java, including their types (checked and unchecked), and the purpose of try-catch blocks for handling exceptions. It also explains key concepts such as the String and Object classes, garbage collection, immutability, collections, wrapper classes, maps, threads, synchronization, and thread properties. Additionally, it discusses thread life cycle, race conditions, and deadlocks.

Uploaded by

garrgoh7
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Module3Definition

--------------------------------------------------------------------------------------------------------
What is an Exception?
An exception is a unexpected or unwanted triggered by the JVM during the
execution of the program which forces the jvm to abnormally terminate the
program.
types of exception
-------------------
checked exception (InterruptedException,IoException,SQLException..)
unchecked exception (RuntimeException)

What is the purpose of try and catch block?


in try block we write those lines of code which might throw an exception
in catch block we will write the code to handle the exception

What is the use of throw keyword?


It is a keyword using which the user can explicitly create and throw exception
objects.

What is the use of throws keyword?


it is a keyword which is used to propagate the checked exception object
back to the caller if the exception is not handled by the user.

What is String class?


It is final class which is present inside java.lang package
It is a immutable class
String class object can be created both using new keyword and without using
new keyword.

What is Object class?


It is the super most class in entire java, every class in java is the subclass of
Object class.
It is present inside java.lang package
Some of the inbuilt methods of Object class are hashCode() , toString() and
equals(Object obj)

Explain the role of garbage collector?


The garbage collector is a sub system of the JVM.
It is responsible for memory management operations inside the heap area.
It identifies and removes the unnecessary objects from the heap memory.
Before destroying an object and removing it from heap area it will internally
call finalize() method.
It is an implicit process and works in the background however programmer can
explicitly call garbage collector by writing "System.gc()" in the code.

What is immutability?
Whenever we create a String class object we cannot perform
any changes to the content of the object but if we try to
perform any changes to the content of the object then along with the changes
a new object is created. This behaviour of a String class object is known
as Immutability.

What is a Collection?
A Collection is a Container in which multiple individual objects are stored
as a single entity.

What is Collection Framework Library?


It is a inbuilt library which contains all the classes and interfaces
that are required to overcome the drawback of array.
all the classes and interface of CFL are present in java.util package

What is Wrapper class?


It is an inbuilt class which is used to convert primitive type data to
non-primitive type and non-primitive data to primitive type.

What is a Map?
It is a container in which the elements are stored in key value pair.
The key value pair is technically called as Entry.

What is thread?
A thread is a lightweight process.
Any program under execution is known as process.
A process that consumes less amount of CPU time and memory is known as
lightweight process.
Thread can be created in 2 ways
a. By extending from Thread class.
b. By implementing Runnable interface.

What is Synchronization?
It is the concept of making a method thread safe.
In java we can achieve synchronization by used “synchronized” keyword.
When we declare a method as synchronized then it can be accessed by only
one thread at a time.
Explain the role of start () method?
It is an inbuilt method present in Thread class.
An Actual thread gets created in Java Memory only when we call start ()
method.
It performs the following operations,
a) Registers thread with JVM.
b) Allocate resources needed for execution.
c) Internally calls start () method.

Explain thread life cycle?


Refer Notes.

What is Race Condition?


Multiple threads competing for the same resource is called race condition.

What is DEADLOCK?
Multiple threads on hold waiting for each other to complete execution is called
deadlock.

What are thread properties.


Every thread in java will have following 3 properties,
ID, NAME and PRIORITY.
ID is readonly i.e, we can access but not assign.
NAME and PRIORITY we can access and assign.

You might also like