Java Unit - I Notes
Java Unit - I Notes
Unit –1
History of Java
JDK 1.0: Released on January 23, 1996, as the first public version.
JDK 1.1: Introduced features like inner classes, JavaBeans, JDBC, and RMI on
February 19, 1997.
J2SE 1.2: Marked a significant expansion of the Java platform, rebranded as Java 2
and released on December 8, 1998.
J2SE 1.3 - 1.4: Brought enhancements like HotSpot JVM inclusion, RMI over IIOP,
and a new I/O API for Java.
Java SE 5.0 (Tiger): Introduced generics, annotations, autoboxing/unboxing, and the
enhanced for-loop in September 2004.
Java SE 6 (Mustang): Released in December 2006, it improved scripting language
support and performance.
Java SE 7 (Dolphin): Launched in July 2011 with language changes like the diamond
operator and improved exception handling.
Java SE 8: Brought lambda expressions and the Stream API in March 2014,
enhancing functional programming capabilities.
Java SE 9 - 10: Introduced the module system and local-variable type inference,
respectively.
Java SE 11 (LTS): Released in September 2018, it removed certain features like
JavaFX and introduced new ones like the HTTP Client API.
Java SE 12 - 15: Continued to introduce new language features and APIs.
Java SE 16 - 17 (LTS): Brought records, pattern matching for instanceof, and sealed
classes.
Java SE 18 - 19: Included features like the UTF-8 by Default and the Foreign
Function & Memory API.
Java SE 20 - 21 (LTS): Released in March 2023, with Java SE 21 being the latest
LTS version as of September 2023.
Java SE 22: The current stable version, released in March 2024, with features like the
Foreign Function & Memory API.
Why Java was named as "Oak"?
Why Oak? Oak is a symbol of strength and chosen as a national tree of many
countries like the U.S.A., France, Germany, Romania, etc.
In 1995, Oak was renamed as "Java" because it was already a trademark by Oak
Technologies.
Advantages of Java
1. Java is Simple
Any language can be considered as simple if it is easy to learn and understand. The
syntax of Java is straightforward, easy to write, learn, maintain, and understand, the
code is easily debuggable.
Moreover, Java is less complex than the languages like C and C++, because many of
the complex features of these languages are being removed from Java such as explicit
pointers concept, storage classes, operator overloading, and many more.
It also helps us to increase security by binding the data and functions into a single unit
and not letting it be accessed by the outside world. It also helps to organize the bigger
modules into smaller ones so they are easy to understand.
Java reduces security threats and risks by avoiding the use of explicit pointers. A
pointer stores the memory address of another value that can cause unauthorized
access to memory.
This issue is resolved by removing the concept of pointers. Also, there is a Security
manager in Java for each application that allows us to define the access rules for
classes.
Java programs are cheap to develop and maintain as these programs are dependent on
a specific hardware infrastructure to run. We can easily execute them on any machine
that reduces the extra cost to maintain.
5. Java is platform-independent
Java offers a very effective boon to its users by providing the feature of platform
independence that is Write Once Run Anywhere(WORA) feature.
The compiled code, i.e the byte code of java is platform-independent and can run on
any machine irrespective of the operating system. We can run this code on any
machine that supports the Java Virtual Machine(JVM) as shown in the figure below:
Java is a portable language due to its platform independence feature. As the Java code
can be run on any platform, it is portable and can be taken to any platform and can be
executed on them. Therefore Java also provides the advantage of portability.
Java is a multithreaded language that is in Java more than one thread can run at the
same time. A thread is the smallest unit of a process. Multithreading helps us to gain the
maximum utilization of CPU.
Multiple threads share a common memory area and increase the efficiency and
performance of the application. These threads run independently of each other without
affecting each other.
8. Use Cases
Java is a powerful language that can be used in many software development domains.
It is particularly useful for:
Enterprise-level applications
Desktop software
Disadvantages of Java
Java mainly works on storage and not focuses on the backup of data. This is a major
drawback that makes it lose the interest and ratings among users.
Documentation Section
The documentation section is an important section but optional for a Java program. It
includes basic information about a Java program. The information includes
the author's name, date of creation, version, program name, company
name, and description of the program. It improves the readability of the program.
Whatever we write in the documentation section, the Java compiler ignores the
statements during the execution of the program. To write the statements in the
documentation section, we use comments. The comments may be single-line, multi-
line, and documentation comments.
o Single-line Comment: It starts with a pair of forwarding slash (//). For example:
o Multi-line Comment: It starts with a /* and ends with */. We write between these
two symbols. For example:
1. /*It is an example of
2. multiline comment*/
3. Documentation Comment: It starts with the delimiter (/**) and ends with */. For
example:
4. /**It is an example of documentation comment*/
Package Declaration
The package declaration is optional. It is placed just after the documentation section. In
this section, we declare the package name in which the class is placed. Note that there
can be only one package statement in a Java program. It must be defined before any
class and interface declaration. It is necessary because a Java class can be placed in
different packages and directories based on the module they are used. For all these
classes package belongs to a single parent directory. We use the keyword package to
declare the package name. For example:
Import Statements
The package contains the many predefined classes and interfaces. If we want to use any
class of a particular package, we need to import that class. The import statement
represents the class stored in the other package. We use the import keyword to import
the class. It is written before the class declaration and after the package statement. We
use the import statement in two ways, either import a specific class or import all classes
of a particular package. In a Java program, we can use multiple import statements. For
example:
Interface Section
1. interface car
2. {
3. void start();
4. void stop();
5. }
Class Definition
In this section, we define the class. It is vital part of a Java program. Without the class,
we cannot create any Java program. A Java program may conation more than one class
definition. We use the class keyword to define the class. The class is a blueprint of a
Java program. It contains information about user-defined methods, variables, and
constants. Every Java program has at least one class that contains the main() method.
For example:
In this section, we define variables and constants that are to be used later in the
program. In a Java program, the variables and constants are defined just after the class
definition. The variables and constants store values of the parameters. It is used during
the execution of the program. We can also decide and define the scope of variables by
using the modifiers. It defines the life of the variables. For example:
In this section, we define the main() method. It is essential for all Java programs.
Because the execution of all Java programs starts from the main() method. In other words,
it is an entry point of the class. It must be inside the class. Inside the main method, we
create objects and call the methods. We use the following statement to define the main()
method:
For example:
5. //statements
6. }
7. }
You can read more about the Java main() method here.
In this section, we define the functionality of the program by using the methods. The
methods are the set of instructions that we want to perform. These instructions execute
at runtime and perform the specified task. For example:
Java Environment
What is JRE?
Java Run-time Environment (JRE) is the part of the Java Development Kit (JDK). It is a
freely available software distribution which has Java Class Library, specific tools, and a
stand-alone JVM. It is the most common environment available on devices to run java
programs. The source Java code gets compiled and converted to Java bytecode. If you
wish to run this bytecode on any platform, you require JRE. The JRE loads classes, verify
access to memory, and retrieves the system resources. JRE acts as a layer on the top of
the operating system.
It also includes
o Technologies which get used for deployment such as Java Web Start.
o Toolkits for user interface like Java 2D.
o Integration libraries like Java Database Connectivity (JDBC) and Java Naming
and Directory Interface (JNDI).
Java Virtual Machine (JVM) consists of Java HotSpot Client and Server Virtual
Machine.
User interface libraries include Swing, Java 2D, Abstract Window Toolkit (AWT),
Accessibility, Image I/O, Print Service, Sound, drag, and Drop (DnD), and input
methods.
Lang and util base libraries, which include lang and util, zip, Collections,
Concurrency Utilities, management, Java Archive (JAR), instrument,
reflection, versioning, Preferences API, Ref Objects, Logging, and Regular
Expressions.
Other base libraries, including Java Management Extensions (JMX), Java Native
Interface (JNI), Math, Networking, international support, input/output (I/O), Beans,
Java Override Mechanism, Security, Serialization, extension mechanism, and Java
for XML Processing (XML JAXP).
Deployment technologies such as Java Web Start, deployment, and Java plug-in.
Working of JRE
Java Development Kit (JDK) and Java Runtime Environment (JRE) both interact with
each other to create a sustainable runtime environment that enables Java-based
applications to run seamlessly on any operating system. The JRE runtime
architecture consists of the following elements as listed:
1. ClassLoader
2. ByteCode verifier
3. Interpreter
Now let us briefly about them as follows:
Bytecode Verifier: The bytecode checker ensures the format and precision of
Java code before passing it to the interpreter. If the code violates system
integrity or access rights, the class is considered corrupt and will not load.
Interpreter: After loading the byte code successfully, the Java interpreter
creates an object of the Java virtual machine that allows the Java program to
run natively on the underlying machine.
What is JVM :-
The Java Virtual Machine is called JVM, is an abstract computing machine or virtual
machine interface that drives the java code.
Reading Bytecode.
Verifying bytecode.
Linking the code with the library
JVM is the main component of Java architecture, and it is the part of the JRE
(Java Runtime Environment).
A program of JVM is written in C Programming Language, and JVM is Operating
System dependent.
JVM is responsible for allocating the necessary memory needed by the Java
program.
JVM is responsible for deallocating memory space.
JDK
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a
software development environment which is used to develop Java applications
and applets. It physically exists. It contains JRE + development tools.
JDK is an implementation of any one of the below given Java Platforms released by
Oracle Corporation:
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such
as an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation
generator (Javadoc), etc. to complete the development of a Java Application.
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such
as an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation
generator (Javadoc), etc. to complete the development of a Java Application.
Everyone is in search of the highest-paying job so as to get into it. And, in the list, the
web developer has been on the top for years and will remain in the same place due to
its demand. If you’re the one who’s looking to get into it. you must be aware of the
most important terms used in it. Out of all the terms, API is yet another term that plays
a very important role in building a website. Now, what is an API – (Application
Programming Interface)?
To make you clear with the diagram of what is API, let’s take a real-life example of
an API, you can think of an API as a waiter in a restaurant who listens to your order
request, goes to the chef, takes the food items ordered and gets back to you with the
order. Also, if you want to look for the working of an API with the example, here’s
one. You’re searching for a course(let’s say DSA-Self Paced) on the XYZ website,
you send a request(product search requested) through an API, and the database
searches for the course and checks if it’s available, the API is responsible here to
send your request to the database (in search of the course) and responds with the
output(best DSA courses)
Procedural Programming is a
Object-oriented Programming is
programming language that follows
a programming language that
a step-by-step approach to break
uses classes and objects to
down a task into a collection of
create models based on the real
variables and routines (or
world environment.
Definition subroutines) through a sequence of
In OOPs, it makes it easy to
instructions.
maintain and modify existing
Each step is carried out in order in a
code as new objects are created
systematic manner so that a
inheriting characteristics from
computer can understand what to
existing ones.
do.
C++, C#, Java, Python, etc. are C, BASIC, COBOL, Pascal, etc. are
Examples
the examples of OOP languages. the examples POP languages.