Java 101 — Introduction to Java
Getting Started
Five Rules of Computer Programming
- Computer Programming is easy but humans make it hard.
- Simple is almost always better.
- Organized always is better.
- Train yourself to step back and consider the problem.
- Think outside the box.
In order to understand a language like JAVA first we must understand how it works.
Java — The Process
Source Code → Compiler → ByteCode → JVM → Machine Code → OS
The Java compiler takes the source code and converts it into bytecode which it stores in a .class file on your hard drive.The JVM then reads the bytecode from the .class files, translates it in real time into machine code when the program is executed.
Java — Developing
There are three Java Development Editions to choose from.
Java SE — Standard EditionJava EE — Enterprise EditionJava ME — Micro EditionFor standard developing we fill focus on Java SE.
Java SE — The Components
Contained within the Java SE we have the JDK (Java Development Kit ).
The JDK contains :
- JRE ( Java Runtime Environment )
- Our Compiler
The JRE contains:
- The Java Virtual Machime
- The Java API
First Program aka 'Hello World'
public class HelloWorld {
public static void main (String [] args)
{
System.out.println("Hello World");
}
}
The first line is our Class Header, the following line is our Method Headerand everything inside the curly braces of our method header is our Class. In the class we have our Method which in this case the program is printing 'Hello World'.
Keep in mind:
- Always start your class with capitals and save it as the same name (Eg. HelloWorld.java)
- Every Java program has at least one class.
- A class is the building block of object oriented programming.
- Every piece of code exists inside a class.
- Case and spaces are very important in Java.