60 likes | 70 Views
Learn how to create a simple Java program that prints "Hello World!" to the console. This tutorial covers the basic structure of a Java program, syntax errors, and common runtime errors.
E N D
COM S 207 The First Program Instructor: Ying Cai Department of Computer Science Iowa State University yingcai@iastate.edu
Hello World! /** * The HelloWorldApp class implements an application * that simply prints "Hello World!" to standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string } } • A few things to note: • Plain text editor • Comments • Class definition • The main method • Object, method, parameters • Java is case sensitive • Coding style
Basic Program Structure class CLASSNAME { public static void main(String[] args) { STATEMENT } }
Common Errors • Compile-time errors • A program contains syntax (or grammar) errors • The Compiler does not understand your code, and so won’t translate your code into JVM instructions • Run-time errors • Your program runs, but does not produce correct results • Syntax is fine, but logic is wrong
Start Edit Program Compile Program Syntax Error? Yes No Run Program Run-time Errors? Yes No End
Announcements • Read chapter 2 (2.1, 2.2., 2.3)