01 Slide
01 Slide
Welcome Back!!!
[email protected]
[email protected]
• Chapter 1
– Course Objectives
– Organization of the Book
• History
• Characteristics of Java
Environment
java
Java Source code javac Java byte-code Java VM
.java .class
loaded
Java interpreted
classes
Runtime
(byte-codes)
call
Native Native
.dll .dll
Liang, Oreilly, Herbert Schildt, Joseph O’Neil
Advantages
• Byte-code is a compact machine
language form. In Java the target
machine is the Java Virtual Machine
(VM).
• These byte-codes are thus portable
across architecture boundaries.
• Applets and Applications have “class”
files loaded on their behalf in order to
execute.
Liang, Oreilly, Herbert Schildt, Joseph O’Neil
JDK Versions
Source Run
Source Code
• On command line
– javac file.java
Compile Source Code
i.e. javac Welcome.java
If compilation errors
Bytecode
Run Byteode
i.e. java Welcome
Result
Bytecode
javac Welcome.java
java Welcome
output:...
Welcome.java
c:\example Where are the files
chapter1 Welcome.class stored in the
Welcome.java~
directory?
.
.
.
chapter19 Java source files and class files for Chapter 19
End-of-line
style
public class Test {
public static void main(String[] args) {
System.out.println("Block Styles");
}
}
Source Run
JOptionPane.showMessageDialog(null, "Welcome
to Java!",
"Example 1.2",
JOptionPane.INFORMATION_MESSAGE));
/*
<applet code="FirstApplet" width=200 height=200>
</applet>
*/
int x = 25;
Liang, Oreilly, Herbert Schildt, Joseph O’Neil
Boolean Literals
• The only literals of boolean type are
true and false.
For example:
For example:
• BIGinterface // legal
• $incomeAfterExpenses // legal
• 3_nodes5 // illegal
• !theCase // illegal
Liang, Oreilly, Herbert Schildt, Joseph O’Neil
Using Keyword
• Using a keyword as an
identifier is a syntax error
v byte
v short
v int
v long
• Example
Number 74
before bitwise NOT -> 01001010
after the NOT operator applied -> 10110101
Liang, Oreilly, Herbert Schildt, Joseph O’Neil
Bitwise AND ( & )
• Produces a 1 bit if both operands are also
1, otherwise a zero is produced.
Example
Number 74 & 29 -> 8
-> 01001010
-> & 00011101
After -> 0 0 0 0 1 000
Operator Name
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
Operand !Operand
true false
false true
Operand1Operand2Operand1 &&
Operand2
false false false
false true false
true false false
true true true
Liang, Oreilly, Herbert Schildt, Joseph O’Neil
Truth Table for Operator ||
Operand1 Operand2 Operand1 ||
Operand2
false false false
false true true
true false true
true true true
double doubleValue
=Double.parseDouble(doubleString);
• while Loops
• do-while Loops
• for Loops
• break and continue
// Display variables
display(i, j, sb);
// call method
a(i, j, sb);
predictRaise(mySalary);
System.out.println("Demonstrating my salary " + mySalary);
predictRaise(400.00);
predictRaiseGivenIncrease(600, 800);
}