Welcome Guest [Log In] [Register]



Add Reply
Basic Java - Part I (Java)
Topic Started: May 21 2007, 06:59 PM (533 Views)
rig
1a5a6a4
Administrators
Note: Some java compilers require a certain class name for the program to be executed properly. Make sure you learn about your compiler first!

All items in red can be changed to any string containing no special chars or numbers. Ignore the blue ones for now, as we will use them later.

First off whenever you make anything, make sure that the first line looks something like this

Quote:
 
public class name
{
public static void main()
{


Java uses "classes". Each class may be used for a different purpose. I will teach you in later lessons on how to extend the use of other classes. Use this for the base class, the one which runs the whole thing.

Code:
 

String str;
str="Hey!";
System.out.print(str);


String str; // "Instanziates" the string str, or in standard english it prepares the program to use it.

str="Hey!" //This sets the variable str to Hey!

System.out.print(str) //This print Hey! System is called an object. Out is a class, and print is called a method.


Methods are like functions except each method is particular to its class object. (We'll talk more advanced about this in a later lesson)

Another important note, is that you always put a semi colon, after a method or Importing a class.

Quote:
 

import cs1.Keyboard; //This imports the keyboard class (You might not already have this, but it is important to get it)

public class joe
{
       public static void main()
       {
        int x; //Instanziates the integer x
        System.out.print("Enter a var ");
        x=Keyboard.readInt(); //Read Int is a method for the keyboard class which reads an integer
         System.out.println("You entered "+x); //Just like in gamemaker, also another method called println moves down a line after it is done executing the method.
       }
}


That is the basic lesson of part I. Ill have more soon.
Posted Image
Offline Profile Quote Post Goto Top
 
fsd
3a4

Anyone know of a good free java compiler. I tryed using netbeans once but i dont think i could get it to work or somthing.
"mmmmm i love the internet. every time i go to a website i get a cookie HOW AWESOME IS THAT!" - Quote from me


"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - Albert Einstein
"Imagination is more important than knowledge."- Albert Einstein
Offline Profile Quote Post Goto Top
 
rig
1a5a6a4
Administrators
Try Blue J, its made by the university of kent. Its what I use, and its free. Its actually better than some you can pay for.
Posted Image
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Tutorials · Next Topic »
Add Reply


Theme designed by Sith of Outline