Beruflich Dokumente
Kultur Dokumente
.org
1. Writing code,
2. Compiling it into bytecode
3. Running the bytecode.
// c is dynamically initialized
double c = a * a + b * b;
C) Constants are the values which do not change during the lifetime of
the program.
System.out.println(FEET_PER_YARD);
System.out.println(MM_PER_INCH);
2. An application can have many classes and only one of the classes
needs to have the method main.
3. This method allows the class containing it to be invoked.
class CommandLine {
public static void main(String args[]) {
for (int i = 0; i < args.length; i++)
System.out.println("args[" + i + "]: " + args[i]);
}
}
Java has eight primitive types of data: byte, short, int, long, char, float,
double, and boolean.
byte
byte b, c;
int
long
Sample Program
public class ClassInitializer1 {
static boolean bool;
static byte by;
static char ch;
static double d;
static float f;
static int i;
static long l;
1. Unary operators
2. Arithmetic operators
3. Relational and conditional operators
4. Shift and logical operators
5. Assignment operators
6. Other operators
Operator
Operator Precedence Group Associativity
Precedence
(), [], postfix ++, postfix -- left Highest
unary +, unary -, prefix ++, prefix --, ~,
right
!
(type), new left
*, /, % left
+, - left
<<, >>, >>> left
< ,<= , >, >=, instanceof
==, !=
& left
^ left
| left
&& left
|| left
?: left
=, +=, -=, *=, /=, %=, <<=, >>=, >>>=,
right lowest
&=, |=, ^=
x = y + 1; z = y + 2;
if (booleanExpression) {
statement (s)
}
or
if (booleanExpression) {
statement (s)
} else {
statement (s)
}
// statements
} else {
// statements
}
}
switch (choice) {
case 1:
System.out.println("Choice 1 selected");
break;
case 2:
System.out.println("Choice 2 selected");
break;
case 3:
System.out.println("Choice 3 selected");
break;
default:
System.out.println("Default");
break;
}
}
}
H) Loops in Java
while (booleanExpression) {
statement (s)
}
For loop
Syntax
For( initializer; condition; increment/decrement)