A program in java consists of a class or collection of classes. A class consists of a group of functions (or methods) that interact with each other. The format of a class would be
public class
DoSomething
{
    public
DoSomething ()
    {
        ...doing something...
    }
    public void
Run ()
    {
        ...doing something else...
    }
}
        In this class, called "DoSomething," i have declared that the class will be public and then what its name will be. It has two methods, one with the same name as the class and another, called "Run." The method with the same name as the class is called the constructor, while the other method is just like a function in c. All methods must be declared either public or private in java, the difference being that private methods can only be called from the class that they are in while public ones can be called from any class.
        If i want to use this class i must create an object that represents it. This is just like creating an 'int' object or a 'string' object and then using it. Instead of 'int k = 0;' i would say 'DoSomething k;' and then i can use k anywhere i want to access methods of the DoSomething class. here is an example of another class using DoSomething
...
    public void
Go ()
    {
        DoSomething k =
new DoSomething();
        k.Run();
    }
...
        Here, the method called "Go" creates a DoSomething object and then calls the "Run" method in it. The 'new' operator must be used every time that an object is created, and when it is the constructor of that object is called. In this case, when i say 'k = new DoSomething()' the DoSomething constructor is called and any code there is executed. However, just as in c, 'new' is not necessary when making an 'int' or 'double.' I can still safely say 'int k = 5,' but if i want a String i do have to use new. Strings in java are objects just like DoSomething, they have a constructor and methods that you can use any time you want to. It is possible to create a String without using new, i can just say String name = "paul" but i like to use new most of the time.
...
    int k = 5;
    double y = 0.05;
    String name =
new String();
    name = "
John ";
...
        To look at the methods in the String class or any other java class use the link at the bottom of the screen. String is in the 'java.lang' package, and if i want to use a String i should have to say "import java.lang.*;" at the top of my class. The equivilent to this in c is the "#include" tag. Using "import" is the way to get any of the packages in the java api, but being as nice as they are they decided to give us 'lang' for free. That means i don't need to import java.lang to be able to use String or any of the other classes in that package.
        Variables such as ints, doubles and even objects like Strings or DoSomethings can be declared inside a method like 'Run' or outside of a method, in which case they are called global. A global variable can be used in any method of that class, while if i declare a variable in 'Run' i can't use it in any other methods (not without a bit of extra work anyway).
public class
DoSomething
{
    private int number;
    private String name;
    public
DoSomething ()
    {
        number = 10;
        name =
new String();
        name = "
Matt ";
    }
    public void
Run ()
    {
        number = 35;
    }
}
        Basic expressions work about the same in java as they do in c, such as 'for' and 'while' loops and 'if' 'else' statements.
        To complile a java program first make sure the program is in a file with the same name as its class. Thus the class DoSomething must be in a file named DoSomething.java. The java compiler is available from the java.sun.com website or if you are in your Duke account (on a unix machine for example) then you should have access to the compiler already. All you need to type is "javac DoSomething.java" or whatever your filename is. This will run the compiler, and if the class doesn't have any mistakes it will create a new file called "DoSomething.class." These 'class' files can then be executed by saying "java DoSomething.class," or if the program is an applet the web can directly use the class file. Thus there are no executables in the same way that a c program is made into an executable, but a class file is basically the equivilent.
        Applets: When a java program runs inside a web browser, it is called an applet and requires some special handling. A class that will be used as an applet must import the 'java.applet' package and have the following line in the class declaration:
public class
DoSomething
extends Applet
{
...
}
        For now, lets just say that this "extends Applet" line allows us to use some of the methods in the java Applet class that create and run the applet. In an applet, the constructor is unnecessary as the browser runs another method instead. It is called 'init,' and all applets must have it to run. Here is where the applet's components are initialized and added.
public class
DoSomething
extends Applet
{
    public void
init ()
    {
        add(...);
    }
}
        The 'add' method of the applet class places components like buttons, text fields, or labels in the applet. In order to use buttons, the "ActionLister" interface must be used. An interface is similar to a class but requires a different line in the class declaration. Instead of saying "extends" we have to use "implements," and the method that does the work for us is "actionPerformed."
public class
DoSomething
extends Applet
implements ActionListener
{
...
    public void
actionPerfomed (ActionEvent e)
    {
       ...
    }
}
        Take a look at Name.java to get an idea of
what a complete applet (a simple one) might look like. To see what
each of the components does (Button, TextField, Label, TextArea, etc)
use the java api link at the bottom of the screen and look in the
java.awt package.