Lecture 2





Lecture Topic:
Java code basics, data types and flow
of control
Sample Quiz
Code-warrior:
Pascal
|
C
|
C++
|
MFC
|
IDE
|
Java
|
- Group 1:
- TrivialApp (Edit, Save, Compile, Run)
Appleframe.java
Classes.zip
SUN JDK Sparc 5 Solaris
IBM
- Commands:
- ls *.html
foo<html>html ( for keeping the original html file)
- Example of Java program code:
- // ExampleJavaApp.java
- class ExampleJavaApp {
- public static void main (String args[ ]) {
int x; // a value must be put into a variable before you can do anything
with the variable
x = x + 1; // illegal - x has not yet been initialized
System.out.println("Hello form Java!");
}
- }
in C or C++:
#include<stdio.h>
in Java:
import java.io.*;
Common in C or C++:
/* common */
// common
Common in Java:
// a single line common
/* common example */
/* A multiple line
common example
*/
Common in Java DOC:
/** common in java.doc*/
java.doc<foo.java>foo.html
Named Constants:
static final ID // in Java
#define PI 3.14 // in C, C++
Example:
class Wow {
static final double PI = 3.14159265358979323846
}
Characters:
Character type are
defined 16-bit unsigned unique code values.
Char theChar = 'a';
it is possible to assign a numeric literal
to a character typed variable and a character literal to an integer variable:
char theChar = 48;
integer theValue = 'a';
Data declaration:
type-name <follow by> variable-name
Symbol
|
meaning
|
D
|
the
|
A
|
boy
|
V
|
likes
|
N
|
Java
|
N
|
computer
|
NP
|
N
|
if
S
|
->
|
NP
|
,
|
VP
|
NP
|
->
|
D
|
,
|
A
|
VP
|
->
|
V
|
,
|
NP
|
( "," means followed by)
Then
S: the boy likes computer. Or S: the
boy likes Java.
VD (variables declaration ) [modifies]
type-name, variable( = initializes );
Public and Private:
public
private int i = 10;
private double[ ] foo;
public Integer[ ] foo = new Integer(100); // Integer
is a class name
Flow of Control
Selection statement:
If expression:
expression if_true;
expression if_false;
Switch expression: // block
{ local_variable_declaration_and_statement }
'a' //OK
"hello" // illegal
LVD: (local_variable_declaration)
type_specification_variable
int i = 10;
statement empty statement;
labeled statement;
expression statement;
jump statement;
synch statement;
iteration statement;
examination statement;
Example
//Use of the Switch / General invokes of Brake
switch (expression) {
case const-1 :
statement_1;
break;
case const_2 :
statement_2;
break;
default:
statement;
break;
}
Sample Quiz
1. Character type are defined 32-bit unsigned
unique code values.
True
False





Last Update: 9/15/96
Copyright © 1996 - Douglas Lyon
Lyon@cse.bridgeport.edu