Tutorial 1: Hello Java

Go down

Tutorial 1: Hello Java Empty Tutorial 1: Hello Java

Post by Choti on Sat Mar 05, 2011 7:19 am

Code:


/** This is a documentation comment.
* you can have multiple lines of this.
*/

/* This is a comment.
 *  you can have multiple lines of this.
 */

//This is another comment

import java.util.*;
public class HelloJava
{
  public static void main(String [] args)
  {
    System.out.println("Sup JAVA");
    System.out.println(new Date());
  }
   
}

Ok so thats the code. Let me explain some stuff though.

public static void main(String [] args) <--this is our main method
{
System.out.println("Sup JAVA"); <---these are statements
System.out.println(new Date()); <---
}

In Java every application must contain a main method. You will need that line in every program you make.

We have two statements in our main method. The first one is used to print "Sup JAVA" and the second one gives us the date. Notice how the statements end with a ';'. If you dont have those your program will not compile and you'll get an error. Also notice after our main method we have curly braces. { }. After every method you need a set of curly braces. Your code for that method needs to go between the braces.

_________________
Tutorial 1: Hello Java Sigpro11
Choti
Choti
Ancient
Ancient

Posts : 282
Join date : 2010-01-16
Age : 29
Location : Scotland,Uk away from Rose =(

http://existenceguild.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum