CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Introduction

Introduction
Anatomy of a class

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

When the JVM starts running, it looks for the class you give it at the command-line. Then it starts looking for a specifically-written method.

Next, the JVM runs everything between the curly braces {} of the main method. Every Java application must have at least one class, and at least one main method.

  • public: It is an access modifier. It defines the circumstances under which a class can be accessed. Here public means that everybody can access it.
  • class: is the keyword to identify a class.
  • HelloWorld: is the name of the class.
  • {: opening curly brace of the class
  • public: starts of the method accessible by everybody.
  • static: means this method works without instantiating an object of the class.
  • void: is the method's return type. It returns nothing.
  • main: is the name of this method.
  • String: is a class. Any arguments to this method must be String objects.
  • []: the suqre brackets mean the argument to this argument is an array of Strings.
  • args: is the identifier of the array of Strings that is the argument to this method.
  • {: opening curly brace of the method.
  • System.out.print: print to standard output (defaults to command-line).
  • ("Hello World!"): is the string you want to print.
  • ;: every statement must end in a semicolon.
  • }: closing brace of the main method.
  • }: closing brace of the Hello class.

Introduction | History | How does Java work? | What you'll do in Java? | Code structure in Java | Anatomy of a class | The main() method