Home » Java Basics » 01 - Java - An Overview
1
Writing and Compiling Java Programs
How to write and compile basic Java programs
- First, certain settings such as the path to the Java API and so on should be specified in an appropriate place on the computer.
- The Java program itself should be written in a plain text file with a “.java” extension (e.g. myprogram.java). The program should obviously follow all of Java's syntax-related rules.
- Next, the javac command (javac myprogram.java) is used to compile the files into bytecode - the language of the Java Virtual Machine - with a “.class” extension. Every Java program including the core and other standard packages are represented by groups of .class files
- This platform independent bytecode may be executed on a JVM installed on any OS or hardware. The JVM loads the program into memory, links related or necessary classes with it and carries out the execution. In effect, the running program will be combined with other classes that are part of the Java API.
- A program may consist of many classes. For easier distribution of large programs, multiple class files may be packaged together in a .jar file.
- The Java launcher tool creates an instance of the Java Virtual Machine to run the bytecode.
- Java is case sensitive - this means that all directives, syntax, and programs written for the Java platform should consistently use lower and upper case keystrokes while referring to variables, commands and so on.