You are on page 1of 5

Multithreading in Java is a process of executing multiple threads simultaneously.

A thread is a lightweight sub-process,


the smallest unit of processing. Multiprocessing and multithreading, both are used to achieve multitasking. However,
we use multithreading than multiprocessing because threads use a shared memory area. They don't allocate separate
memory area so saves memory, and context-switching between the threads takes less time than process. Java
Multithreading is mostly used in games, animation, etc.
Advantages of Java Multithreading 1) It doesn't block the user because threads are independent and you can perform
multiple operations at the same time. 2) You can perform many operations together, so it saves time. 3) Threads
are independent, so it doesn't affect other threads if an exception occurs in a single thread.
What is Thread in java A thread is a lightweight subprocess, the smallest unit of processing. It is a separate path of
execution. Threads are independent. If there occurs exception in one thread, it doesn't affect other threads. It uses a
shared memory area.

Synchronization in Java is the capability to control the access of multiple threads to any shared resource. Java
Synchronization is better option where we want to allow only one thread to access the shared resource. types of
synchronization 1.Process Synchronization 2. Thread Synchronization
Java Synchronized Method If you declare any method as synchronized, it is known as synchronized method.
Synchronized method is used to lock an object for any shared resource. When a thread invokes a synchronized method,
it automatically acquires the lock for that object and releases it when the thread completes its task.

String StringBuffer

The String class is immutable. The StringBuffer class is mutable.

String is slow and consumes more memory when we concatenate StringBuffer is fast and consumes less
too many strings because every time it creates new instance. memory when we concatenate t strings.

String class overrides the equals() method of Object class. So you StringBuffer class doesn't override the
can compare the contents of two strings by equals() method. equals() method of Object class.

String class is slower while performing concatenation operation. StringBuffer class is faster while performing
concatenation operation.

String class uses String constant pool. StringBuffer uses Heap memory

The java.util.StringTokenizer class allows you to break a String into tokens. It is simple way to break a String. It is a
legacy class of Java. It doesn't provide the facility to differentiate numbers, quoted strings, identifiers etc. like
StreamTokenizer class. We will discuss about the StreamTokenizer class in I/O chapter. In the StringTokenizer class,
the delimiters can be provided at the time of creation or one by one to the tokens.

Applet is a special type of program that is embedded in the webpage to generate the dynamic content. It runs inside the
browser and works at client side. Advantage of Applet 1. It works at client side so less response time. 2.Secured 3.It
can be executed by browsers running under many plateforms, including Linux, Windows, Mac Os etc. Drawback of
Applet: Plugin is required at client browser to execute applet.
Life Cycle of an Applet Four methods in the Applet class gives you the framework on which you build any serious
applet – 1. init − This method is intended for whatever initialization is needed for your applet. It is called after the
param tags inside the applet tag have been processed. 2. start − This method is automatically called after the browser
calls the init method. It is also called whenever the user returns to the page containing the applet after having gone off
to other pages. 3. stop − This method is automatically called when the user moves off the page on which the applet
sits. It can, therefore, be called repeatedly in the same applet. 4. destroy − This method is only called when the
browser shuts down normally. Because applets are meant to live on an HTML page, you should not normally leave
resources behind after a user leaves the page that contains the applet. 5. paint − Invoked immediately after the start()
method, and also any time the applet needs to repaint itself in the browser. The paint() method is actually inherited
from the java.awt.
Steps involved in event handling 1. The User clicks the button and the event is generated. 2. Now the object of
concerned event class is created automatically and information about the source and the event get populated with in
same object. 3. Event object is forwarded to the method of registered listener class. 4. the method is now get executed
and returns. Components in Event Handling: Events 1)The events are defined as an object that describes a change in
the state of a source object. 2)The Java defines a number of such Event Classes inside java.awt.event package 3) Some
of the events are ActionEvent, MouseEvent, KeyEvent, FocusEvent, ItemEvent and etc.
Event Sources 1)A source is an object that generates an event. 2)An event generation occurs when an internal state of
that object changes in some way. 3)Some of the event sources are Button, CheckBox, List, Choice, Window and etc.
Event Listeners 1)A listener is an object that is notified when an event occurs. 2)a set of interfaces for receiving and
processing the events under the java.awt.event package. 3)Some of the listeners
are ActionListener, MouseListener, ItemListener, KeyListener, WindowListener and etc.

Basis AWT Swing

Java AWT is an Application programming Swing comes from the set of Java Foundation
Meaning interface for developing GUI applications Classes and is used for creating various
using Java. applications.

The Java AWT components are usually The Java Swing components are usually light
Weight
heavy weighted. weighted.

Java AWT has lesser functionalities in Java Swing has wider functionality in
Functionality
comparison to Swing. comparison to AWT.

Execution The execution time of AWT is quite higher The execution time of Swing is quite lower
Time than Swing. than that of AWT.

Platform The components of Java AWT are typically The components of Java Swing are typically
Support platform-dependent. platform-independent.

MVC pattern AWT doesn’t support the MVC pattern. Swing supports the MVC pattern.

AWT components are comparatively less Swing components are comparatively more
Power
powerful. powerful.

The Layout managers enable us to control the way in which visual components are arranged in the GUI forms by
determining the size and position of components within the containers. FlowLayout: It arranges the components in a
container like the words on a page. It fills the top line from left to right and top to bottom. The components are
arranged in the order as they are added i.e. first components appears at top left, if the container is not wide enough to
display all the components, it is wrapped around the line. Vertical and horizontal gap between components can be
controlled. The components can be left, center or right aligned. GridLayout: It arranges all the components in a grid
of equally sized cells, adding them from the left to right and top to bottom. Only one component can be placed in a
cell and each region of the grid will have the same size. When the container is resized, all cells are automatically
resized. The order of placing the components in a cell is determined as they were added.

RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one system (JVM) to
access/invoke an object running on another JVM. RMI is used to build distributed applications; it provides remote
communication between Java programs. It is provided in the package java.rmi. Architecture of an RMI Application
In an RMI application, we write two programs, a server program (resides on the server) and a client program (resides
on the client). • Inside the server program, a remote object is created and reference of that object is made available for
the client (using the registry). • The client program requests the remote objects on the server and tries to invoke its
methods.
A JavaBean is a specially constructed Java class written in the Java and coded according to the JavaBeans API
specifications. Following are the unique characteristics that distinguish a JavaBean from other Java classes −
• It provides a default, no-argument constructor.
• It should be serializable and that which can implement the Serializable interface.
• It may have a number of properties which can be read or written.
• It may have a number of "getter" and "setter" methods for the properties.
Procedural Oriented Programming: 1)In PP the program is divided into small parts called functions. 2)PP follows a
top-down approach. 3)There is no access specifier in PP. 4) Adding new data and functions is not easy. 5)It does not
have any proper way of hiding data so it is less secure. 6)In PP overloading is not possible. 7)In PP there is no concept
of data hiding and inheritance. EX: C, FORTRAN, Pascal, Basic, etc. Object-Oriented Programming: 1)In OOP the
programs is divided into small parts called objects. 2)OOP follows a bottom-up approach. 3)It has access specifiers like
private, public, protected, etc. 4)Adding new data and function is easy. 5) It provides data hiding so it is more secure
6)overloading is possible 7)In OOP the concept of data hiding and inheritance is used. EX: C++, Java, Python, C#, etc.
Abstraction: 1)AB is a feature of OOPs that hides the unnecessary detail but shows the essential information. 2)It
solves an issue at the design level. 3)It focuses on the external lookout. 4)It can be implemented using abstract classes
and interfaces. 5)It is the process of gaining information. 6)In AB, we use abstract classes and interfaces to hide the
code complexities. Encapsulation: 1)EN is also a feature of OOPs. It hides the code and data into a single entity or unit
so that the data can be protected from the outside world. 2)EN solves on issue at implementation level. 3)It focuses on
internal working. 4)It can be implemented by using the access modifiers (private, public, protected). 5)It is the process
of containing the information. 6)We use the getters and setters methods to hide the data.
Method Overloading: 1)MO is used to increase the readability of the program. 2)MO is performed within class. 3)In
case of MO, parameter must be different. 4)MO is the example of compile time polymorphism. 5) class overloading Ex
{, static int add (int a, int b), {return a+b;}, static int add (inta, intb, intc), {return a+b+c;}, } Method Overriding: 1)
MO is used to provide the specific implementation of the method that is already provided by its super class. 2)MO
occurs in two classes that have IS-A (inheritance) relationship. 3) In case of MO parameter must be same. 4)MO is the
example of run time polymorphism. 5) class Animal{, void eat(), {system.out.println(“eating…”);}, }, class Dog
extends Animal {, void eat(), {system.out.println(“eating bread…”);}, }
Constructor Overloading: 1)Writing more than 1 constructor in a class with a unique set of arguments is called as
CO. 2)All constructors will have the name of the class. 3)OC will be executed at the time of instantiating an object 4)An
OC cannot be static as a constructor relates to the creation of a object. 5)An OC cannot be final as constructor is not
derived by sub classes it won’t make sense.
Public Access Modifier: 1)This modifier is applicable for both top-level classes and interfaces. 2)Public members can
be accessed from the child class of the same package. 3)Public member can be accessed from non-child classes of the
same package. 4)Public members can be accessed from the child class of outside package. 5)Public members can be
accessed from non-child class of outside package. Private Access Modifier: 1)This modifier is not applicable for both
top-level classes and interfaces. 2)Private members cannot be accessed from the child class of the same package.
3)Private members cannot be accessed from non-child classes of the same package. 4)Private members cannot be
accessed from the child class of outside package. 5)Private members cannot be accessed from non-child class of outside
package. Protected access modifier: 1)This modifier is not applicable for both top-level classes and interfaces.
2)Protected members can be accessed from the child class of the same package. 3)Protected member can be accessed
from non-child classes of the same package. 4)Protected members can be accessed from the child class of the outside
package, but we should use child reference only. 5)Protected members cannot be accessed from the non-child class of
outside package.

CLASSPATH: CLASSPATH is an environment variable which is used by Application ClassLoader to locate and load
the .class files. The CLASSPATH defines the path, to find third-party and user-defined classes that are not extensions
or part of Java platform. Include all the directories which contain .class files and JAR files when setting the
CLASSPATH. You need to set the CLASSPATH if: • You need to load a class that is not present in the current directory
or any sub-directories.• You need to load a class that is not in a location specified by the extensions mechanism.

An interface in Java is a blueprint of a class. It has static constants and abstract methods.
The interface in Java is a mechanism to achieve abstraction
There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and
multiple inheritance in Java
In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body.
Java Interface also represents the IS-A relationship.

Dictionary Meaning: Exception is an abnormal condition. In Java, an exception is an event that disrupts the normal
flow of the program. It is an object which is thrown at runtime. 1) Checked Exception: The classes that directly inherit
the Throwable class except RuntimeException and Error are known as checked exceptions. For example, IOException,
SQLException, etc. Checked exceptions are checked at compile-time. 2) Unchecked Exception :The classes that inherit
the RuntimeException are known as unchecked exceptions. For example, ArithmeticException, NullPointerException,
ArrayIndexOutOfBoundsException, etc. Unchecked exceptions are not checked at compile-time, but they are checked
at runtime.

There can be a lot of usage of Java this keyword. In Java, this is a reference variable that refers to the current object.
Here is given the 6 usage of java this keyword. 1)this can be used to refer current class instance variable.
2)this can be used to invoke current class method (implicitly)
3)this() can be used to invoke current class constructor.
4)this can be passed as an argument in the method call.
5)this can be passed as argument in the constructor call.
6)this can be used to return the current class instance from the method.

Comparison Cookie Session

Cookies are client-side files that are stored on Sessions are server-side files that store user
Definition
a local computer and contain user information. information.

Cookies expire after the user specified The session ends when the user closes the
Expiry
lifetime. browser or logs out of the program.

It can only store a limited amount of data. It is able to store an unlimited amount of
Data storage
information.

Cookies are used to store information in a text The data is saved in an encrypted format during
Data Format
file. sessions.

Cookies are stored on a limited amount of A session can store an unlimited amount of
Storage
data. data.

Sr. Key final finally finalize


no.

1. Definition final is the keyword and finally is the block in Java finalize is the method in Java
access modifier which is Exception Handling to which is used to perform
used to apply restrictions execute the important code clean up processing just
on a class, method or whether the exception before object is garbage
variable. occurs or not. collected.

2. Applicable Final keyword is used with Finally block is always finalize() method is used
to the classes, methods and related to the try and catch with the objects.
variables. block in exception handling.

3. Functionality (1) Once declared, final (1) finally block runs the finalize method performs the
variable becomes constant important code even if cleaning activities with
and cannot be modified. exception occurs or not. respect to the object before
(2) final method cannot be (2) finally block cleans up its destruction.
overridden by sub class. all the resources used in try
(3) final class cannot be block
inherited.

4. Execution Final method is executed Finally block is executed as finalize method is executed
only when we call it. soon as the try-catch block just before the object is
is executed. destroyed.
It's execution is not
dependant on the exception.

You might also like