Wednesday, February 20, 2013

A simple first example

HelloWorld.java

Download the following file and save it to a location on your machine. In this example, I will use the following directory:

HelloWorld.java

C:\SimpleJavaFiles

Note that the file HelloWorld.java has the .java file extension - this is a source code file. Open the file with Notepad (or another simple text editor).

It contains a class declaration which then opens a set of curly braces. All code for the class will be contained within these curly braces. The name of the class is HelloWorld. The class name and the file name must have the exact same spelling and case.


There is a single method inside of the class, called main. This is a special method in that it is where program execution begins.

public static void are reserved Java keywords.

The main method contains a single instruction/statement/line of code:

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

This will cause the sentence Hello World! to be printed to the default console window.


Java JDK


http://www.java.com/en/download/faq/develop.xml

Once downloaded and installed, you can find the JDK in your Program Files folder.


Class declaration

Every Java class begins with a class declaration, as follows:

public class MyClass {

}

public and class are reserved Java keywords and you may not use them to name entities in your own library files.

MyClass is the name of the class - this can be anything you like, however:
  • must not contain spaces - rule
  • should start with an uppercase letter - convention
  • should not start with a number - convention
  • where there are multiple words in the class name, the first letter of each word should be capitalised (also known as Camel-Case) - convention
Note: A rule applies to language syntax and cannot be broken. Convention applies to common standards and these can be broken.

Every class declaration includes a set of curly braces - one that opens a block, and one that closes the block. All code for the class must be contained within this set or the code will fail.

Another example:

public class NetworkUser {

}

This class is called NetworkUser.
 

Monday, February 18, 2013

continue statement


From "Branching Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)" ( http://bit.ly/ZlvTp1 )

"The continue statement skips the current iteration of a for, while , or do-while loop...."

Monday, January 21, 2013

Find installed version of Java

Windows
  • Find the 'Run' menu item from the start menu.
  • Open up a command prompt and type:
              java -version




....or you can just visit the Oracle site :)