I didn't like how the only java tutorial I found on this site didn't catch the essence of java which is
that it is an object oriented programming language. First I'll show you a little program without
using the object oriented part of java.
Code:
public class test
{
	public static void main(String args[])
	{
		System.out.println("Testing");
	}
}
This is about as simple as java gets. First of all, let me just say that for this program to compile
and run you must have it saved as test.java. Now let's analyze the program.

public class test

every program must have this at the top and the third word must be the same as what you
saved the program as. If it is different you will get an error.

public static void main(String args[])

every program must also have a main method. This is where you handle your output.

System.out.println("Testing");

This is the standard form of showing output. You can also do

System.out.print("Testing");

This statement does the same thing except that it won't go to the next line after it prints
Testing. If you wanted the next output to go to the next line you could use

System.out.print("\nThis will be on a new line");

The \n puts the output on a new line.

Now let's add a new class to the program.

Let's say you had the same as above. You could put a whole new class within the program.
In this class you can have methods. A method is like a function in C++. You put stuff you want
done such as output or adding numbers in the method then you call it from the main class.
Here's an example.
Code:
public class test
{
	public static void main(String args[])
	{
		System.out.println("Testing");
		stuff.print();  // this calls the print method
	}
}

class stuff
{
	public static void print()
	{
		System.out.println("Hello World");
	}

}
If you compile and run this program you will see this output

Testing
Hello World

Now let's get into the object oriented part of java. If you change the program above to this.
Code:
public class test
{
	public static void main(String args[])
	{
		stuff s1=new stuff();		
		System.out.println("Testing");
		s1.print();  // this calls the print method
	}
}

class stuff
{
	public void print()
	{
		System.out.println("Hello World");
	}
}
notice how it's public void print() instead of public static void print().
This is because we want to make different objects of the stuff class. We do this using these lines
which are in the main method above.

stuff s1=new stuff();

This creates an object or instance of the stuff class called s1. Then we used s1 to call the
print() method.

s1.print();

You could even make another method in the first class called test and leave out the second class
stuff. Here is how this would be done.
Code:
public class test
{
	public static void main(String args[])
	{
		System.out.println("Testing");
		print();
	}
	public static void print()
	{
		System.out.println("Hello World");
	}
}
As you can see there are many ways to do the same thing in java. The last 3 programs all have
the same output, but they are all different. Some say the proper way to do it is to make a new class
for each task you are trying to do. If you take the second example
Code:
public class test
{
	public static void main(String args[])
	{
		System.out.println("Testing");
		stuff.print();  // this calls the print method
	}
}

class stuff
{
	public static void print()
	{
		System.out.println("Hello World");
	}
}
You could also leave off the second class stuff and make it into a whole different file.
I used the java sdk from sun and jcreator for my development environment. As long as you save it in
the same directory you can have two separate files. This is how they want you to program in java.
They don't want one file with a bunch of garbage. Every time you do a new task you either make a
new method to do within the class, or make a whole different class. Using this method you would have
Code:
public class test
{
	public static void main(String args[])
	{
		System.out.println("Testing");
		stuff.print();
	}
}
edit:
does anyone know how to get spaces to show up?
This would be the first file saved as test.java.(don't forget the .java)

Then you would have this in a separate file saved as stuff.java *in the same directory
Code:
public class stuff
{
	public static void print()
	{
		System.out.println("Hello World");
	}
}
You would have to run this from the first file called test.java because that contains the main method.


Here is a program using integers
Code:
public class calc
{
	public static void main(String args[])
	{
		int num1;
		int num2;
		int num3;
		num1 = 2;
		num2 = 3;
		num3 = num1 + num2;
		System.out.println(num1 + "+" + num2 + "=" + num3);
	}
}
Generally in java you declare the variables at the top of the main method as shown above. If
you declare a variable and don't set it equal to anything you will get an error saying variable
not initialized. You could just start it out at zero when you declare it by typing

int num1=0;

This program adds num1 and num2 and puts the answer in num3. within the
System.out.println statement you see a lot of pluses. you have to use pluses between each
thing you are printing out. You would get an error if you left any of the pluses out.

Now I'm going to talk about constructors. Look at the sample program below.
Code:
public class test
{
	public static void main(String args[])
	{
		stuff s1 = new stuff(5);
		System.out.println(s1.showValue());
	}
}
class stuff
{
	private int getValue;  //if you are going to use a variable throughout the class declare 	
//here to be able to use it in each method
	
	public stuff(int num)  // this is the constructor and it receives the 5 that you put 
	{                      //within the parenthesis when you instantiated the object
		getValue=num;     // in the main method
	}
	public int showValue()
	{
		return getValue;
	}
}
Whether you make a constructor or not it is automatically done behind the seens and it initializes
all the values to zero (or false if its boolean).
here we have a return method(public int showValue()).
All return methods must return something or you get an error. You could just say return 0;
if you want. The variable must be the same type as declared in the head of the method.


ex.
Code:
public String getString()
{
	String a= "Hello";
	return a;
}
You could also use double. Whenever you do a return method the output is not printed out.

This is why I did System.out.println(showValue()); in the main method.

if you were wondering what the private keyword does private int getValue;
This makes that variable only accessable through the stuff class. You can return it to the
test class through a method but you cannot change it from the test class.

I forgot something. You can also instantiate an object like this.

stuff s1;
s1=new stuff(); //you can put this part anywhere within the class, it doesn't have to be right under the stuff s1; line

I'm getting tired of typing now. If you all would like to see more like maybe some
graphics, just post some replies on what you would like to know. This should be enough to get
anyone started in java. I hope you all enjoyed it. p.s. If you see any errors please post about
them and I will fix them.