Introduction to Java Programming
Fundamentals of OOP
Java Features
Constants, Variables, Data types
Operators
Decision Making & Branching
Decision Making & Looping
Type Casting
Why Java?
The answer is that Java enables users to
develop and deploy applications on the Internet
for servers, desktop computers, and small handheld devices. The future of computing is being
profoundly influenced by the Internet, and Java
promises to remain a big part of that future.
Java is the Internet programming language.
Java is a
language.
general
purpose
programming
Java is the Internet programming language.
Java History
James
Gosling and Sun Microsystems
Oak
Java,
May 20, 1995, Sun World
HotJava
The first Java-enabled Web browser
Early
History Website:
http://java.sun.com/features/1998/05/birthday.html
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 (possibly 2010) a. k. a. JDK 7 or Java 7
4
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 and Java
ServerPages.
Java Micro Edition (J2ME)
J2ME can be used to develop applications for
mobile devices such as cell phones.
This book uses J2SE to introduce Java programming.
5
Popular Java IDEs
NetBeans
Eclipse
Open Source by Sun
Open Source by IBM
A Simple Java Program
Listing 1.1
//This program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Welcome
Run
IMPORTANT NOTE: (1) To enable the buttons, you
must download the entire slide file slide.zip and
unzip the files into a directory (e.g., c:\slide) .
(2) You must have installed JDK and set JDKs bin
directory in your environment path
(e.g., c:\Program Files\java\jdk1.6.0_14\bin in your
environment path.
7
Compiling Java Source Code
You can port a source program to any machine with
appropriate compilers.
The source program must be recompiled, however, because
the object program can only run on a specific machine.
Nowadays computers are networked to work together. Java
was designed to run object programs on any platform.
With Java, you write the program once, and compile the
source program into a special type of object code, known
as bytecode.
The bytecode can then run on any computer with a Java
Virtual Machine, as shown below.
Java Virtual Machine is a software that interprets Java
bytecode.
8
Fundamentals of OOP
Object
and Classes
Data abstraction and encapsulation
Inheritance,
Polymorphism
Dynamic Binding
Java Features
Compiled
and Interpreted
Platform independent and portable
Object oriented
Distributed
Multithreaded and interactive
High performance
Java Tokens
Constant,
Variables
Data
Types
Scope of variable
Symbolic Constant,
Standard default values
Operators
Arithmetic
Operators
Relational Operators
Logical Operators
Assignment Operator
Increment and Decrement Operator
Conditional Operator
Bit wise Operator
Special Operator
Decision Making & Branching
1)
2)
3)
if statement
Simple if statement,
if else statement
else if ladder
switch statement
? : Operator
Decision Making & Looping
while
statement
do statement
for statement
Jumps in Loops ( Break ,
Continue)