Wednesday, November 7, 2007

^ -^ Java Exam: Private courses

//HelloDate.java.....This exam is very famous. ^^;

import.java.util.*;
//exam's subject = class'name....
public class HelloDate{
public static void main(String[] args){
System.out.println("Hello, Today?");
System.out.print(new Date()); //Objects produce
System.out.print(".....");
}
}


//operators/Precedence.java

public class Precedence{
public static void main(String[] args){
int x = 1, y = 2, z = 3;
int a = x + y - 2/2 + z;
int b = x + (y - 2)/(2 + z);
System.out.println("a = " + a + " b = " + b);
}
}



//Assignment.java
//import static net.mindview.util.Print.*;
//This error..^^; I don't useing
.

class Tank{
int level;
}

public class Assignment{
public static void main(String[] args){
Tank t1 = new Tank();
Tank t2 = new Tank();
t1.level = 9;
t2.level = 47;

System.out.println("1: t1.level: " + t1.level +
", t2.level: " + t2.level);
t1 = t2;
System.out.println("2: t1.level: " + t1.level +
", t2.level: " + t2.level);
t1.level = 27;
System.out.println("3: t1.level: " + t1.level +
", t2.level: " + t2.level);
}
}



//Relation operateor
public class Equivalence{
public static void main(String[] args){
Integer n1 = new Integer(46);
Integer n2 = new Integer(10);
System.out.println(n1 == n2); ==>boolen(false)
System.out.println(n1 != n2); ==>boolen(true)
}
}


//initializations/SimpleConstructor.java
class Rock{
Rock() { //initializations
System.out.print("Rock");
}
}

public class SimpleConstructor{
public static void main(String[] args){
for(int i = 0; i < 10; i++);
new Rock();
}
}


//OverloadingOrder.java:메소드 오버로딩

public class OverloadingOrder{
static void f(String s, int i)
{
System.out.println("String: " + s + ", int: " + 1);
}
static void f(int i, String s)
{
System.out.println("int: " + i + ",String: " +s);
}
public static void main(String[] args){
f("String first", 11);
f(15, "Int first");
}
}


//initialization/Leaf.java:Using This - This의 리턴문 사용.

public class Leaf{
int i = 0;
Leaf increment(){
i++;
return this;
}
void print(){
System.out.println(" i = " + i);
}
public static void main(String[] args){
Leaf X = new Leaf();
X.increment().increment().increment().print(); //Same method using <.>
}
}


//initialization/PassingThis.jsva - Class passed(This)- 다른 클래스의 메소드로 전달

class Person{
public void eat(Apple apple){
Apple peeled = apple.getPeeled();
System.out.println("Yummy");
}
}

class Peeler{
static Apple peel(Apple apple){
//....remove peel
return apple; //Peeled
}
}

class Apple{
Apple getPeeled(){
return Peeler.peel(this); //used this for pass to another method
}
}

public class PassingThis{
public static void main(String[] args){
new Person().eat(new Apple());
}
}

No comments: