0% found this document useful (0 votes)
5 views21 pages

Java Unit - I Notes

Java is an object-oriented programming language developed by Sun Microsystems in 1995, designed for platform independence and ease of use. It offers features such as simplicity, security, and multithreading, making it suitable for various applications including web and mobile development. The document also outlines Java's version history, advantages and disadvantages, and the basic structure of a Java program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views21 pages

Java Unit - I Notes

Java is an object-oriented programming language developed by Sun Microsystems in 1995, designed for platform independence and ease of use. It offers features such as simplicity, security, and multithreading, making it suitable for various applications including web and mobile development. The document also outlines Java's version history, advantages and disadvantages, and the basic structure of a Java program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

1

Unit –1

INTRODUCTION TO JAVA M-8

Introduction to Java:- Java is an object-oriented programming language with its runtime


environment. It is a combination of features of C and C++ with some essential additional
concepts. Java is well suited for both standalone and web application development and
is designed to provide solutions to most of the problems faced by users of the internet
era

Java is a class-based, object-oriented programming language that is designed to have


as few implementation dependencies as possible. It is intended to let application
developers write once, and run anywhere (WORA), meaning that compiled Java code
can run on all platforms that support Java without the need for recompilation. Java
was first released in 1995 and is widely used for developing applications for desktop,
web, and mobile devices. Java is known for its simplicity, robustness, and security
features, making it a popular choice for enterprise-level applications

What is Java: - Developed by Sun Microsystems in 1995, Java is a highly popular,


object-oriented programming language. This platform independent programming
language is utilized for Android development, web development, artificial intelligence,
cloud applications, and much more.

History of Java

Java, a class-based, object-oriented programming language, has undergone numerous


changes and expansions since its inception. The language was initially created for
interactive television, but it proved too advanced for the digital cable television industry
at the time. The Green Team, consisting of James Gosling, Mike Sheridan, and Patrick
Naughton, initiated the Java language project in June 1991. It was originally designed
for small, embedded systems in electronic appliances like set-top boxes. Initially named
"Greentalk" with a .gt extension, it was later renamed to "Oak" and eventually to "Java"
in 1995 due to trademark issues with Oak Technologies.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


2

Key Milestones in Java's Version History

 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"?

Subject –Java Programming Language Created by - MR.S.B.Baviskar


3


 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 and Disadvantages of Java

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.

2. Java is an Object-Oriented Programming language

Java is an object-oriented language that helps us to enhance the flexibility and


reusability of the code. Using the OOPs concept, we can easily reuse the object in other
programs.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


4

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.

3. Java is a secure language

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.

4. Java is cheap and economical to maintain

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:

Subject –Java Programming Language Created by - MR.S.B.Baviskar


5

5. Java is a high-level programm4ing language

Java is a high-level programming language as it is a human-readable language. It is


similar to human language and has a very simple and easy to maintain syntax that is
similar to the syntax of C++ language but in a simpler manner.

6. Java supports portability feature

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.

7. Java supports Multithreading

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.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


6

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

 Mobile development for Android

 Scientific computing and data analysis

 Web development and web apps

 Embedded programming and the IoT

 Desktop software

Disadvantages of Java

1.Slower Execution Speed

While Java’s platform independence is a big benefit, it also comes at a cost to


performance. Java programs (on average) run a bit slower than its natively compiled
“cousin” like C and C++. A lot of these performance issues, however, have been
mitigated by a number of factors, such as modern hardware processing power,
optimizations in the JVM in more recent versions of Java, and further performance
optimizations by Java’s built-in garbage collector. Still, when dealing with applications
that require more access to low-level hardware resource manipulation, you may want to
consider options like C or C++, both of which excel in this arena.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


7

2.Java provides no backup facility

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.

3.Java requires significant memory space

Java requires a significant or major amount of memory space as compared to other


languages like C and C++. During the execution of garbage collection, the memory
efficiency and the performance of the system may be adversely affected.

 Structure of Java Program


Java is an object-oriented programming, platform-
independent, and secure programming language that makes it popular. Using the Java
programming language, we can develop a wide variety of applications. So, before diving
in depth, it is necessary to understand the basic structure of Java program in detail.
In this section, we have discussed the basic structure of a Java program. At the end
of this section, you will able to develop the Hello world Java program, easily.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


8

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:

1. //First Java Program

Subject –Java Programming Language Created by - MR.S.B.Baviskar


9

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:

1. package javatpoint; //where javatpoint is the package name


2. package com.javatpoint; //where com is the root directory and javatpoint is the subdirec
tory

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:

Subject –Java Programming Language Created by - MR.S.B.Baviskar


10

1. import java.util.Scanner; //it imports the Scanner class only


2. import java.util.*; //it imports all the class of the java.util package

Interface Section

It is an optional section. We can create an interface in this section if required. We use


the interface keyword to create an interface. An interface is a slightly different from the
class. It contains only constants and method declarations. Another difference is that it
cannot be instantiated. We can use interface in classes by using
the implements keyword. An interface can also be used with other interfaces by using
the extends keyword. For example:

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:

1. class Student //class definition


2. {
3. }

Subject –Java Programming Language Created by - MR.S.B.Baviskar


11

Class Variables and Constants

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:

1. class Student //class definition


2. {
3. String sname; //variable
4. int id;
5. double percentage;
6. }

Main Method Class

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:

1. public static void main(String args[])


2. {
3. }

For example:

1. public class Student //class definition


2. {
3. public static void main(String args[])
4. {

Subject –Java Programming Language Created by - MR.S.B.Baviskar


12

5. //statements
6. }
7. }

You can read more about the Java main() method here.

Methods and behavior

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:

1. public class Demo //class definition


2. {
3. public static void main(String args[])
4. {
5. void display()
6. {
7. System.out.println("Welcome to PratapCollege");
8. }
9. //statements
10. }
11. }

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

Subject –Java Programming Language Created by - MR.S.B.Baviskar


13

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).

o Libraries such as Lang and util.


o Other base libraries like Java Management Extensions (JMX), Java Native
Interface (JNI) and Java for XML Processing (JAX-WS).

Java Virtual Machine (JVM) consists of Java HotSpot Client and Server Virtual
Machine.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


14

 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:

 ClassLoader: Java ClassLoader dynamically loads all the classes necessary to


run a Java program. Because classes are only loaded into memory whenever they
are needed, the JRE uses ClassLoader will automate this process when needed.
During the initialization of the JVM, three classLoaders are loaded:

 Bootstrap class loader


 Extensions class loader
 System class loader

Subject –Java Programming Language Created by - MR.S.B.Baviskar


15

 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.

 JVM, i.e., Java Virtual Machine.


 JVM is the engine that drives the Java code.
 Mostly in other Programming Languages, compiler produce code for a particular
system but Java compiler produce Bytecode for a Java Virtual Machine.
 When we compile a Java program, then bytecode is generated. Bytecode is the
source code that can be used to run on any platform.
 Bytecode is an intermediary language between Java source and the host system.
 It is the medium which compiles Java code to bytecode which gets interpreted on
a different machine and hence it makes it Platform/Operating system
independent.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


16

JVM work following steps

 Reading Bytecode.
 Verifying bytecode.
 Linking the code with the library

Java is called platform independent because of Java Virtual Machine. As different


computers with the different operating system have their JVM, when we submit
a .class file to any operating system, JVM interprets the bytecode into machine level
language.

 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.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


17

 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:

o Standard Edition Java Platform


o Enterprise Edition Java Platform
o Micro Edition Java Platform

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.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


18

What is an API (Application Programming Interface)

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)?

Subject –Java Programming Language Created by - MR.S.B.Baviskar


19

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)

API full form is an Application Programming Interface that is a collection of


communication protocols and subroutines used by various programs to communicate
between them. A programmer can make use of various API tools to make their
program easier and simpler. Also, an API facilitates programmers with an efficient way
to develop their software programs. Thus api meaning is when an API helps two
programs or applications to communicate with each other by providing them with the
necessary tools and functions. It takes the request from the user and sends it to the
service provider and then again sends the result generated from the service provider
to the desired user.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


20

Procedural Programming vs Object-Oriented Programming

Parameter Object Oriented Programming Procedural Programming

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.

In OOPs concept of objects and In procedural programming, the


classes is introduced and hence main program is divided into small
Approach the program is divided into small parts based on the functions and is
chunks called objects which are treated as separate program for
instances of classes. individual smaller program.

In OOPs access modifiers are


Access No such modifiers are introduced in
introduced namely as Private,
modifiers procedural programming.
Public, and Protected.

Due to abstraction in OOPs data


Procedural programming is less
Security hiding is possible and hence it is
secure as compare to OOPs.
more secure than POP.

Subject –Java Programming Language Created by - MR.S.B.Baviskar


21

OOPs due to modularity in its


programs is less complex and There is no simple process to add
hence new data objects can be data in procedural programming, at
Complexity
created easily from existing least not without revising the whole
objects making object-oriented program.
programs easy to modify

Procedural programming divides a


OOP divides a program into
Program program into small programs and
small parts and these parts are
division each small program is referred to as
referred to as objects.
a function.

Procedural programming does not


OOP gives importance to data
give importance to data. In POP,
Importance rather than functions or
functions along with sequence of
procedures.
actions are followed.

OOP provides inheritance in


Procedural programming does not
Inheritance three modes i.e. protected,
provide any inheritance.
private, and public

C++, C#, Java, Python, etc. are C, BASIC, COBOL, Pascal, etc. are
Examples
the examples of OOP languages. the examples POP languages.

Subject –Java Programming Language Created by - MR.S.B.Baviskar

You might also like