Java Article 3 - Introduction

Java is a programming language widely used today for programming software that runs on servers, PCs, and mobile devices. It is an appealing language to learn since programs written in Java are fully compatible with Mac OS X, Linux, Solaris, Android, and Microsoft Windows operating systems.

To demonstrate the demand for Java in the US, I went to a popular job search site and typed in a job title of "Java." Over 1000 entries appeared, with 45 posted on the day this article was written. While many new programmers are focusing on languages like C# and C++ there still is a huge demand for Java.

Java tends to be used a lot for programming business, scientific, and server-based applications. Java is not commonly used for game programming, however some notable exceptions are: Minecraft, which is a truly awesome sandbox game, and Runescape which at the time of this writing is the world's most popular free MMO. This being the case most people would still say if you are interested in game programming you should look into C++ or even C#.

As a language Java has many characteristics. For now I will just mention two:

  • It is a high-level language in that it resembles English rather than low-level languages like machine language which are in binary(1's and 0's).
  • It is object oriented.

Object oriented programming (OOP) was an important development in computer science and is a huge leap forward from older languages such as Fortran and BASIC. The benefits and uses for OOP are many and it can take years to fully understand and use. For now just remember the following:

A Java program is made up of classes. A class is a blueprint which can be used to create objects. Think of a blueprint in real life. It is a set of instructions to create an object, such as a bicycle. In the old days you would just write code for a bicycle. In OOP you write code for a class which will create a bicycle for you.

One advantage here is it is very easy to automate your class and create as many bikes you want, each with their own unique properties like color and size.

Can you see how this would be handy to a game programmer? One class could be used to create a variety of monster objects each with their own unique graphics, health values, and attack types. So in this example the class runs behind the scenes and creates monsters for you, a bit like a cookie-cutter creates cookies.

In a commercial setting you could have a RawMaterial class, used to create individual raw material lots with properties like lot size, raw material name, and date received. A Customer class is another common example and it can have properties like telephone number, name, and transaction history.

I am barley scratching the surface on what OOP can do, but that is enough for now on classes and objects. So how do you program a class? Well here is a very basic Java program that just displays "Hello world" to the console when you run it.

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

This class is so simple it does not even create an object. For flexibility and convenience Java was designed so that classes don't have to always create an object. So in the above example it would be extra work for the programmer to create an object from the class that just says "Hello world." People who create programming languages try to make them as efficient as possible, to save work for the programmer, and allow companies to develop software with less cost.

Don't let the whole concept of classes intimidate you. For now just say to yourself "My HelloWorld program is a class."

Since there are only about 12,000 examples of "Hello World" in books and on the internet I decided to try to do something useful and turn this into a Java syntax cheat-sheet. So below is a Hello World infographic with notes as to what all the non-intuitive things that raise questions such as:

What the heck does "public static void" mean? Why and why there braces (}) everywhere? This reminds me of orthodontists and high school. "args…" this has something to do with pirates?

Java Syntax Summary:

Feel free to download, repost, and reuse this just please keep my website name visible. If any of the terms confuse you, look at Java article 2: Definitions.

The HelloWorld program just does one thing:

System.out.print("Hello World!");

It prints Hello World to the console. This is called a statement. Statements are single lines of code that tell the program to do something.

Statements are contained within methods. In this case the method is named "main".

public static void main (String [] args)
   //Your statements go here
   System.out.println("Hello World!");

So those are the fundamentals of classes, methods and statements.

In the next article we will look at what gives a lot of people the most grief when learning programming: syntax, the picky way the compiler makes you word and punctuate things