20 likes | 124 Views
Ch1 Cont. 1.6 Compiling a Simple Program : Lets dissect the simple “Hello World” program: public class Hello{ public static void main(String[ ] args ){ System.out.println (“Hello, World”); } }
E N D
Ch1 Cont. • 1.6 Compiling a Simple Program: • Lets dissect the simple “Hello World” program: public class Hello{ public static void main(String[ ] args){ System.out.println(“Hello, World”); } } • Points of Importance ( In General – not necessarily applicable in “Hello World”): • Classes are the Building blocks in Java! • Classes are written to represent entities in the Real World. ADT “BankAccount”! • Class variables (Objects of that class) manipulate their data (instance fields) by calling associated methods. NOTE – EITHER BUCKLE UP <or> gloss over – TBD! • Methods are functions of a class -> usually invoked by dot.notation( ). • Classes by convention start in UpperCase. • Every Java application contains a main method. Basically the main program. • General Layout conventions: • Tab over every level of abstraction (top-down design indentation) • Line up ending brackets} with its starting code. • Give your code “air” in a uniform manner. • Your code should be readable. • Lets dissect the above code: • “Hello World” is a ___________, and also a __________ of the print method. • Syntax vs Semantics.
1.7 Errors • A compile-time or syntax error is a violation of the grammatical rules of the particular language you are programming in. • Syntax errors occur during the compilation process. • Common syntax errors: • Misspelled words – Java is case-sensitive. • Omitting semi-colons. • A run-time or logic error occurs when the program compiled correctly, but the program either crashes during execution or gives incorrect results. • Test your answers using pencil & paper! • Using various methods along with the Debugger will allow you to find logic errors. • 1.8 The Compilation Process. • Look at the p26 diagrams. • Lets log on (StudentAccessCode & ID_Number) • BlueJ public class Hello { public static void main(String[ ] args) { System.out.println(“Hello, World”); } }