Java PPT-1 by Adi
Java PPT-1 by Adi
Unit-1
Dr. K ADISESHA
Java Tutorial 2
Introduction
Java Platforms
Features of Java
Java program
Prof. K. Adisesha
3
Introduction
Introduction:
Java is a general-purpose programming language intended to let programmers write
once, run anywhere (WORA). This means that compiled Java code can run on all
platforms that support Java without the need to recompile.
➢ Java is popular high-level, class-based object oriented programming language
originally developed by Sun Microsystems and released in 1995.
❖ Java is Open Source which means its available free of cost.
❖ Java is simple and so easy to learn
❖ Java is much in demand and ensures high salary
❖ Java has a large vibrant community
❖ Java has powerful development tools
❖ Java is platform independent
Prof. K. Adisesha
4
Introduction
History of Java:
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991. The small team of sun engineers called Green Team.
➢ Initially it was designed for small, embedded systems in electronic appliances like set-top
boxes.
➢ Firstly, it was called "Greentalk" by James Gosling, and the file extension was .gt.
➢ After that, it was called Oak and was developed as a part of the Green project.
➢ In 1995, Oak was renamed as "Java" because it was already a trademark by Oak
Technologies.
➢ Initially developed by James Gosling at Sun Microsystems (which is now a subsidiary of
Oracle Corporation) and released in 1995.
Prof. K. Adisesha
5
Introduction
History of Java:
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991. The small team of sun engineers called Green Team.
➢ Many java versions have been released till now: JDK Alpha and Beta (1995), JDK 1.0( 1996) to
Java SE 18 (to be released by March 2022)
➢ Popular Java Editors :To write your Java programs, you will need a text editor. There
are even more sophisticated IDEs available in the market.
❖ Notepad − On Windows machine, you can use any simple text editor like Notepad
(Recommended for this tutorial).
❖ Netbeans − A Java IDE that is open-source and free which can be downloaded from
https://www.netbeans.org/index.html.
❖ Eclipse − A Java IDE developed by the eclipse open-source community and can be
Prof. K. Adisesha
downloaded from https://www.eclipse.org/.
6
Introduction
Application:
According to Sun, 3 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, javatpoint.com, etc.
❖ Enterprise Applications such as banking applications.
❖ Mobile
❖ Embedded System
❖ Smart Card
❖ Robotics
❖ Games, etc.
Prof. K. Adisesha
7
Introduction
Features of Java:
The primary objective of Java programming language creation was to make it portable,
simple and secure programming language.
➢ Simple
➢ Object-Oriented
➢ Portable
➢ Platform independent
➢ Secured
➢ Robust
➢ Architecture neutral
➢ Interpreted
➢ Multithreaded
➢Prof.Distributed
K. Adisesha
9
Introduction
Features of Java:
The primary objective of Java programming language creation was to make it portable,
simple and secure programming language.
➢ Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on
the Object model.
➢ Platform Independent − When Java is compiled, it is not compiled into platform specific machine,
rather into platform independent byte code.
➢ Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it
would be easy to master.
➢ Secure − With Java's secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-key encryption.
➢ Architecture-neutral − Java compiler generates an architecture-neutral object file format, which
makes the compiled code executable on many processors, with the presence of Java runtime system.
Prof. K. Adisesha
10
Introduction
Features of Java:
The primary objective of Java programming language creation was to make it portable,
simple and secure programming language.
➢ Portable − Being architecture-neutral and having no implementation dependent aspects of the
specification makes Java portable.
➢ Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on
compile time error checking and runtime checking.
➢ Multithreaded − With Java's multithreaded feature it is possible to write programs that can
perform many tasks simultaneously.
➢ High Performance − With the use of Just-In-Time compilers, Java enables high performance.
➢ Distributed − Java is designed for the distributed environment of the internet.
➢ Dynamic − Java programs can carry extensive amount of run-time information that can be used
to verify and resolve accesses to objects on run-time.
Prof. K. Adisesha
11
Introduction
C++ vs Java:
C++ Java
• C++ is platform-dependent. • Java is platform-independent.
• C++ is mainly used for system programming. • It is widely used in Windows-based, web-based,
enterprise, and mobile applications.
• C++ supports multiple inheritance. • It can be achieved by using interfaces in java.
• C++ supports goto statement, Pointers, operator • Java doesn't supports goto statement, Pointers,
overloading. operator overloading.
• C++ supports both call by value and call by • Java supports call by value only. There is no call
reference. by reference in java.
Dr. K ADISESHA
14
Introduction
Java Architecture:
Java Architecture combines the process of compilation and interpretation.
➢ In Java, there is a process of compilation and interpretation.
➢ The code written in Java, is converted into byte codes which is done by the Java Compiler.
➢ The byte codes, then are converted into machine code by the JVM.
➢ The Machine code is executed directly by the machine.
Prof. K. Adisesha
15
Java program
Java Program:
To create a simple Java program, you need to create a class that contains the main
method.
➢ For executing any Java program, the following software or application must be
properly installed.
➢ Install the JDK if you don't have installed it, download the JDK and install it.
➢ Set path of the jdk/bin directory.
class Simple{
➢ Create the Java program public static void main(String args[])
➢ Compile and run the Java program {
❖ To compile: javac Simple.java System.out.println("Hello Java");
}
❖ To execute: java Simple }
Prof. K. Adisesha
16
Java program
Basic Syntax:
Java program, can be defined as a collection of objects that communicate via invoking
each other's methods.
➢ It is very important to keep in mind the following points.
❖ Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would have
different meaning in Java.
❖ Class Names − For all class names the first letter should be in Upper Case. If several words
are used to form a name of the class, each inner word's first letter should be in Upper Case.
Example: class MyFirstJavaClass
❖ Method Names − All method names should start with a Lower Case letter. If several words
are used to form the name of the method, then each inner word's first letter should be in
Upper Case. Example: public void myMethodName()
❖ Program File Name − Name of the program file should exactly match the class name.
Prof. K. Adisesha
17
Java program
Basic Syntax:
Java program, can be defined as a collection of objects that communicate via invoking
each other's methods.
Prof. K. Adisesha
18
Java program
Java I/O (Input and 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.
➢ 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.
➢ 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.
➢ In Java, 3 streams are created for us automatically. All these streams are attached
with the console.
❖ System.out: standard output stream
❖ System.in: standard input stream
❖ System.err: standard error stream
Prof. K. Adisesha
19
Java program
Java Identifiers:
All Java components require names. Names used for classes, variables, and methods
are called identifiers.
➢ In Java, there are several points to remember about identifiers. They are as follows −
❖ All identifiers should begin with a letter (A to Z or a to z), currency character ($)
or an underscore (_).
❖ After the first character, identifiers can have any combination of characters.
❖ A key word cannot be used as an identifier.
❖ Most importantly, identifiers are case sensitive.
❖ Examples of legal identifiers: age, $salary, _value, __1_value.
❖ Examples of illegal identifiers: 123abc, -salary.
Prof. K. Adisesha
20
Java program
Java Variables:
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:
public class A
❖ local variable : A variable declared inside the body of the { static int m=100; //static variable
method is called local variable. void method()
❖ instance variable: A variable declared inside the class but {
int n=90; //local variable
outside the body of the method, is called an instance variable. }
❖ static variable : A variable that is declared as static is called public static void main(String args[])
a static variable. It cannot be local. You can create a single {
copy of the static variable and share it among all the int data=50; //instance variable
instances of the class. }
Prof. K. Adisesha } //end of class
21
Java program
Prof. K. Adisesha
22
Java program
char 16 bit, Unicode Unicode character, \u0000 to \uFFFF Can mix with integer types
Prof. K. Adisesha
23
Java program
Operators in Java:
Operator Type Category Precedence
Operator in Java is a symbol that isUnary
used to perform
postfix
operations. expr++ expr--
➢ Types of operators in Java: prefix ++expr --expr +expr -expr ~ !
❖ Unary Operator, Arithmetic multiplicative */%
Java - Arrays:
Java provides a data structure, the array, which is used to store a collection of
sequential collection of elements of the same type.
➢ Declaring Array Variables: ➢ Example:
dataType[] arrayRefVar; // preferred way. double[] myList; // preferred way.
or or
dataType arrayRefVar[]; // works but not preferred way. double myList[]; // works but not preferred way.
➢ Creating Arrays ➢ Example:
arrayRefVar = new dataType[arraySize]; double[] myList = new double[10];
dataType[] arrayRefVar = new dataType[arraySize]; or
dataType[] arrayRefVar = {value0, value1, ..., valuek}; double[] myList = {1.9, 2.9, 3.4, 3.5};
dataType[][] arrayRefVar = new dataType[Size][Size]; or
Prof. K. Adisesha
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
30
Java program
Queries ?
Prof. K. Adisesha
9449081542