Java Programming: Writing Your First Java Program, Study notes of Computer Science

Learn the basics of java programming by writing and running your first java program. This guide covers commenting, class definition, main method, and output. Compiling and running the program is also explained.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-emb
koofers-user-emb 🇺🇸

9 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java Intro
pf3
pf4
pf5
pf8

Partial preview of the text

Download Java Programming: Writing Your First Java Program and more Study notes Computer Science in PDF only on Docsity!

Java Intro

A First Java Program

//The Hello, World! program in Java

public class Hello {

public static void main(String[] args) { System.out.println("Hello, World!"); }

A First Java Program

public class Hello {

}

  • Definition for the class Hello
  • Class Hello MUST be defined in a file named Hello.java
  • The class definition is enclosed in {}

A First Java Program

public static void main(String[] args) { }

  • Every Java application must have a main method
  • The header of every main method looks the same
  • The method is enclosed by {}
    • Whitespace is ignored
    • Proper indentation is not required by the compiler
      • But, it is required by the instructor...

Java

High level Code

Compiler

Interpreter Output (JVM)

Bytecode

Writing/Compiling/Running

1)Write the program using your favorite text editor –

save a class classname into file classname.java

2)Open a terminal window and cd into the directory

where your code is saved

3)To compile, type javac classname.java

4)Fix any errors and go back to step 3

5)To run, type java classname