Welcome to Java
Created in the early 1990's by James Gosling, Java is a high level language that is able to be executed on a variety of platforms, making it an ideal addition to a web developers aresenal. Java programs are secure and reliable, meaning that applets on running on a web site are not likely to infect a users device AND once a Java program compiles correctly, it tends to work.
Unlike JavaScript, which is interpreted by browsers on the fly, Java code needs to be compiled and packaged to be run. Most high level languages that need to be compiled require separate compiling runs for different platforms and devices. This is because compiling a script is the process of turning it into byte code for a computer to execute and each platform requires a specific type of byte code. Java, however, compiles into its own byte code, which is then run by the Java Virtual Machine (JVM). The JVM is a program that can run on multiple platforms, thus one compilation of a script can execute in a variety of environments (provided that the environment is running the JVM).
Getting Started
To get started, you will need to download the latest version of the Java Development Kit(JDK) and a Java editor. When downloading the JDK, you will also see references to the JRE (Java Runtime Environment) - this is the virtual machine that allows computers to run Java programs. The JDK will have a version of the JRE in its download, so there is no need to download it separately. When downloaded, the JDK will install itself into you computer by double clicking on the downloaded file.
As for an editor, there are a variety of Java editors out there. In this course, we will be using Eclipse. Eclipse is an Integrated Development Environment (IDE) which means it provides robust support for coding and debugging Java. Eclipse has a lot of very advanced features and is used in many professional development environments. We will only be scraping the surface of what Eclipse can do. When downloading Eclipse, you will simply need to unzip the downloaded file to the location of your choice. You will also need to create a local folder in which all of your Java code will be stored.
Your First Java Program
When Eclipse first opens, it will ask to identify your workspace. This is the folder in which all of your Java programs are stored. All programs for this class can be saved in the same workspace. Files in eclipse are organized by projects. So, the first thing to do is create a new project (File -> New Java Project). When naming your project, use only letters, numbers and underscores. Try to avoid using spaces. Next, you will need to create a class. The class is the basis of all Java programming. Follow the same naming rules when naming classes. Also, when creating your class, be sure to check the box next to
public static void main(String [] args). This will automatically create the main method in which all of your code will be placed. Type the following inside the main method:
System.out.println("Hello World!");
Then, click the Green play button. Congratulations! You made your first Java program.