Exercise :
public class Test {
enum Animal { "CATS", "DOGS", "ELEPHANT"};
public static void main(String [] args) {
Animal myAnimal = Animal.CATS;
if ( myAnimal == Animal.CATS) {
System.out.println("It's a CATS");
} else if (myAnimal.equals(Animal.DOGS)) {
System.out.println("It's a DOGS");
} else {
System.out.println("It's an elephant");
}
}
}
What is the result ? (choose one)
A It's a CATS
B It's a DOGS
C It's an elephant
D Compilation fails
E An exception is thrown at runtime
Solution :
The solution is D.There is an compilation error because the enum syntax is wrong.
It should be : enum Animal { CATS, DOGS, ELEPHANT};
Wednesday, February 10, 2010
SCJP exercise : enum
Wednesday, February 3, 2010
SCJP exercise : enum
Exercise :
Given the following :
public class Test {
enum Animal { CATS, DOGS, ELEPHANT};
public static void main(String [] args) {
Animal myAnimal = Animal.CATS;
if ( myAnimal == Animal.CATS) {
System.out.println("It's a CATS");
} else if (myAnimal.equals(Animal.DOGS)) {
System.out.println("It's a DOGS");
} else {
System.out.println("It's an elephant");
}
}
}
What is the result ? (choose one)
A It's a CATS
B It's a DOGS
C It's an elephant
D Compilation fails
E An exception is thrown at runtime
Solution :
The solution is A.There is no errors.You can use enum with == or with the method equals.
Given the following :
public class Test {
enum Animal { CATS, DOGS, ELEPHANT};
public static void main(String [] args) {
Animal myAnimal = Animal.CATS;
if ( myAnimal == Animal.CATS) {
System.out.println("It's a CATS");
} else if (myAnimal.equals(Animal.DOGS)) {
System.out.println("It's a DOGS");
} else {
System.out.println("It's an elephant");
}
}
}
What is the result ? (choose one)
A It's a CATS
B It's a DOGS
C It's an elephant
D Compilation fails
E An exception is thrown at runtime
Solution :
The solution is A.There is no errors.You can use enum with == or with the method equals.
Wednesday, January 27, 2010
SCJP exercise : operators
Exercise :
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num == 'a') {
System.out.println("Good result !");
} else {
System.out.println("Result:" + num);
}
}
}
What is the result ? (choose one)
A Good result !
B Result:1
C Compilation fails
D An exception is thrown at runtime
Solution :
The result is C.There is no compilation error.You can compare 1 with 'a' because the comparison use the unicode value of a.So it's correct to compare 1 with 'a'.
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num == 'a') {
System.out.println("Good result !");
} else {
System.out.println("Result:" + num);
}
}
}
What is the result ? (choose one)
A Good result !
B Result:1
C Compilation fails
D An exception is thrown at runtime
Solution :
The result is C.There is no compilation error.You can compare 1 with 'a' because the comparison use the unicode value of a.So it's correct to compare 1 with 'a'.
Wednesday, January 20, 2010
SCJP exercise : operators
An other exercise ! The goal is practice and learn commons java certification SCJP questions.
Exercise :
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num = 2) {
System.out.println("Result:" + num);
}
System.out.println("Result:" + num);
}
}
What is the result ? (choose one)
A Result:1
B Result:2
C Compilation fails
D An exception is thrown at runtime
Solution :
The solution is C.In fact we set num to 2 with num=2.
So the result of the setting is an int.Or the if is waiting a boolean so the compilation fails.
Exercise :
Given the following :
public class Test {
public static void main(String [] args) {
int num = 1;
if ( num = 2) {
System.out.println("Result:" + num);
}
System.out.println("Result:" + num);
}
}
What is the result ? (choose one)
A Result:1
B Result:2
C Compilation fails
D An exception is thrown at runtime
Solution :
The solution is C.In fact we set num to 2 with num=2.
So the result of the setting is an int.Or the if is waiting a boolean so the compilation fails.
Thursday, January 7, 2010
Good year
Hi !
This year we will see many things like certification exercise, Java tips, Go langage ...
So it's exiting !
This year we will see many things like certification exercise, Java tips, Go langage ...
So it's exiting !
Friday, December 4, 2009
GWT [ERROR] No source code is available for ...GWTTestCase
Problem :
You have the following error:
[ERROR] Line 11: No source code is available for type com.google.gwt.junit.client.GWTTestCase;
did you forget to inherit a required module?
Solution :
In your module file(*.gwt.xml), simply add :
"< name="com.google.gwt.junit.JUnit">"
You have the following error:
[ERROR] Line 11: No source code is available for type com.google.gwt.junit.client.GWTTestCase;
did you forget to inherit a required module?
Solution :
In your module file(*.gwt.xml), simply add :
"< name="com.google.gwt.junit.JUnit">"
Friday, November 27, 2009
Eclipse GWT_EXTERNAL_BROWSER
Problem :
When you compile in hosted mode, you have the following error :
[ERROR] Unable to find a default external web browser
[WARN] Try setting the environment variable GWT_EXTERNAL_BROWSER to your web browser executable before launching the GWT shell
Solution :
In eclipse, Go on Run -> Run Configurations.Then, choose your google's project and click on Environment.The last thing, you have to do is to add the variable GWT_EXTERNAL_BROWSER with the value firefox.
When you compile in hosted mode, you have the following error :
[ERROR] Unable to find a default external web browser
[WARN] Try setting the environment variable GWT_EXTERNAL_BROWSER to your web browser executable before launching the GWT shell
Solution :
In eclipse, Go on Run -> Run Configurations.Then, choose your google's project and click on Environment.The last thing, you have to do is to add the variable GWT_EXTERNAL_BROWSER with the value firefox.
Subscribe to:
Posts (Atom)