The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Help Getting Started With Java (tutorial)

I wrote the following tutorial for my friend and decided I'd post it on here to help out some people .

Some basics that aren't covered in this tutorial:
*applets
*exceptions
*cases
and some other stuff.

public class NameGoesHere {

*pubic class indicates that the class is public.
*NameGoesHere is the name of the class (this is case s. Meaning that capital letters matter.)
*{ indicates the starting of the class block
Note: we need to close the blocks with } at the end of each block.

public static void main (String[] args) {

*This sentence is needed in order to be able to execute the code, we will be
needing this in all of our codes (args stands for arguements).
*{ indicates the starting of the code block

Numbers:

int = integer (does not have a decimal & it does not round the number, it removes the decimal value).
double = an integer with a decimal.
float = a double but with more numbers (e.g: 0.00000000001).

int count = 12;

*This gives count a value of 12, whenever count is mentioned the stored value
of 12 will be used.
*; is required at the end of each statement in order to be executed, think
of it as a period in english.

*System.out.print command is used to display a certain value or string on
the output.

Example:

System.out.println("Hello");

Output:
Hello

*System.out represents the object while print is the method & ln stands for
new line (prints on a new line).
*The " indicates the string, we need these quotation marks whenever we use
a string.

Packages & imports:
Packages are the set of classes, while imports are used so we can use certain
classes and objects.
Example: import.java.util.Scanner;
This import must be declared in order for the scanner to work in the code.

We can either import single imports of the utilities or all of them using the *.

Definitions (just the basic ones we're going to be using)
boolean = either true or false
final = constant / can't be changed
char = character (we use single quotes such as 'H')
String = words & sentences, we use double quotes when using strings.

compile-time error: this means that you have wrong syntax or you're trying
to do something that java doesn't allow (example: if you forget to use ;
at the end of a print statement then you'll get a compile-time error).
If a compile time error occurs the class file will not be produced.

logical error: this means that the program does compile and run but the output
is incorrect. Usually happens when you have the wrong formula, etc.

runtime error: forces the program to crash, usually happens when we do things
that cause it to terminate abnormally such as dividing by zero.

We debug and test programs to look for errors.

The while loop:

while (condition) {
statement;
}

if the condition is true then the statement will be repeated until the condition
turns false.

This will print out:
Hello
This is an example
to show you
"escape sequences."

Now let's use what we just learnt to make a program that will read 10 inputs
and prints out the highest number.

Note: I will not be going into detail with the scanner class, formats, math
classes, etc. You'll need to study these on your own.

import java.util.Scanner;
import java.text.DecimalFormat;

public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in); //command we use to be able to read an input from the user
DecimalFormat fmt = new DecimalFormat ("0.###");