/* Expressions */ 3 3+1 3.14*Math.sin(3) true !true 1<5 "This is a String" "man"+"kind" int x=4; x*5 x++ ++x x (x<5 ? "x is smaller than 5" : "x is greater or equal to 5") /* Statements */ x++; System.out.println(x); System.out.println("hi"); System.out.print("x*5="); System.out.println(x*5); /* Method declaration */ int square(int x) { return x*x; } square(100) /* Class declaration */ // if you define a class, JOSH will try to // execute its main() method !!! class A { void sayHi() { System.out.println("hi"); } void sayHo() { System.out.println("ho"); } } A a = new A(); a.sayHi(); a.sayHo(); class B extends A { void sayHi() { System.out.print("Hi"); } void sayHiHo() { sayHi(); sayHo(); } } (new B()).sayHiHo(); /* Exception handling and IO */ try { java.io.BufferedReader inb = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.println("Enter your name: "); String name=inb.readLine(); System.out.println("Hi "+name+", welcome to JOSH!"); } catch (Exception e) { System.out.println("Error: Could not read your name!"); }