Java - Notes Store

mobdescriptiveSoftware and s/w Development

Oct 28, 2013 (3 years and 9 months ago)

89 views



Why Java?

2

The answer is that Java enables users to develop and deploy
applications on
the;


Internet
for servers,


desktop
computers,


and
small hand
-
held 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 a general purpose programming language.


Java is the Internet programming language.

Java, Web, and Beyond


Java can be used to develop Web
applications/Java
Applets.



Java Servlets



Java can also be used to develop applications for
hand
-
held devices such as Palm and cell
phones.

3

Examples of Java’s Versatility (Applets)

4

PDA and Cell Phone

5

Java’s History


Java

is a programming language originally
developed by James Gosling at Sun
Microsystems


The language was initially called
Oak

after an oak
tree that stood outside Gosling's office


Java released on May 20, 1995 as a core
component of Sun Microsystems' Java platform.


Hot Java


The first Java
-
enabled Web
browser

6

Principles


There were five primary goals in the creation of the
Java language:


It should be "simple and familiar"


It should be "robust and secure"


It should be "architecture
-
neutral and portable"


It should execute with "high performance"


It should be “multithreaded, and dynamic"


JDK(Java development Kit)
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



8

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
Server Pages
.


Java Micro Edition (J2ME).


J2ME can be used to develop applications for mobile devices
such as cell phones.

9

Popular Java IDEs


Net
-
Beans
Open Source by Sun


Eclipse Open Source by IBM

10

Syntax of Java


The syntax of Java, combines the syntax for structured and
object
-
oriented programming.


Java was built almost exclusively as an object
-
oriented
language.


All code is written inside a class, and everything is an object.


A Simple Java Program



12

Program
1


// This program prints welcome to java!

Public class Welcome


{


public static void main (strings [] args)



{



System.out.println (“Welcome to Java!”);



}


}


Creating, Compiling, and Running Programs

13

Trace a Program Execution

14

//This program prints Welcome to Java!

public class Welcome {



public static void main(String[] args) {


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


}

}

Enter main method

Trace a Program Execution

15

//This program prints Welcome to Java!

public class Welcome {



public static void main(String[] args) {


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


}

}

Execute statement

Trace a Program Execution

16

//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


Anatomy of a Java Program


Comments


Key/Reserved
words


Modifiers


Statements


Blocks


Methods


The main method

18

Comments


Java uses commenting methods. There are
three different styles of comments:



Single line
style marked with two slashes (//),


Multiple line
style opened with /* and closed
with */,



Comments cont’d

Reserved/Key
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.

Public class Welcome


21

Java Reserved/Key words

Modifiers

Java uses certain reserved words called modifiers
that specify the properties of the data, methods,
and classes and how they can be used.

Examples
of modifiers are
public and static
.

A
public
data, method or
class can be accessed by other
programs.

A
private
data
or method cannot be accessed by other
programs.



Public class Welcome


Other modifiers are private, final, abstract, and
protected.

23

Statements

A statement represents an action or a sequence of
actions.

Complete sentence that causes some action to occur
and ends with a semicolon (
;
)


int

k;


int

j = 10;


double d1, d2, d3;


k = a + b


10;


boolean p = (a >= b);


System.out.println(“go”);


sqareRootTwo = Math.sqrt(2);



block of statements are the statements within a block of curly braces ({ … })


24

Methods

What is System.out.println? It is a method:


A collection of statements that performs a sequence of
operations to display a message on the console



It
is used by invoking a statement with a string argument.
The string argument is enclosed within parentheses.


In
this case, the argument is

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


You
can call
this “println method”
with a different
argument to print a different message.

25

main Method

The main method provides the control of program
flow. The Java interpreter executes the application by
invoking the main method.



The main method looks like this:



public static void main(String
[ ]
args
)


{



//
Statements;


}

26

Blocks

27

A
pair of braces in a program
forms a block that
groups components of a program.


28

Naming Conventions


Choose

meaningful

and

descriptive

names
.


Variables

and

method

names
:



Use
lowercase.



If
the name consists of several words,
concatenate

all in one,


use
lowercase for the first word, and capitalize
the first letter of each subsequent word in the
name.


For
example, the variables
radius

and
area
,
and the method
computeArea
.

29

Naming Conventions, cont.


Class

names
:



Capitalize the first letter of each word in the name.


For
example, the class name
ComputeArea
.


For compound words use camelCcase



Constants
:



Capitalize all letters in constants, and use
underscores to connect words.


For
example, the constant
PI

and

MAX_VALUE

Escape Sequences


An
escape sequence
is a
special character
sequence

that represents another character.



Each of these special character sequences
starts with a backslash, which is followed by
another character.



Characteristics of Java


Java Is Simple



Java
Is Robust



Java Is Secure



Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


32

Java is partially modeled on C++, but greatly
simplified and improved. Some people refer to
Java as "C++
--
" because it is like C++ but with
more functionality and fewer negative aspects
.

Characteristics of Java


Java Is Simple


Java
Is Robust



Java Is Secure



Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


33

Java compilers can detect many problems
that would first show up at execution time
in other languages.


Java has eliminated certain types of error
-
prone programming constructs found in
other languages.


Java has a runtime exception
-
handling
feature to provide programming support
for robustness.

Characteristics of Java


Java Is Simple


Java
Is Robust



Java Is Secure



Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


34

Java implements several security
mechanisms to protect your system
against harm caused by stray programs.

Characteristics of Java


Java Is Simple


Java
Is Robust



Java Is Secure


Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


35

Write once, run anywhere


With a Java Virtual Machine (JVM),
you can write one program that will
run on any platform
.

Characteristics of Java


Java Is Simple


Java
Is Robust



Java Is Secure


Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


36

Because Java is architecture neutral,
Java programs are portable. They can
be run on any platform without being
recompiled.

Characteristics of Java


Java Is Simple


Java
Is Robust



Java Is Secure


Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


37

Java

s performance Because Java is
architecture neutral, Java programs are
portable. They can be run on any
platform without being recompiled.

Characteristics of Java


Java Is Simple


Java
Is Robust



Java Is Secure


Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


38

Multithread programming is smoothly
integrated in Java, whereas in other
languages you have to call procedures
specific to the operating system to enable
multithreading.

Characteristics of Java


Java Is Simple


Java
Is Robust



Java Is Secure


Java Is Architecture
-
Neutral



Java Is Portable



Java's Performance



Java Is Multithreaded



Java Is Dynamic


39

Java was designed to adapt to an evolving
environment. New code can be loaded on the
fly without recompilation. There is no need for
developers to create, and for users to install,
major new software versions. New features can
be incorporated transparently as needed.