KEMBAR78
Introduction PDF | PDF | Java (Programming Language) | Object Oriented Programming
0% found this document useful (0 votes)
14 views45 pages

Introduction PDF

The document provides an introduction to Java programming, detailing the different editions of the Java Development Kit (JDK) including J2SE, J2EE, and J2ME, and their respective applications. It covers the structure of a simple Java program, key programming concepts such as classes, methods, statements, and the importance of proper programming style and documentation. Additionally, it highlights Java's characteristics, history, and the evolution of JDK versions.

Uploaded by

Rayyan Mostapha
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)
14 views45 pages

Introduction PDF

The document provides an introduction to Java programming, detailing the different editions of the Java Development Kit (JDK) including J2SE, J2EE, and J2ME, and their respective applications. It covers the structure of a simple Java program, key programming concepts such as classes, methods, statements, and the importance of proper programming style and documentation. Additionally, it highlights Java's characteristics, history, and the evolution of JDK versions.

Uploaded by

Rayyan Mostapha
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/ 45

Introduction to Java

Ali Choumane

Original slides by Daniel Liang:


Introduction to Java Programming, 10th edition

1
Java Development Kit (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.

In this course we use J2SE to introduce OOP with


Java
2
Popular Java IDEs

NetBeans
Eclipse
IntelliJ

3
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!");
}
}

4
Creating and Editing Using NotePad

5
Creating, Compiling, and Running
Programs

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

7
Anatomy of a Java Program

Class name
Main method
Statements
Statement terminator
Reserved words
Comments
Blocks

8
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!");
}
}

9
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!");
}
}

10
Statement
A statement represents an action or a sequence of
actions. The statement System.out.println("Welcome to
Java!") 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!");
}
}

11
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!");
}
}

12
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!");
}
}

13
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
}
}

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

15
{ …}

// This program prints Welcome to Java!


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

// This program prints Welcome to Java!


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

// This program prints Welcome to Java!


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

// This program prints Welcome to Java!


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

// This program prints Welcome to Java!


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

Appropriate Comments
Naming Conventions
Proper Indentation and Spacing Lines
Block Styles

21
Appropriate Comments

Include a summary at the beginning of the program to explain what the


program does, its key features, its supporting data structures, and any
unique techniques it uses.

Include your name, class section, instructor, date, and a brief description at
the beginning of the program.

22
Naming Conventions
Choose meaningful and descriptive names.
Class names:
• Capitalize the first letter of each word in the name. For example, the class
name ComputeExpression.

23
Proper Indentation and Spacing
Indentation
• Indent with one tab.

Spacing
• Use blank line to separate segments of the code.

24
Block Styles
Use end-of-line style for braces.

Next-line public class Test


style {
public static void main(String[] args)
{
System.out.println("Block Styles");
}
}

End-of-line
style
public class Test {
public static void main(String[] args) {
System.out.println("Block Styles");
}
}

25
Programming Errors
Syntax Errors
• Detected by the compiler
Runtime Errors
• Causes the program to abort
Logic Errors
• Produces incorrect result

26
Syntax Errors
public class ShowSyntaxErrors {
public static main(String[] args) {
System.out.println("Welcome to Java);
}
}

27
Runtime Errors

public class ShowRuntimeErrors {


public static void main(String[] args) {
System.out.println(1 / 0);
}
}

28
Logic Errors

public class ShowLogicErrors {


public static void main(String[] args) {
System.out.print("Celsius 35 is ");
System.out.print("Fahrenheit ");
System.out.println((9 / 5) * (35 + 32));
}
}

29
Why Java?
Java can be used to develop standalone
applications.
Java can be used to develop applications
running from a browser.
Java can also be used to develop applications
for hand-held devices.
Java can be used to develop applications for
Web servers.

30
Java’s History
The “Green Team” (James Gosling, Mike Sheridan, and Patrick Naughton) at
“Sun Microsystems” initiated the Java language project in 1991

Firstly, it was called "Greentalk"


After that, it was called Oak
Finally named Java in 1995
Java is an island of Indonesia where the first coffee was produced. Java name was
chosen by James Gosling while having coffee near his office.
Sun Microsystems acquired by Oracle in 2010 ($7.4B)

31
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

32
Characteristics of Java
Java Is Simple Java is partially modeled on C++, but greatly
simplified and improved. Some people refer to
Java Is Object-Oriented
Java as "C++--" because it is like C++ but
Java Is Distributed with more functionality and fewer negative
Java Is Interpreted aspects.

Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic

33
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
Java Is Interpreted object-oriented. Object-oriented
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
Java's Performance development is how to reuse code. Object-
oriented programming provides great
Java Is Multithreaded flexibility, modularity, clarity, and
Java Is Dynamic reusability through encapsulation,
inheritance, and polymorphism.

34
Characteristics of Java
Java Is Simple Distributed computing involves several
computers working together on a network.
Java Is Object-Oriented
Java is designed to make distributed
Java Is Distributed computing easy. Since networking
Java Is Interpreted capability is inherently integrated into
Java, writing network programs is like
Java Is Robust sending and receiving data to and from a
Java Is Secure file.
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic

35
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-
Java Is Interpreted independent and can run on any machine
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

36
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 Is Interpreted Java has eliminated certain types of error-
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

37
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 against
Java Is Secure harm caused by stray programs.
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic

38
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

39
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's Performance Java programs are portable. They can
be run on any platform without being
Java Is Multithreaded recompiled.
Java Is Dynamic

40
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
Java's Performance architecture neutral, Java programs are
portable. They can be run on any
Java Is Multithreaded platform without being recompiled.
Java Is Dynamic

41
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.
42
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
Java Is Dynamic developers to create, and for users to install,
major new software versions. New features can
be incorporated transparently as needed.
43
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
….

44
IDE for our course

• Download JDK 8u111 with NetBeans 8.2


• https://www.oracle.com/technetwork/java/javase/downloads/jdk-
netbeans-jsp-3413139-esa.html

45

You might also like