package demo; // Must be the first row!
import demo.ClassName;
public class process extends Object {
public static void main(String[] args) {
System.out.println("Hello, This is Java!");
System.out.println("-----------------------------------------------");
// if sentence
boolean condition = true;
if (condition) {
System.out.println("This is if sentence! The condition is true");
System.out
.println("-----------------------------------------------");
} else if (condition) {
System.out
.println("This is if sentence! The condition is another true");
System.out
.println("-----------------------------------------------");
} else {
System.out.println("This is if sentence! The condition is false");
System.out
.println("-----------------------------------------------");
}
// max = (a>b)?a:b
int a = 2;
int b = 1;
int max = (a > b) ? a : b;
System.out.println("This is max=(a>b)?a:b! Now, max is" + max);
System.out.println("-----------------------------------------------");
// switch sentence
char switch_condition = 'a';
switch (switch_condition) {
case 'a':
System.out.println("This is switch sentence! The case is '"
+ switch_condition + "'");
System.out
.println("-----------------------------------------------");
break;
case 'b':
break;
default:
break;
}
// while sentence
int while_condition = 5;
while (while_condition > 0) {
while_condition--;
if (while_condition != 1) {
System.out.println("This is the the continue sentence!");
continue; // Go to the next cycle!
} else {
System.out.println("This is the break sentence!");
break; // Jump out of the cycle!
}
}
System.out.println("End of the while sentence! while_condition is"
+ while_condition + "now.");
System.out.println("-----------------------------------------------");
// do ... while
do {
while_condition++;
} while (while_condition < 5); // While the condition expression is
// true, go on the cycle!
System.out.println("This is do...while sentence! while_condition is"
+ while_condition + "now.");
System.out.println("-----------------------------------------------");
// for sentence
for (int for_condition = 0; for_condition < 5; for_condition++) {
System.out.println("This is for sentence! for_condition is"
+ for_condition + "now.");
}
System.out.println("-----------------------------------------------");
try{
throw new Error("try...catch(error)...");
}
catch(Error ee){
System.out.println(ee.getMessage());
}
finally{
System.out.println("Finally!");
}
}
void array_about() {
int[] array_int;
array_int = new int[10]; // Array must be initialed!
array_int[0] = 1;
int array_int_2[];
array_int_2 = new int[10];
char[] array_char = { 'a', 'b', 'c' };
}
}
class class_about extends process {
demo.ClassName cn = new demo.ClassName();
void array_about() {
System.out.println("Overwrite the array_about method!");
super.array_about(); // process.array_about()
}
}
abstract class abstract_class_about {
// Only statement in the abstract class!
int i;
abstract void abstract_method();
void abstract_method_2() {
// ...
}
}
interface interface_about {
final int i = 1; // Must be final! Must be initial!
abstract void interface_abstract_method(); // Must be abstract!
}