What Is Java? Getting Started With Java Programming: - Create, Compile and Running A Java Application
What Is Java? Getting Started With Java Programming: - Create, Compile and Running A Java Application
and Forte
What Is Java?
Getting Started With Java Programming
What Is Java?
History
Characteristics of Java
History
Oak
HotJava
The first Java-enabled Web browser
JDK Evolutions
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
Javas performance
Java is multithreaded
Java is dynamic
JDK Versions
JDK Editions
WebGain Caf
Java Application
Compiling
Programs
Executing Applications
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
package chapter1;
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Source
Run
NOTE: To run the program,
install slide files on hard
disk.
On command line
javac file.java
Source Code
Bytecode
Run Byteode
i.e. java Welcome
Result
10
Executing Applications
On command line
java classname
Bytecode
Java
Interpreter
on Windows
Java
Interpreter
on Linux
...
Java
Interpreter
on Sun Solaris
11
Example
javac Welcome.java
java Welcome
output:...
12
c:\example
chapter1
Welcome.class
Welcome.java~
.
.
.
chapter2
chapter19
13
14
Comments
InJava,commentsareprecededby
twoslashes(//)inaline,or
enclosedbetween/*and*/inone
ormultiplelines.Whenthe
compilersees//,itignoresall
textafter//inthesameline.
Whenitsees/*,itscansforthe
next*/andignoresanytext
between/*and*/.
15
Package
The second line in the program
(package chapter1;) specifies a package
name, chapter1, for the class Welcome.
Forte compiles the source code in
Welcome.java, generates
Welcome.class, and stores
Welcome.class in the chapter1 folder.
16
Reserved Words
Reservedwordsorkeywordsarewords
thathaveaspecificmeaningtothe
compilerandcannotbeusedforother
purposesintheprogram.Forexample,
whenthecompilerseestheword
class,itunderstandsthattheword
afterclassisthenameforthe
class.Otherreservedwordsin
Example1.1arepublic,static,and
void.Theirusewillbeintroduced
laterinthebook.
17
Modifiers
Statements
Astatementrepresentsanaction
orasequenceofactions.The
statement
System.out.println("Welcometo
Java!")intheprogramin
Example1.1isastatementto
displaythegreeting"Welcometo
Java!"EverystatementinJava
endswithasemicolon(;).
19
Blocks
Apairofbracesinaprogram
formsablockthatgroups
componentsofaprogram.
public class Test {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Class block
Method block
20
Classes
TheclassistheessentialJava
construct.Aclassisatemplateor
blueprintforobjects.Toprogramin
Java,youmustunderstandclasses
andbeabletowriteandusethem.
Themysteryoftheclasswill
continuetobeunveiledthroughout
thisbook.Fornow,though,
understandthataprogramisdefined
byusingoneormoreclasses.
21
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 can be used even without
fully understanding the details of how it
works. It is used by invoking a statement
with a string argument. The string argument
is enclosed within parentheses. In this case,
the argument is "Welcome to Java!" You can
call the same println method with a different
argument to print a different message.
22
main Method
Themainmethodprovidesthecontrol
ofprogramflow.TheJavainterpreter
executestheapplicationbyinvoking
themainmethod.
Themainmethodlookslikethis:
publicstaticvoidmain(String[]
args){
//Statements;
}
23
Run
24
25