Computer Science 15-100, Fall 2008
Class Notes: Getting Started
Getting Started
class MyCode { public static void main(String[] args) { System.out.print("This is"); System.out.print("a test"); System.out.println("that will run, albeit"); System.out.println(); System.out.println("with some problems..."); } }
class MyCode { public static void main(String[] args) { System.out.println(1); System.out.println(1 + 2); } }
class MyCode { public static void main(String[] args) { System.out.println("Howdy!"); // this is an end-of-line comment // (but not a very good one!) // The next line is commented out, so it is ignored! // System.out.println("This will be ignored"); System.out.println("And howdy on line #2"); } }
class MyCode { public static void main(String[] args) { System.out.println("Howdy!"); /* The preceding comments end at the end of the line, but this is a block comment, started with a slash-star, which will continue across new lines until a star-slash (on the next line): */ System.out.println("And howdy on line #2"); /* another block comment! */ } }
class MyCode {
public static void main(String[] args) {
System.out.println("Uh oh!); // ERROR! missing close-quote
}
}
Compiler output:
MyCode.java:3: unclosed string literal
System.out.println("Uh oh!); // ERROR! missing close-quote
class MyCode {
public static void main(String[] args) {
System.out.println(1/0); // ERROR! Division by zero!
}
}
Runtime (Console) output:
Exception in thread "main" java.lang.ArithmeticException: / by zero
at MyCode.main(Foo.java:3)
class MyCode {
public static void main(String[] args) {
System.out.println("2+2=5"); // ERROR! Untrue!!!
}
}
Runtime (Console) output:
2+2=5
carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem