ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Main Class Java


Enviado por   •  26 de Junio de 2012  •  987 Palabras (4 Páginas)  •  525 Visitas

Página 1 de 4

public class Main(){

public static void main(String[] args){

//Body of main method

System.out.println("I just want to say hello!");

}

}

In Java, you need to have a method named main in at least one class. The following is what must appear in a real Java program.

public static void main(String [ ] args)

{

UrRobot Karel = new UrRobot(1, 1, East, 0);

// Deliver the robot to the origin (1,1),

// facing East, with no beepers.

Karel.move();

Karel.move();

Karel.move();

Karel.pickBeeper();

Karel.turnOff();

}

This method must appear within a class, but it can be any class. So here is the above main method enclosed in a class called Temporary. This would normally be in a file named Temporary.java. Your class should implement the Directions interface so that words like North are understood. We also put all of our files into the kareltherobot package so that all features of the UrRobot class are available. So here is a complete version of the file Temporary.java:

package kareltherobot;

public class Temporary implements Directions

{

public static void main(String [] args)

{

UrRobot Karel = new UrRobot(1, 1, East, 0);

// Deliver the robot to the origin (1,1),

// facing East, with no beepers.

Karel.move();

Karel.move();

Karel.move();

Karel.pickBeeper();

Karel.turnOff();

}

}

--------------------------------------------------------------------------------

For those wanting explanation of some of the Java words here we provide the following somewhat simplified definitions.

A Java package is a way to collect different parts of a large program together logically. The Java system (JDK or Java Development Kit) comes with several packages of its own, but you can create your own. The name kareltherobot was created by the authors of the simulator for Karel J. Robot as a convenient place in which to collect robot programming code.

In Java the qualifier public means that something is available across packages. It is also possible to restrict visibility of names like Temporary to a single package or even more, but here we make it public.

The particular form of main is required by Java. While the following explanation of its parts is not needed now, and probably not especially understandable, you can return to it later when you know more.

In Java, main is a static method. This means the method is part of its class and not part of objects. Robots are objects. They are defined by classes, which are like factories for the creation

...

Descargar como (para miembros actualizados)  txt (5.8 Kb)  
Leer 3 páginas más »
Disponible sólo en Clubensayos.com