COS 212 Resources

COS 212 Resources

  • Docs

›Java Crash Course

Getting Started

  • Introduction
  • Installing Linux
  • Development Environment

Java Crash Course

  • Hello World
  • Compiling and Running
  • Makefile
  • Comments
  • Variables and Types
  • Operators
  • Slides

Tools

  • Version Control
  • Hello World with Git

Notes

  • Self Organising Lists

Compiling and Running

Compiling

Once Java and Java JDK have been installed Java programs can be compiled using javac

man javac

NAME
       javac - Reads Java class and interface definitions and compiles them
       into bytecode and class files.

SYNOPSIS
       javac [ options ] [ sourcefiles ] [ classes] [ @argfiles ]

Examples

Explicitly list java source files to compile

javac Main.java 

Compile all .java files in the current directory

javac *.java

This will generate .class files in the current directory. These can be executed using the java command, if they contain a

public static void main(String[] args)

method.

Running

The java command is used to run .class files that have a main method.

man java

NAME
        java - Launches a Java application.

SYNOPSIS
        java [options] classname [args]

Examples

java Main

Which will output

Hello, World!
Last updated on 2/7/2019 by Evert Geldenhuys
← Hello WorldMakefile →
  • Compiling
  • Running
COS 212 Resources
Docs
Getting Started
GitHubStar
Facebook Open Source
Copyright © 2019 Evert Geldenhuys