Object Oriented Programming in Java
Object Oriented Programming in Java
Features of Array
1. Arrays are objects.
2. They can eve hold the reference variables of other objects.
3. They are created during runtime.
4. They are dynamic , created on the heap.
5. The length of the Array is fixed.
Array Declaration
The type of the element that the array holds followed by the identifier and square braces which
indicates the identifier is array type.
Array Usage
The array elements can be accessed with the help of the index.
For example, aiFirstArray[0] refers to 1, aiFirstArray[1] refers to 2 and so on.
To get the size of the array we need the dot operator and length.
Example: aiFirstArray.length - returns the size of the array.
Array of References
The above statement creates an array with 3 elements which holds 3 employee references emp[0],
emp[1] and emp[2]. The employee object are not yet created.
Arrays Page 1
Since the parent class reference can also point to child class objects:
An Interface cannot be instantiated, but the reference can be used to point to the objects of the
classes that implements it.
Arrays Page 2
OOPs concepts in Java
четврток, 25 март 2021 21:17
What is an Object?
Object is a bundle of data and its behavior often known as methods.
Objects have two characteristics:
They have states.
They have behaviors.
So if I had to write a class based on the given information, I will have a class House, attributes
Address, Color and Area. And I will have two methods, method Open door, and method Close door.
Example 2:
Let’s take another example.
Object: Car
State: Color, Brand, Weight, Model
Behavior: Break, Accelerate, Slow Down, Gear change.
Now I have to write a class Car, which has the attributes Color, Brand, Weight and Model. And
methods: Break, Accelerate, Slow down, Gear change.
Characteristics of Objects:
1. Abstraction
2. Encapsulation
3. Message passing
Abstraction: is a process where you show only "relevant" data and "hide" unnecessary details of an
object from the user.
Encapsulation: simply means binding object state and behavior together. If I am creating a class then
I am doing encapsulation.
Message passing: A application contains many objects. One object interacts with another object by
What is a Constructor?
The name of the Constructor must be the same name as the class.
Example: If I have a class named Animal, then the Constructors name will be Animal() {};
The Constructor doesn't have a return type.
On the right side of this statement, we are calling the default Constructor of the class MyClass to
create a new object.
A Constructor can be default or parameterized, if the constructor is empty then it is called the
default Constructor, else if the Constructor has parameters, it is called parameterized constructor.
Example:
Abstraction
Abstraction is hiding relevant and unnecessary data or details from the user. For example if you login
in your bank account, you type your name and password and press login, what happens when you
press login and how the servers sends the message is all hidden from you.
Encapsulation
Encapsulation means getting object states and behaviors (attributes, objects, methods) together. For
example if I make a class I am doing encapsulation.
Encapsulation example:
Inheritance
Inheritance means using the properties and functionalities of another class. Every sub class defines
only those properties that are unique for the sub class, the rest of the properties inherits from the
parent or super class.
1. Inheritance is a process of creating a new class that is based on an existing class, simply by
extending its common data members and methods.
2. With inheritance we can reuse code.
3. The class that is extends it is called super class or parent class, and the class that extends the
class it’s called child class or sub class.
One of the biggest advantages of Inheritance is when we reuse the code we don't have to type it
again in the sub class.
The variables (attributes) or methods in the parent class can be used in the child class.
To inherit a class we use the "extends" keyword. For example the class A, extends class B, where
class A is sub class, and class B is super class.
Example: We have a class Teacher that is a super class and a class MathTeacher that extends the
super class.
Single Inheritance: it's when one class extends another class. Child and parent class.
Multilevel Inheritance: It's when a class extends the child class. For example class A extends class B,
and class B extends class C.
Hierarchical Inheritance: it's when the super class is extended by more than one sub class. For
example, class B extends class A, and class C extends class A.
Multiple Inheritance: it's when a child class extends more than one parent class. For example, the
sub class C extends the super class B, and the super class A.
Polymorphism
Polymorphism allows us to perform a single action in different ways.
For example if we have a class Animal that has a method animalSound(), here we cannot give
implementation to this method because we don’t know which class would extend Animal class. So
we make the method AnimalSound() abstract by adding the "abstract" keyword before the methods
name.
Now, suppose we have two Animal sub classes Dog and Lion. We can provide the implementation
detail there.
Abstract method is a method that it's declared but not defined. It means that the abstract method
doesn't has body.
It is declared with the keyword "abstract".
The sub class that inherits must implement all the abstract methods from the super class or to be
declared as an abstract class.
Constructors, static methods, private methods and final methods cannot be abstract.
A abstract class cannot be instanced, that means than you cannot create an object of an abstract
class.
• All methods in the interface are public and abstract. It is optional to use the "abstract"
keyword before each method.
• A class can implement any number of interfaces.
• When a class implements an interface it has to give the definition of all the abstract methods
of interface or to be declared as abstract.
• An interface reference can point to objects of its implementing classes.
Access Specifiers
There are four types of access specifiers in Java:
Public: Accessible to all, inside and out of the class.
Private: Accessible only inside of the class.
Protected: Accessible for the class and the subclass.
Default: (Package Friendly).
Constructor is a block of code that initializes the newly created object. Constructors don't have a
return type.
Constructor has the same name as the class, here is an example of a Constructor:
We have created an object obj of class Hello and then we displayed the instance variable name of
the object. When we created the object, the constructor got invoked. We used this keyword, which
refers to the current object, object obj.
Types of Constructors
There are three types of constructors: Default, No-arg constructor and Parameterized.
Default constructor
If the programmer does not write any constructor in the class, then the Java compiler creates a
default constructor automatically. The default constructor does not has parameters and his name
must be the same as the name of the class.
No-arg constructor
It is a constructor similar to the default constructor, the difference is that the no-arg constructor can
have body, unlike the default constructor where its body it is empty.
The code above will show an error. Because we created an object Example3 myobj = new
Example3(); that invokes the default constructor, which we don't have. We only have one
parameterized constructor. When the user doesn't implement any kind of constructor in the class
the compiler creates one automatically, but when the user creates a constructor, for example
parameterized constructor, then the compiler doesn't create a default constructor.
Constructor Chaining
When a constructor calls another constructor of the same class, then this is called constructor
chaining.
Constructor Overloading
Constructor overloading is when we have more than one constructor with different parameters.
Inheritance is when a class inherits properties and methods from another class. The purpose of
inheritance is to make one code of one class reusable.
Inheritance is a process of defining a new class based on an existing class by extending its properties,
common data, members and methods.
The code that it's in the super class doesn't has to be written in the sub classes.
Child class: is a class that extends the properties of another class, and it's called child class or sub
class.
Parent class: is a class whose properties are used by another class and it's called parent class or
super class.
We have a class XYZ that extends the class ABC. The class XYZ is sub class, and the class ABC is super
class.
Based on the example above we can say that PhysicsTeacher IS-A Teacher. This means that a child
class has IS-A relationship with the parent class. This inheritance is known as IS-A relationship
between child and parent class.
The sub class inherits all the methods and members that are declared public or protected in the
super class. If the members and methods are private, then the sub class cannot access them directly.
We have to use getters and setters so we can access the private members and methods.
Types of Inheritance
Single Inheritance: single inheritance it's when one class extends another class. Or we have
one super class and one sub class.
Multilevel Inheritance: multilevel inheritance is when a class extends a child class. For
example, class C extends class B, and class B extends class A.
Aggregation
For example, consider two classes Student class and Address class. Every student has an address so
the relationship between student and address is a Has-A relationship. But if you consider the other
way around it doesn't make any sense as an Address doesn't need to have a Student necessarily.
We did not write the Address code in any of the classes, we simply created the HAS-A relationship
with the address class to use the Address code.
The keyword "super" refers to the constructor of the parent class or superclass.
In the following program, we have a data member num declared in the child class. The member with
the same name is already present in the parent class. To access the num variable in parent class you
have to use "super" keyword.
Now let's take the same example but this time we pass super.num in the print statement.
What if the child class is not overriding any method: No need of super
When child class doesn't override the parent class method then we don't need to use the super
keyword to call the parent class method. This is because in this case we have only one version of
each method and child class has access to the parent class methods so we can directly call the
methods of the parent class without using super.
Method Overloading allows a class to have more than one method with the same name but
different arguments (parameters). It is similar to constructor overloading, that allows a class to have
more than one constructor with different parameters.
For example we have two methods, add(int a, int b) and add(int a, int b, int c). The two methods
although they have the same name they are different because the first one has only two parameters
and the second one has three parameters. This is called method overloading.
Result: Compile time error. Argument lists are exactly the same. Both methods are having same
number, data types and same sequence of data types.
Result: Valid case of overloading, the methods have different number of parameters and different
types of arguments.
Result: Valid case of overloading, the methods have different number of parameters.
Result: Invalid case of overloading. Argument lists are exactly the same. The return type doesn't
matter in method overloading.
Result:
Question 2 - return type is different. Method name and argument list same.
Declaring a method in sub class which is already present in the parent class is known as method
overriding.
Overriding is done so that a child class can give its own implementation to a method which is already
provided by the parent class. In this case the method in parent class is called overridden method
and the method in child class is called overriding method.
Now we have two subclasses of Animal class: Horse and Cat that extends Animal class.
And
Although we had the common action for all subclasses sound() but there were different ways to do
the same action. This is perfect example of polymorphism. It would not make any sense to just call
the generic sound() method as each Animal has a different sound.
A class that is declared using "abstract" keyword is known as abstract class. It can have abstract
methods (methods without body) or concrete methods (regular methods with body). A normal class
cannot have abstract methods.
An abstract class cannot be instantiated, which means you are not allowed to create an object of an
abstract class.
Rules
1. There are cases when it is difficult or often unnecessary to implement all the methods in the
parent class. In these cases, we can declare the parent class as abstract, which makes it a
special class which is not complete on its own.
A subclass of a superclass must override all the abstract methods that are declared in
superclass.
2. Abstract class cannot be instantiated which means you cannot create the object of it. To use
the abstract class, you need to create an object of the subclass and then call the non-abstract
methods of parent class as well as implemented methods (those that are abstract in parent
but implemented in child class).
3. If the child class doesn't implement all the abstract methods from the parent class, then it
need to be declared as abstract class.
Key Points:
1. An abstract class has no use until its extended by some other class.
2. If you declare an abstract method in the class, then you must declare the class as abstract.
Also a class can be declared abstract, even if the class doesn't have an abstract method.
3. An abstract class can have a non-abstract (concrete) methods.
Main basics:
1. Abstract method has no body.
2. Always end the declaration with a semicolon (;).
3. Abstract method must be overridden. An abstract class must be extended and in a same way
abstract method must be overridden.
4. A class has to be declared as abstract in order to have abstract methods.
Abstraction is a process where you show only relevant data and hide unnecessary details of an
object from the user.
Nested interfaces
An interface that is declared in another interface is called nested interface. They are also known as
inner interfaces.
Key Points:
1. We can't instantiate an interface in Java. That means that we cannot create an object of an
interface.
2. An interface provides full abstraction as none of its methods have body.
3. To implement an interface we use "implements" keyword.
4. When we implement an interface it has to be public.
Encapsulation means binding states in behaviors together. For example if you are creating a class,
you are doing encapsulation.
What is encapsulation?
The whole idea behind encapsulation is to hide the implementation details from users. If a data
member is private that means that it can be only accessed within the same class. No outside class
can access private data member (variable) of other class.
But, if we create public setter and getter method to update the data fields then the outside class can
access those private data fields via public methods.
A package is a pack (group) of classes, interfaces and other packages. In java we use packages to
organize our classes and interfaces. We have two types of packages in Java: built-in packages and
packages that we can create.
In Java we have several built-in packages, for example, when we need user input, we import a
package like this:
Here:
- Java is a top level package
- Util is a sub package
- And Scanner is a class which is present in the sub package util.
Points to remember:
1. Sometimes class name conflict may occur. For example: Let's say we have two packages
abcpackage and xyzpackage and both the packages have a class with the same name, let it be
JavaExample.java. Now suppose a class import both these packages like this:
This will throw compilation error. To avoid such errors you need to use the fully qualifies name
method.
2. If we create a class inside a package while importing another package then the package
declaration should be the first statement, followed by the package import.
4. The wild card import like package.* should be used carefully when working with subclasses.
For example: Let's say we have a package abs and inside that package we have another
package foo, now foo is a sub package.
Classes inside abc are: Example1, Example2, Example3
Classes inside foo are: Demo1, Demo2
So if we import the package abs using wildcard like the one bellow, then it will import classes
Example1, Example2, Example3.
To import the classes of the sub package we need to import like this:
This will import Demo1, Demo2 but it will not import Example1, Example2 and Example3.
So to import all the classes present in the package and sub package, we need to use two
import statements like this:
An access modifiers restricts the access of a class, constructor, data member and method in another
class. In Java we have four modifiers:
1. Default
2. Private
3. Protected
4. Public
An Enum is a special type of data type which is basically a collection (set) of constants.
Declaring an Enum
Here, we have a variable Directions of enum type, which is collection of four constants, EAST, WEST,
NORTH, and SOUTH.
The variable dir is of type Directions (that is an enum type). This variable can take any value, out of
the possible four values. In this case it's set to North.
You may get this error when you try to compile the program "javac is not recognized as an internal
or external command, operable program or batch file." This occurs when the java path is not set in
your system.
If you get this error, then you first need to set the path before compilation.
Step 4: After compilation the .java file gets translated into the .class file (byte code). Now we can run
the program. To run the program, type the following command and hit enter.
What is an exception?
An Exception is an unwanted event that interrupts the normal flow of the program. When an
exception occurs program execution gets terminated. In such cases we get a system generated error
message. By handling the exceptions we can provide a meaningful message to the user about the
issue rather than a system generated message, which may not be understandable to a user.
Exception Handling
If an exception occurs, which has not been handled by programmer then program execution get
terminated and a system generated error message is shown to the user.
This message is not user friendly so a user will not be able to understand what went wrong. In order
to let them know the reason in simple language, we handle exceptions.
Type of Exceptions
There are two types of exceptions in Java:
1. Checked Exceptions
2. Unchecked Exceptions
Check Exceptions
All exceptions other than Runtime Exceptions are known as Checked exceptions as the compiler
checks them during compilation to see whether the programmer has handled them or not.
Unchecked Exceptions
Runtime Exceptions are also known as Unchecked Exceptions. These exceptions are not checked at
Try block
The try block contains set of statements where an exception can occur. A try block is always
followed by a catch block, which handles the exception that occurs in associated try block. A try
block must be followed by catch blocks or finally block or both.
Catch block
A catch block is where you handle the exceptions, this block must follow the try block. A single try
block can have one or several catch blocks associated with it. You can have different exceptions in
different catch blocks. When an exception occurs in the try block, the corresponding catch block that
handles the particular exception executes.
3. If no exception occurs in try block then the catch block are completely ignored.
4. Corresponding catch block execute for that specific type of exception.
5. An exception can be thrown by a user.
Finally block
This block executes whether an exception occurs or not. You should place those statements in finally
blocks, that must execute whether exception occurs or not.
3. Throw keyword is used in the method body to throw an exception, while throws is used in
method signature to declare the exceptions that can occur in the statements present in the
method.
4. You can throw one exception at a time but you can handle multiple exceptions by declaring
them using throws keyword.
Java AWT
AWT stands for Abstract Windows Toolkit. It is a platform dependent API for creating Graphical User
Interface (GUI) for java programs.
Java AWT calls native platform (Operating systems) subroutine for creating components such as
textbox, checkbox, button etc. For example an AWT GUI having a button would have a different look
and feel across platforms like Windows, Mac OS & Unix.
An application build on AWT would look like a windows application when it runs on Windows, but
the same application would look like a Mac application when runs on Mac OS.
AWT hierarchy
Types of containers:
A container is a place where we add components like text field, button, checkbox etc. There are four
types of containers available in AWT: Window, Frame, Dialog and Panel. As shown in the hierarchy
diagram above, Frame and Dialog are subclasses of Window class.
Frame: A frame has tittle, border and menu bars. It can contain several components like buttons,
text fields, scrollbars etc. This is most widely used container while developing an application in AWT.
Java JFrame
The javax.swing.JFrame class is a type of container which inherits the java.awt.Frame class. JFrame
works like the main window where components like labels, buttons, text fields are added to create a
GUI. Unlike Frame, JFrame has the option to hide or close the window with the help of
setDefaultCloseOperation(int) method.
Semantic events
Are events at a higher level. They combine several low-level events. They are treated identically to
low events. For example: ActionEvent, ItemEvent.
Action Event
Button - mouse click on a button.
List - double click on the list element.
MenuItem - click on the choice element.
TextField - click on the button Return.
Item Event
CheckBox - marking or deleting (uncheck).
CheckBoxMenuItem - the selection element is highlighted or unchecked.
Choice - selected a new choice.
List - list item selected or deselected.
The Collection in Java is a framework that provides an architecture to store and manipulate the
group of objects.
Java Collections can achieve all the operations that you perform on a data such as searching, sorting,
insertion, manipulation, and deletion.
Java Collection means a single unit of objects. Java Collection framework provides many interfaces
(Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet,
LinkedHashSet, TreeSet).
Java ArrayList
Java ArrayList class uses a dynamic array for storing the elements. It is like an array, but there is no
size limit. We can add or remove elements anytime. So, it is much more flexible than the traditional
array. It is found in the java.util package.
The ArrayList in Java can have the duplicate elements also. It implements the List interface so we
can use all the methods of List interface here. The ArrayList maintains the insertion order internally.
The important points about Java ArrayList class are:
• Java ArrayList class can contain duplicate elements.
• Java ArrayList class maintains insertion order.
• Java ArrayList class is non synchronized.
• Java ArrayList allows random access because array works at the index basis.
• In ArrayList, manipulation is little bit slower than the LinkedList in Java because a lot of shifting
needs to occur if any element is removed from the array list.
ArrayList declaration
ArrayList<String> arrayList = new ArrayList<String>(); -/ creating new generic ArrayList.
ArrayList list = new ArrayList(); -/ creating non-generic ArrayList.
In a generic collection, we specify the type in angular braces. Now ArrayList is forced to have the
only specified type of objects in it. If you try to add another type of object, it gives compile time
error.
Collection class
Collections class provides static methods for sorting the elements of collections. If collection
elements are of Set or Map, we can use TreeSet or TreeMap. However, we cannot sort the elements
of List. Collections class provides methods for sorting the elements of List type elements.
Serialization in Java is a mechanism of writing the state of an object into a byte-stream. It is mainly
used in Hibernate, RMI, JPA, EJB and JMS technologies.
The reverse operation of serialization is called deserialization where byte-stream in converted into
an object. The serialization and deserialization process is platform - independent, it means you can
serialize an object in a platform and deserialize in different platform.
For serializing the object, we call the writeObject() method ObjectOutputStream, and for
deserialization we call the readObject() method of ObjectInputStream class.
Java.io.Serializable interface
Serializable is a marker interface (has no data member and method). It is used to "mark" Java classes
so that the objects of these classes may get a certain capability.
It must be implemented by the class whose object you want to persist.
The String class and all the wrapper classes implement the java.io.Serializable interface by default.
In the above example, Student class implements Serializable interface. Now its objects can be
converted into stream.
Now, ID will not be serialized, so when you deserialize the object after serialization, you will not get
the value of ID. It will return default value always. In such case, it will return 0 because the data type
of ID is an integer.
Java I/O (Input and Output) is used to process the input and produce the output.
Java uses the concept of a stream to make I/O operation fast. The java.io package contains all the classes required for input
and output operations.
Stream
A stream is a sequence of data. In Java, a stream is composed of bytes. It's called a stream because it is like a stream of water
that continues to flow.
OutputStream vs InputStream
1. OutputStream - Java application uses an output stream to write data to a destination. It may be a file, an array,
peripheral device or socket.
2. InputStream - Java application uses an input stream to read data from a source. It may be a file, an array, peripheral
device or socket.
OutputStream class
OutputStream class is an abstract class. It is the superclass of all classes representing an output stream of bytes. An output
stream accepts output bytes and sends them to some sink.
InputStream class
InputStream class is an abstract class. It is the superclass of all classes representing an input stream of bytes.
Class declaration
Declaration for Java.io.PrintStream class:
Class declaration
Declaration for Java.io.PrintWriter class:
Multithreading in Java
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.
Multitasking
Multitasking is a process of executing multiple tasks simultaneously. We use multitasking to utilize
the CPU. Multitasking can be achieved in two ways:
• Process-based Multitasking (Multiprocessing)
• Thread-based Multitasking (Multithreading)
Threads
Threads allow a program to operate more efficiently by doing multiple things at the same time.
Threads can be used to perform complicated tasks in the background without interrupting the main
program.
New - The thread is in new state if you create an instance of Thread class but before the invocation
Thread class
Thread class provide constructors and methods to create and perform operations on a thread.
Thread class extends Object class and implements Runnable interface.
Runnable Interface
The Runnable interface should be implemented by any class whose instances are intended to be
executed by a thread. Runnable interface have only one method named run().
Starting a thread
Start() method of Thread class is used to start a newly created thread. It performs following tasks:
• A new thread starts
• The thread moves from New state to the Runnable state.
• When the thread gets a chance to execute, its target run() method will run.
Default priority of a thread is 5 (NORM_PRIORITY). The value of MIN_PRIORITY is 1 and the value of
MAX_PRIORITY is 10.
ThreadGroup in Java
Java provides a convenient way to group multiple threads in a single object. In such way, we can
suspends, resume or interrupt group of threads by a single method call.
Java thread group is implemented by java.lang.ThreadGroup class.
A ThreadGroup represents a set of threads. A thread group can also include the other thread group.
The thread group creates a tree in which every thread group except the initial thread group has a
parent.
A thread is allowed to access information about its own thread group, but I cannot access the
information about its thread group's parent thread group or any other thread groups.
Factory method
The method that returns the instances of a class is known as factory method.
Synchronization in Java is the capability the 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
There are two types of synchronization
1. Process Synchronization.
2. Thread Synchronization.
Thread Synchronization
There are two types of thread synchronization mutual exclusive and inter-thread communication.
1. Mutual Exclusive
1. Synchronized method.
2. Synchronized block.
3. Static synchronization.
2. Cooperation (Inter-thread communication in Java)
Mutual Exclusive
Mutual Exclusive helps keep threads from interfering with one another while sharing data. This can
be done by three ways in Java:
1. By synchronized method.
2. By synchronized block
3. By static synchronization.
1. Wait() method
Causes current thread to release the lock and wait until either another thread invokes the notify()
method or the notifyAll() method for this object, or a specified amount of time has elapsed.
The current thread must own this object's monitor, so it must be called from the synchronized
method only otherwise it will throw exception.
2. Notify() method
Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this
object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of
the implementation. Syntax:
Public final void notify()
3. notifyAll() method
Wakes up all threads that are waiting on this object's monitor. Syntax:
Public final void notifyAll()
Java Networking is a concept of connecting two or more computing devices together so that we can
share resources.
Java socket programming provides facility to share data between different computing devices.
IP Address
IP address is a unique number assigned to a node of a network e.g. 192.168.0.1. It is composed of
octets that range from 0 to 255.
It is a logical address that can be changed.
Protocol
A protocol is a set of rules basically that is followed for communication. For example:
• TCP
• FTP
• Telnet
• SMTP
• POP etc.
Port Number
The port number is used to uniquely identify different applications. It acts as a communication
endpoint between applications.
The port number is associated with the IP address for communication between two applications.
MAC Address
MAC (Media Access Control) Address is a unique identifier of NIC (Network Interface Controller). A
network node can have multiple NIC but each with unique MAC.
Socket
A socket is an endpoint between two way communication.
Socket class
A socket is simply an endpoint for communications between the machines. The Socket class can be
used to create a socket.
ServerSocket class
The ServerSocket class can be used to create a server socket. This object is used to establish
communication with the clients.
Creating Client:
To create the client application, we need to create the instance of Socket class. Here, we need to
pass the IP address or hostname of the Server and a port number. Here, we are using localhost
because our server is running on same system.
Example of Java socket programming where client sends a text and server receives and prints it.
File: MyServer.java
To run the program open command prompt and type javac MyServer.java.
Java URL
The Java URL class represents an URL. URL is an acronym for Uniform Resource Locator. It points to a
resource on the World Wide Web. For example:
A Java Bean is a Java class that should follow the following conventions:
• It should have a no-arg constructor.
• It should be Serializable.
• It should provide methods to set and get the values of the properties, known as getter and
setter methods.