Saturday, July 31, 2010

Command-Line: Antique.java

Courtesy of SCJP Sun® Certified Programmer for Java™ 6 Study Guide Exam (310-065) (9780071591065)
Chapter 10, Question 7










There are two sets of compile and run statements that will cause the code to run and compile without exception or error

javac Antique.java
java Antique
 
The second set ensures that the compiler uses JVM 6
 
javac -source 6 Antique.java
java Antique
 
To create error and exception, either of the following three pairs can be invoked
 
javac Antique.java
java -ea Antique
 
will throw a java.lang.AssertionError because there are 0 arguments


javac -source 1.4 Antique.java
java Antique.java 

will make the compiler output 
 
Antique.java:4: generics are not supported in -source 1.4
(use -source 5 or higher to enable generics)
  List myList = new ArrayList();
 
and finally

javac -source 1.6 Antique.java
java -ea Antique

will throw a java.lang.AssertionError because there are 0 arguments
 

No comments:

Post a Comment