Think you will like it
I'm going to cover almost all the Java basics like Basic language concepts,I/O,File handling,Statements and so on.
As a starters I'm going to tell you how to write a simple "Hello World" program using both Command line and GUI.
Remember It's required to install a version of JDK:http://www.oracle.com/technetwork/java/javase/downloads/ on your computer and the path javadir/bin added to PATH environment variable to follow this tutorial.I'll cover this part in my next tutorial.
Let's start,
Command Line
First open a text editor (If you are using Windows you have in built Notepad but I prefer Notepad++:http://notepad-plus-plus.org.Create a file called helloWorld.java and put this code in.
public class helloWorld { public static void main(String args[]) { System.out.println("Hello World"); } }
Then open up a command line and go to the folder helloWorld.java file located (I'm using c:/java).
Type
javac helloWorld.java
This will create a file called helloWorld.class in the same folder.Then type,
java helloWorld
This will print the following on command line,
Hello World
Now I'm going to explain the code,
The first line of the code is
public class helloWorld
"public" is the keyword that define the class to publicly accessible,I'll explain more about this further.
"class helloWorld" is defining of the class.HelloWorld is the class name,Note that this must be the same as file name!.
The first "{}" marks the block,area that Owns by helloWorld class.
The next line is,
public static void main(String args[])
This is definition of main() method,Every java program must have the main() method to execute!!
"public" is same as before.
"static" this keyword define the method as static.I'll explain this further as well.
"void" is the return type,which means what is the type the method returning the result.This could be int,String,etc..void means there is no return type.
Then,
System.out.println("Hello World");
This is the line which prints "Hello World" on command line.
"System.out" is the class used to stranded output in Java.
println() is the method which prints the "Hello World",It prints the part in the "()" in a new line.If you don't want a new line just use print()
That's it,
So try to compile and run.Here is my snapshot.

GUI
Create a new file called helloWorldGUI.java and put this code in.
import javax.swing.*; class helloWorldGUI { public static void main(String args[]) { JOptionPane.showMessageDialog(null,"Hello World"); } }
Then using command line go to the folder and,
javac helloWorldGUI.java
java helloWorldGUI
This will pop up a message box saying "Hello World".Press ok to end the program.
What's new in this code?,
import javax.swing.*;
"import" keyword is used to include external packages or classes in our java program.
"javax.swing" is the JDK's inbuilt GUI toolkit.
What is the meaning of "javax.swing.*"
The "*" in the end means import all the classes inside the package "javax.swing"
JOptionPane.showMessageDialog(null,"Hello World");
"JOptionPane" is the class which includes the tools like message boxes or input boxes.
"showMessageDialog()" is the method which pops up a message box.The parameter "null" means the message box should not be in a parent window.We'll come to this later.And the next parameter says what is the message.In this case it's "Hello World".
Compile and run.Let's see how it goes!

Here are the both command line version and GUI version sources.


That's it,
See you with the next tutorial.
Any questions and comments are welcome
Edited by madushan1000, 20 August 2012 - 09:34 PM.
added poll