0% found this document useful (0 votes)
2 views92 pages

Complete JAVA Notes ???✍️ (1)

Java is a high-level, robust, object-oriented programming language developed by Sun Microsystems in 1995, known for its platform independence and security features. It supports various applications across devices, including desktop, web, and mobile, and is characterized by its ease of learning, community support, and object-oriented principles. Key features include multi-threading, portability, and the ability to create distributed applications, making it a popular choice among developers.

Uploaded by

Krishna Joshi
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)
2 views92 pages

Complete JAVA Notes ???✍️ (1)

Java is a high-level, robust, object-oriented programming language developed by Sun Microsystems in 1995, known for its platform independence and security features. It supports various applications across devices, including desktop, web, and mobile, and is characterized by its ease of learning, community support, and object-oriented principles. Key features include multi-threading, portability, and the ability to create distributed applications, making it a popular choice among developers.

Uploaded by

Krishna Joshi
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/ 92

What is JAVA

ABHISHEK MAURYA

What is JAVA 1
Java is a programming language and a platform. Java is a high level,
robust, object-oriented and secure programming language.
 Java was developed by Sun Microsystems (which is now the subsidiary of
Oracle) in the year 1995 and released 23 January 1996. The first version of
java was JDK 1.0 and latest version of java 17.0.2
 James Gosling is known as the father of Java. Before Java, its name was
Oak. Since Oak was already a registered company, so James Gosling and his
team changed the name from Oak to Java. The team of java called green team
and the first program name was Greentalk which is created by James
Gosling.
 Platform: Any hardware or software environment in which a program runs, is
known as a platform. Since Java has a runtime environment (JRE) and API, it
is called a platform.
2
 According to Sun, 5 billion devices run Java. There are many devices
where Java is currently used. Some of them are as follows:
• Desktop Applications such as acrobat reader, media player, antivirus, etc.
• Web Applications such as irctc.co.in, etc.
• Enterprise Applications such as banking applications.
• Mobile
• Embedded System
• Smart Card
• Robotics
• Games, etc.
Why Use Java ? 3

• Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
• It is one of the most popular programming language in the world
• It is easy to learn and simple to use
• It is open-source and free
• It is secure, fast and powerful
• Write once run any where
• It has a huge community support (tens of millions of developers)
• Java is an object oriented language which gives a clear structure to
programs and allows code to be reused, lowering development costs
• As Java is close to C++ and C#, it makes it easy for programmers to switch
to Java.
Features of Java
1. Object – Oriented 4

Java is a pure Object Oriented Programming Language


(OOPs). Procedures are not used in it but it is only Object
based language. Java follows the concept of OOPs which
simplifies the work of software development and
maintenance.
2. Platform Independent 5

Java is Platform Independent Language. It runs in every


platform like Android, Windows, Linux and Mac. Programs
written in Java can be run in any operating system, such
as if Java's program is written in Windows OS, then we will
be able to run it easily in Linux OS as well.
3. Secure 6

Another great feature of Java is that it is a secure language.


Java is the most secure because the Java program runs in the
Java Run Time Environment, before generating the machine
code, the program detects the error by running some tests on
the JVM. The Java language is virus free, which keeps the
programs safe.
How JDK Work’s ? 7

(JDK) Java Development Kit


How JRE Work’s ? 8
(JRE) Java Runtime Environment
How JVM Work’s ? 9

(JVM) Java Virtual Machine


How JVM Work’s ? 10

(JVM) Java Virtual Machine


4. Simple Language 11

Java is an easy language because it has syntax like C++ which


can be easily learned but operator overloading and header files
are not used in it like C++, which makes learning even easier.
5. Portable 12

Java is a portable language because the source code of Java


is converted into Byte Code with the help of Complier, this Byte
Code can be run in any system, so it can be easily obtained.
6. Robust 13

Robust means strong. Any program made in Java can work in


different environments without crashing, its programs never
crash. Whatever error comes in Java, they can be easily found
and solved. For all these reasons, Java is a robust language.
7. Distributed 14

Java is a Distributed, which means that Java programs are


made to run in the Internet, from Java, we can create
Distributed Applications, these are the applications that are
distributed on different networks, but together they perform
tasks. In this, http and ftp protocols are used, so that data is
easily accessed in the Internet.
8. Multi Threaded 15

Java is a Multi Threaded Language, which means that in Java,


big programs are divided into small sub programs and these
sub programs are done sequentially, similarly. Java can
complete many tasks together, this feature makes Java fast
and Interactive makes this feature used in Multi Media and
Web Application.
9
9
9
9
9
9
9
9
9
9
Click Here
9
9
9
9
9
Press Ctrl + R and Type cmd

9
9
Successfully installed

9
Java Not installed

9
Java Variables ? 35

• A variable is a container which holds the value


while the Java program is executed. A variable is
assigned with a data type.
• Variable is a name of memory location. There are
three types of variables in java: local, instance
and static.
• There are two types of data types in Java:
primitive and non-primitive.
Variable ? 36

• A variable is the name of a reserved area


allocated in memory. In other words, it is a
name of the memory location. It is a
combination of "vary + able" which means its
value can be changed.

int data=50;//Here data is variable


What is OOPs ? 37

OOPs (Object-Oriented Programming System)


Object means a real-world entity such as a pen, chair, table, computer,
watch, etc. Object-Oriented Programming is a methodology or paradigm to
design a program using classes and objects. It simplifies software
development and maintenance by providing some concepts:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
37

NOTE:
A class should always start with an uppercase first letter, and that the name of
the java file should match the class name.
Public: It is a Access Specifier used to public the Function .

Static: When java runtime starts, there is no object of the class present. That’s why the main
method has to be static so that JVM can load the class into memory and call the main
method.

Void: It is used to Non Return Type


Main: It is a Brain of the Program.
String: It is a Class which is used to accept a single argument of type String array.
Args: it is a Object of String class
Creating Object With Class. 38
Before Object

After Object
Class Methods Static Vs Public 39
Constructors 44

A constructor in Java is a special method that is used to


initialize objects. The constructor is called when an object
of a class is created. It can be used to set initial values for
object attributes:
45
It is Automatically Call
When Object is Created

Constructors is used to
Set the initial value for
the class attribute x
Encapsulation 46

• Encapsulation is a mechanism through which we can


wrapping the data member and member method of
class in a single unit called Encapsulation
• Note:
• 1) Declare the class Variable as a private
• 2) Declare the class Method as a public
1
Packages 48

A package in Java is used to group related classes.


Think of it as a folder in a file directory. We use
packages to avoid name conflicts, and to write a better
maintainable code. Packages are divided into two
categories:
• Built-in Packages (packages from the Java API)
• User-defined Packages (create your own packages)
Built-in Packages 1

• The Java API is a library of prewritten classes, that are free


to use, included in the Java Development Environment.
• The library contains components for managing input,
database programming, and much much more
• The library is divided into packages and classes. Meaning
you can either import a single class (along with its methods
and attributes), or a whole package that contain all the
classes that belong to the specified package.
50
Inheritance 51

it is possible to inherit attributes and methods from one


class to another. We group the "inheritance concept"
into two categories:
•subclass (child) - the class that inherits from another
class
•superclass (parent) - the class being inherited from
To inherit from a class, use the extends keyword.
Types of inheritance in java 52

Single Inheritance:

A B
53
Multilevel Inheritance
A B C
5454
Hierarchical Inheritance

55
A

B C

In Hierarchical Inheritance One class Provide their


property to more than one class in the above Diagram
Class A provide property to class B and class C
56
Polymorphism 57

• The word polymorphism means having many forms. In simple


words, we can define polymorphism as the ability of a
message to be displayed in more than one form.
• Polymorphism is considered one of the important features of
Object-Oriented Programming. Polymorphism allows us to
perform a single action in different ways. In other words,
polymorphism allows you to define one interface and have
multiple implementations. The word “poly” means many and
“morphs” means forms, So it means many forms.
Types of polymorphism 58

1. Compile-time Polymorphism
2. Runtime Polymorphism

Compile Time Polymorphism

It is also known as static polymorphism. This type of


polymorphism is achieved by function overloading or operator
overloading.
Note: But Java doesn’t support the Operator Overloading.
Method Overloading 59

• When there are multiple


functions with the same name
but different parameters then
these functions are said to
be overloaded. Functions can
be overloaded by change in the
number of arguments or/and a
change in the type of
arguments.
Runtime polymorphism 60

• It is also known as Dynamic Method


Dispatch. It is a process in which a
function call to the overridden method
is resolved at Runtime. This type of
polymorphism is achieved by Method
Overriding. Method overriding, on the
other hand, occurs when a derived
class has a definition for one of the
member functions of the base class.
That base function is said to
be overridden.
User Define Packages 61

• The package which are created by java programmer or user for their own use
are classed user defined package

• Syntax: package package name;


• Rule 1)package statement must be first line of the program.
2)The way of compilation of these classes would be different.
Java –d . Classname.java
62
Inner Classes 63
• In Java, it is also possible to
nest classes (a class within a
class). The purpose of
nested classes is to group
classes that belong
together, which makes your
code more readable and
maintainable.
Private Inner Class 64
Unlike a "regular" class, an
inner class can
be private or protected. If
you don't want outside
objects to access the inner
class, declare the class
as private:
Static Inner Class 65

An inner class can also


be static, which means
that you can access it
without creating an object
of the outer class:
Access Outer Class From Inner Class 66

• One advantage of inner


classes, is that they can
access attributes and
methods of the outer
class:
Abstraction 67

Abstract Classes and Methods


Data abstraction is the process of hiding certain details and showing only
essential information to the user.
Abstraction can be achieved with either abstract
classes or interfaces The abstract keyword is a non-access modifier, used
for classes and methods:
•Abstract class: is a restricted class that cannot be used to create objects
(to access it, it must be inherited from another class).

•Abstract method: can only be used in an abstract class, and it does not
have a body. The body is provided by the subclass (inherited from).
68
Interface 69

Another way to achieve abstraction in Java, is with interfaces.


An interface is a completely "abstract class" that is used to group related
methods with empty bodies:

To access the interface methods, the interface must be "implemented"


(kind a like inherited) by another class with the implements keyword
(instead of extends). The body of the interface method is provided by
the "implement" class:
70
Enum 71
An enum is a special "class"
that represents a group
of constants (unchangeable
variables,
like final variables).

To create an enum, use


the enum keyword (instead
of class or interface), and
separate the constants with
a comma. Note that they
should be in uppercase You can access enum constants with
letters: the dot syntax:
Dates 72

Java does not have a built-in Date class, but we can import the java. Time package
to work with the date and time API. The package includes many date and time
classes.

Class Description

LocalDate Represents a date (year, month, day (yyyy-MM-dd))

LocalTime Represents a time (hour, minute, second and nanoseconds (HH-mm-ss-ns))

LocalDateTime Represents both a date and a time (yyyy-MM-dd-HH-mm-ss-ns)


Display Current Date
73
Display Current Time
74
Display Current Date and Time
75
Array List 76

The Array List class is a resizable array, which can be found in


the java.util package.
The difference between a built-in array and an ArrayList in Java, is that the
size of an array cannot be modified (if you want to add or remove elements
to/from an array, you have to create a new one). While elem20ents can be
added and removed from an ArrayList whenever you want.

Syntax
import java.util.ArrayList; // import the Array List class
ArrayList<String> cars = new Array List<String>(); // Create an ArrayList
77
ADD is used to insert element

GET is used to access element


78
Update ArrayList using Set function 79
80
81

REMOVE AND
CLEAR FUNCTION
Java AWT 82

Java AWT (Abstract Window Toolkit) is an API to develop Graphical User


Interface (GUI) or windows-based applications in Java.
Java AWT components are platform-dependent i.e. components are displayed
according to the view of operating system. AWT is heavy weight i.e. its
components are using the resources of underlying operating system (OS).
The java.awt package
provides classes
for AWT API such as TextField, Label, TextArea, RadioButton, CheckBox
, Choice, List etc.
The AWT tutorial will help the user to understand Java GUI programming in
simple and easy steps.
Why AWT is platform independent? 83

Java AWT calls the native platform calls the native platform (operating
systems) subroutine for creating API components like TextField, ChechBox,
button, etc.

For example, an AWT GUI with components like TextField, label and button
will have different look and feel for the different platforms like Windows,
MAC OS, and Unix. The reason for this is the platforms have different view
for their native components and AWT directly calls the native subroutine
that creates those components.

In simple words, an AWT application will look like a windows application in


Windows OS whereas it will look like a Mac application in the MAC OS.
Java Swing 84

Java Swing tutorial is a part of Java Foundation Classes (JFC) that is used to
create window-based applications. It is built on the top of AWT (Abstract
Windowing Toolkit) API and entirely written in java.
Unlike AWT, Java Swing provides platform-independent and lightweight
components.
The javax.swing package provides classes for java swing API such as JButton,
JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.
Difference between AWT and Swing
No. Java AWT Java Swing
1) AWT components are platform-dependent. 85
Java swing components are platform-independent.

2) AWT components are heavyweight. Swing components are lightweight.

3) AWT doesn't support pluggable look and Swing supports pluggable look and feel.
feel.
4) AWT provides less components than Swing. Swing provides more powerful components such
as tables, lists, scrollpanes, colorchooser,
tabbedpane etc.
5) AWT doesn't follows MVC(Model View Swing follows MVC.
Controller) where model represents data, view
represents presentation and controller acts as
an interface between model and view.
Login Page Project Using Netbeans (Jframe , AWT, Swing)

86
Variable Name: name

Variable Name: pass


getText is used to receive data in entry box and t/f to
variable
87

Calling new file to afterlogin page


Visible is used to show file
Java JDBC 88

JDBC API is a Java API that can access any kind of tabular data, especially data stored
in a Relational Database. JDBC works with Java on a variety of platforms, such as
Windows, Mac OS, and the various versions of UNIX.
Why to Learn JDBC? 89

JDBC stands for Java Database Connectivity, which is a standard Java API for
database-independent connectivity between the Java programming language and a
wide range of databases.

The JDBC library includes APIs for each of the tasks mentioned below that are
commonly associated with database usage.

•Making a connection to a database.


•Creating SQL or MySQL statements.
•Executing SQL or MySQL queries in the database.
•Viewing & Modifying the resulting records.
Applications of JDBC 90

Fundamentally, JDBC is a specification that provides a complete set of


interfaces that allows for portable access to an underlying database. Java
can be used to write different types of executables, such as −
•Java Applications
•Java Applets
•Java Servlets
•Java Server Pages (JSPs)
•Enterprise JavaBeans (EJBs).
Java Database Connectivity with MySQL 91

To connect Java application with the MySQL database, we need to follow 5 following
steps.
In this example we are using MySql as the database. So we need to know following
informations for the mysql database:
1.Driver class: The driver class for the mysql database is com.mysql.jdbc.Driver.
2.Connection URL: The connection URL for the mysql database
is jdbc:mysql://localhost:3306/sonoo where jdbc is the API, mysql is the database,
localhost is the server name on which mysql is running, we may also use IP address,
3306 is the port number and sonoo is the database name. We may use any database,
in such case, we need to replace the sonoo with our database name.
3.Username: The default username for the mysql database is root.
4.Password: It is the password given by the user at the time of installing the mysql
1.import java.sql.*;
2.class MysqlCon{
3.public static void main(String args[]){
4.try{
92
5.Class.forName("com.mysql.jdbc.Driver");
6.Connection con=DriverManager.getConnection(
7."jdbc:mysql://localhost:3306/sonoo","root","root");
8.//here sonoo is database name, root is username and password
9.Statement stmt=con.createStatement();
10.ResultSet rs=stmt.executeQuery("select * from emp");
11.while(rs.next())
12.System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
13.con.close();
14.}catch(Exception e){ System.out.println(e);}
15.}
16.}

You might also like