0% found this document useful (0 votes)
9 views

Day 1 Java Introduction

The document provides an introduction to Java, covering its history, characteristics, features, and various JDK versions. It explains Java's object-oriented nature, platform independence, and the process of compiling and executing Java programs. Additionally, it includes basic definitions, examples of simple Java programs, and popular Java IDEs.

Uploaded by

sipesog774
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Day 1 Java Introduction

The document provides an introduction to Java, covering its history, characteristics, features, and various JDK versions. It explains Java's object-oriented nature, platform independence, and the process of compiling and executing Java programs. Additionally, it includes basic definitions, examples of simple Java programs, and popular Java IDEs.

Uploaded by

sipesog774
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Introduction to Java

Day 1

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 1
Vaibhav Diwan
Welcome

• History • Java Processing and Execution


• Characteristics of Java • Compiling and Executing a
• Features of Java Java Program
• JDK Versions • Trace a Program Execution
• JDK Editions • Anatomy of a Java Program
• Popular Java IDEs
• Basic Definitions
• A Simple Java Program
• Creating and Editing Java
Program

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 2
Vaibhav Diwan
Very Brief History

• Started in 1991 by SUN Microsystems


• Targeted at consumer electronics. Wanted
reliable programming language.
• Integrated into browsers
• Evolved into write once run anywhere,
integrates into Netscape
• General purpose libraries released
Java Training for WIPRO TalentNext 2017 -
13-Mar-18 3
Vaibhav Diwan
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 4
Vaibhav Diwan
Characteristics of Java
• Java Is Simple Java is partially modeled on C++, but greatly
simplified and improved. Some people refer
• Java Is Object-Oriented to Java as "C++--" because it is like C++ but
• Java Is Distributed with more functionality and fewer negative
aspects.
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 5
Vaibhav Diwan
Characteristics of Java
• Java Is Simple Java is inherently object-oriented.
Although many object-oriented languages
• Java Is Object-Oriented began strictly as procedural languages,
• Java Is Distributed Java was designed from the start to be
object-oriented. Object-oriented
• Java Is Interpreted
programming (OOP) is a popular
• Java Is Robust programming approach that is replacing
• Java Is Secure traditional procedural programming
techniques.
• Java Is Architecture-Neutral
• Java Is Portable One of the central issues in software
development is how to reuse code.
• Java's Performance Object-oriented programming provides
• Java Is Multithreaded great flexibility, modularity, clarity, and
reusability through encapsulation,
• Java Is Dynamic inheritance, and polymorphism.

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 6
Vaibhav Diwan
Characteristics of Java
• Java Is Simple Distributed computing involves several
computers working together on a
• Java Is Object-Oriented network. Java is designed to make
• Java Is Distributed distributed computing easy. Since
networking capability is inherently
• Java Is Interpreted
integrated into Java, writing network
• Java Is Robust programs is like sending and receiving
• Java Is Secure data to and from a file.

• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 7
Vaibhav Diwan
Characteristics of Java
• Java Is Simple You need an interpreter to run Java
programs. The programs are compiled into
• Java Is Object-Oriented the Java Virtual Machine code called
• Java Is Distributed bytecode. The bytecode is machine-
independent and can run on any machine
• Java Is Interpreted
that has a Java interpreter, which is part of
• Java Is Robust the Java Virtual Machine (JVM).
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 8
Vaibhav Diwan
Characteristics of Java
• Java Is Simple Java compilers can detect many problems
that would first show up at execution time
• Java Is Object-Oriented in other languages.
• Java Is Distributed
Java has eliminated certain types of error-
• Java Is Interpreted
prone programming constructs found in
• Java Is Robust other languages.
• Java Is Secure
Java has a runtime exception-handling
• Java Is Architecture-Neutral feature to provide programming support
• Java Is Portable for robustness.

• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 9
Vaibhav Diwan
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
Java implements several security
• Java Is Robust mechanisms to protect your system
• Java Is Secure against harm caused by stray programs.
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 10
Vaibhav Diwan
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral Write once, run anywhere
• Java Is Portable
With a Java Virtual Machine (JVM),
• Java's Performance you can write one program that will
• Java Is Multithreaded run on any platform.

• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 11
Vaibhav Diwan
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable Because Java is architecture neutral,
Java programs are portable. They can
• Java's Performance
be run on any platform without being
• Java Is Multithreaded recompiled.
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 12
Vaibhav Diwan
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable Java’s performance Because Java is
architecture neutral, Java programs are
• Java's Performance
portable. They can be run on any
• Java Is Multithreaded platform without being recompiled.
• Java Is Dynamic

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 13
Vaibhav Diwan
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
Multithread programming is smoothly
• Java Is Multithreaded integrated in Java, whereas in other
• Java Is Dynamic languages you have to call procedures
specific to the operating system to enable
multithreading.
Java Training for WIPRO TalentNext 2017 -
13-Mar-18 14
Vaibhav Diwan
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance Java was designed to adapt to an evolving
environment. New code can be loaded on the
• Java Is Multithreaded fly without recompilation. There is no need for
developers to create, and for users to install,
• Java Is Dynamic major new software versions. New features can
be incorporated transparently as needed.
Java Training for WIPRO TalentNext 2017 -
13-Mar-18 15
Vaibhav Diwan
Some Salient Features of Java
• Java is platform independent: the same program can run on
any correctly implemented Java system
• Java is object-oriented:
– Structured in terms of classes, which group data with
operations on that data
– Can construct new classes by extending existing ones
• Java designed as
– A core language plus
– A rich collection of commonly available packages
• Java can be embedded in Web pages

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 16
Vaibhav Diwan
JDK Versions
• JDK 1.02 (1995)
• JDK 1.1 (1996)
• JDK 1.2 (1998)
• JDK 1.3 (2000)
• JDK 1.4 (2002)
• JDK 1.5 (2004) a. k. a. JDK 5 or Java 5
• JDK 1.6 (2006) a. k. a. JDK 6 or Java 6
• JDK 1.7 (2011) a. k. a. JDK 7 or Java 7
• JDK 1.8 (2014) a. k. a. JDK 8 or Java 8

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 17
Vaibhav Diwan
JDK Editions
• Java Standard Edition (J2SE)
– J2SE can be used to develop client-side
standalone applications or applets.
• Java Enterprise Edition (J2EE)
– J2EE can be used to develop server-side
applications such as Java servlets, Java
ServerPages, and Java ServerFaces.
• Java Micro Edition (J2ME).
– J2ME can be used to develop applications for
mobile devices such as cell phones.

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 18
Vaibhav Diwan
Popular Java IDEs
• NetBeans
• Eclipse

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 19
Vaibhav Diwan
Basic Definitions

• Java is an object oriented language.


– Object
– Method
– Class
– Applications
– Applets
– Threads
– Exceptions

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 20
Vaibhav Diwan
A Simple Java Program

//This program prints Welcome to Java!


public class Welcome {

public static void main(String[] args) {

System.out.println("Welcome to Java!");
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 21
Vaibhav Diwan
Creating and Editing Java Program
in Windows
• You can use Notepad for creating java
program

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 22
Vaibhav Diwan
Creating and Editing Java Program
in Ubuntu
• You can use “gedit” text editor from Terminal
for creating java program
• You can use the following command:
– gedit Welcome.java
This will start a the text editor and create a file with
filename Welcome.java

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 23
Vaibhav Diwan
Java Processing and Execution

• Begin with Java source code in text files:


Welcome.java
• A Java source code compiler produces Java byte code
– Outputs one file per class: Welcome.class
– May be standalone or part of an IDE
• A Java Virtual Machine loads and executes class files
– May compile them to native code (e.g., x86)
internally

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 24
Vaibhav Diwan
Compiling and Executing a Java
Program

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 25
Vaibhav Diwan
Compiling a Java Program

• In Windows
– Open command prompt
– Goto your directory of java program
– Then use the following command to compile your
code
• javac Welcome.java
–javac ProgramName with extention

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 26
Vaibhav Diwan
Compiling a Java Program

• In Ubuntu
– Open Terminal
– Goto your directory of java program
– Then use the following command to compile your
code
• javac Welcome.java
• javac ProgramName with
extention
Java Training for WIPRO TalentNext 2017 -
13-Mar-18 27
Vaibhav Diwan
Executing a Java Program

• In Windows
– Open command prompt
– Goto your directory of java program
– Then use the following command to compile your
code
• java Welcome
java ProgramName

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 28
Vaibhav Diwan
Executing a Java Program

• In Ubuntu
– Open command prompt
– Goto your directory of java program
– Then use the following command to compile your
code
• java Welcome
java ProgramName

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 29
Vaibhav Diwan
Trace a Program Execution
Enter main method

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 30
Vaibhav Diwan
Trace a Program Execution
Execute statement

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 31
Vaibhav Diwan
Trace a Program Execution

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

print a message to the


console

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 32
Vaibhav Diwan
Anatomy of a Java Program

• Class name
• Main method
• Statements
• Statement terminator
• Reserved words
• Comments
• Blocks

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 33
Vaibhav Diwan
Class Name
Every Java program must have at least one class.
Each class has a name. By convention, class names
start with an uppercase letter. In this example, the
class name is Welcome.

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 34
Vaibhav Diwan
Main Method
Line 2 defines the main method. In order to run a
class, the class must contain a method named
main. The program is executed from the main
method.

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 35
Vaibhav Diwan
Statement
A statement represents an action or a sequence of
actions. The statement System.out.println("Welcome to
Java!") in the program in Listing 1.1 is a statement to
display the greeting "Welcome to Java!“.

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 36
Vaibhav Diwan
Statement Terminator
Every statement in Java ends with a semicolon (;).

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {

System.out.println("Welcome to Java!") ;
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 37
Vaibhav Diwan
Reserved words
Reserved words or keywords are words that have a
specific meaning to the compiler and cannot be used for
other purposes in the program. For example, when the
compiler sees the word class, it understands that the
word after class is the name for the class.

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 38
Vaibhav Diwan
Blocks
A pair of braces in a program forms a block that groups
components of a program.

public class Test {


public static void main(String[] args) { Class block
System.out.println("Welcome to Java!"); Method block
}
}

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 39
Vaibhav Diwan
Special Symbols

Character Name Description

{} Opening and closing Denotes a block to enclose statements.


braces
() Opening and closing Used with methods.
parentheses
[] Opening and closing Denotes an array.
brackets
// Double slashes Precedes a comment line.

" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 40
Vaibhav Diwan
How to install Java

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 41
Vaibhav Diwan
Steps

1. Download Java
2. Install Java
3. Update Path environmental variable
4. Verify Installation

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 42
Vaibhav Diwan
1. Download Java
1. Open your
web browser

2. Type URL:
http://www.orac
le.com/technetw
ork/java/javase/
downloads/index
.html to go to
Oracle download
page

3. Click on button “
JDK download ”
for Java SE
update 4.
This will lead you
JDK download
page
http://www.orac
le.com/technetw
ork/java/javase/
downloads/jdk-
7u4-downloads-
1591156.html

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 43
Vaibhav Diwan
4. Accept oracle
license agreement

5. Find and click on


the correct jdk
download link
right for your
operating system
to download

6. Save the file to


disk

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 44
Vaibhav Diwan
3.Set Path
• After installing the software, the JDK directory will have the structure shown below.

• The bin directory contains both the compiler and the launcher. The path environmental variable should be
updated to include path to bin in PATH variable. This is not mandatory, but highly recommended for convenience.

• It is useful to set the PATH variable permanently so it will persist after rebooting.

• To set the PATH variable permanently, add the full path of the jdk1.7.0\bin directory to the PATH variable. Typically,
this full path looks something like C:\Program Files\Java\jdk1.7.0\bin in Windows o/s.

• Refer: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html to learn how to do this.

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 45
Vaibhav Diwan
• For example, in Windows 7:
REF: http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#Check
1. 2. 3.

4. 5.

Add the location of the bin folder of the JDK


installation for the PATH variable in System
Variables in Environmental variables.

The following is a typical value for the PATH


variable:
C:\WINDOWS\system32;C:\WINDOWS;C:\
Program Files\Java\jdk1.7.0\bin

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 46
Vaibhav Diwan
Verify Installation
• Go to command prompt
and type javac

• It should display javac


usage with options if
installed correctly

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 47
Vaibhav Diwan
Useful Links
• JDK installation for Microsoft Windows:
– http://docs.oracle.com/javase/7/docs/webnotes/i
nstall/windows/jdk-installation-windows.html
• JDK installation for Mac OS X:
– http://docs.oracle.com/javase/7/docs/webnotes/i
nstall/mac/mac-jdk.html
• JDK installation for Linux Platforms:
– http://docs.oracle.com/javase/7/docs/webnotes/i
nstall/linux/linux-jdk.html

Java Training for WIPRO TalentNext 2017 -


13-Mar-18 48
Vaibhav Diwan

You might also like