Hi, welcome to my beginner Java tutorial. I, like you, am learning Java. If you really are eager to learning Java, but think you are not able, think again! You would be surprised how far a strong will for learning can take you. Let us begin with a simple exercise:
--------------------------------------------------------------------------------
Exercise 1: Creating a simple 'HelloJava' program
Hopefully you have your environmental variables set up. Because I assume you do, this will be our compiler using the Command Prompt:
javac -cp . *.java
The javac will call upon the Classpath environmental variable to redirect it to the bin folder of the Java Development Kit (JDK). The '-cp' tells the compiler to be ready to change directories depending on where the Java files are, and where the outputed class files should be placed. The reason why we use the 'Change Directory' tag is because it helps the compiler better understand where the Java files should be compiled to and where they are themselves. Using the default 'javac *.java' at some points can cause issues. This tag also helps you in the future when you want to use simpler methods of cross-compiling.
Now that our compiler is set up, lets make our first Java file. Open up Notepad (unless you have an IDE [Integrated Development Environment] set up, there is a link for both Eclipse and Visual J# at the bottom of this Exercise) and add this code:
public class HelloJava
{
public static void main(String[] args)
{
JFrame frame = new JFrame("Hello, Java!");
JLabel label = new JLabel("Hello, Java!");
frame.add(label);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
Now save this code as 'HelloJava.java'. After you are done with that, lets use our compiler command prompt code to compile our new Java file:
javac -cp . HelloJava.java
If you wish to, you could use the wildcard '*' to cover all the Java files in the directory. This will be needed in future exercises. Now, you should have a file called 'HelloJava.class'. Lets use some new command prompt code to run our class file:
java -cp . HelloJava
Note that we do not use wildcards (will not work with the Java interpreter) or a '.java' extension while calling the interpreter. We do not do these things because they will cause an error whilst running the Java Runtime Environment (JRE). After you have started your application, you should see this:

Congratulations, you have just created your first Java program! Lets relook over the code that we have just used.
public class HelloJava
This will create a new public class file called 'HelloJava'. Instead of creating an 'heir' class file (used with just the 'class' without 'public', this will be explained more in future exercises) you are creating a Java file that represents its name. That is why it is essential to have the Java file named 'HelloJava' and nothing else (it does not ignore capitals.) You should also notice the brackets ('{', '}') that are both after this lin at the end of the class file. These brackets start the parsing of the code in that a class or other code that use brackets (integers, voids, booleans, etc....) The final bracket will also end the parsing of the code. If the final bracket is not implemented, you most likely will have a parsing or public errors.
public static void main(String[] args)
This is a public static (unchangeable unless the creator changes it) void that the interpreter auto-maticly looks for. Without one of these, it is impossible to run a class file directly. However, you can still run it be calling it from another file (hence comes the static [static will be used for every void and boolean that is called from another class file].) Also, you may notice the 'String[] args'. This will String the basic argument (args) to the main void. This will implement basic System code inside of the application (used in 'System.out.println' and other System code, depending on the arugement implemented.) You will be using many Strings while coding in Java. I will teach you more about strings in the future exercises.
JFrame frame = new JFrame("Hello, Java!");
This code will start a new JFrame class and input it with the text 'Hello, Java!'. This will serve as the title of our Java application. The JFrame is also out Graphical User Interface (GUI) whilst coding basic Java applications. It is very important while making a visual Java program. Also note the semicolon (';') at the end of this statement. This tells the interpreter that this is the end of the line. Without a semicolon on most statements, a Java error will occur during the compiling.
JLabel label = new JLabel("Hello, Java!");
This will call the Java heirarchy JLabel and set it as a new class. It will then input the quoted text 'Hello, Java!' inside of the public JLabel and will set it equal to that String. JLabel then will create a new Label called 'label' with the value of its String (in thise case, 'Hello, Java!'.)
frame.add(label);
This will add our JLabek 'label' to our JFrame 'frame'. The method 'add' comes from the JFrame heirarchy class.
frame.setSize(300, 300);
The method 'setSize' is also from the JFrame class. In this case, it is setting our JFrame 'frame''s size to three hundred by three hundred pixels, a good size for the purpose of our application.
frame.setVisible(true);
Of course, you could have guess that the 'setVisible' method also comes from the JFrame class. In this case, it is setting our JFrame 'frame''s visiblity to 'true'. We could always change the value of the boolean to 'false' instead, but then we would not be able to see our GUI .
I hope you enjoyed this Exercise. I will, in the future, hopefully add more to teach you a little more about basic Java. Thank you for reading.
-----------------------------------------------------------------------------------------------------
Here are some useful Java resources:
Eclipse Open-Source-IDEVisual J# Express IDE (for J# development)