the basics of java for the beginners

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply

was this a helpful tutorial

yes
2
67%
no, it was the most disgusting thing ever!
1
33%
 
Total votes: 3

stephen10101





Posts: 140
Joined: Sat Jul 29, 2006 9:11 pm
Location: Klein, TX

the basics of java for the beginners

Post by stephen10101 »

PICS OF COMPILING AND RUNNING AT THE BOTTOM!!!!

ok, im gonna try to make this as simple as i can, but java is easy so you will get it for sure! :) so you will need Jcreator, its the best compiler i have found for free. you can get it at http://www.jcreator.com/download.htm dl the second one, its what you want. once you have that installed open up Jcreator and go to file/new file/ and name it hey(make sure it is saving it as a java file!) ok, now that you have Jcreator open and hey.java ready to go here is the way you set up almost any program you will ever write in java

Code: Select all

public class hey
{
	public static void main(String args[])
	   {
	   	 
	   }
}
now to learn what this means... the public class thing lets it know what java file to make a class file for when you compile it, it will always be public clas followed by what you named the java file, not including the .java.

public static void main(String args[]) is the way most programs are started, pretty easy so far i hope...

the brackets will need to be set up that way, and you put things between the MIDDLE brackets, unless you are adding a new method such as pause, but i wont explain that, because this is the basics.

congrats, you just learned how to and set up a program in java that does absolutally nothing!!! :D so... how do you change that? by putting stuff between the middle brackets of cource!

Code: Select all

public class hey
{
	public static void main(String args[])
	   {
	      System.out.println("hey");	 
	   }
}
compile and run and you will get a command prompt that says hey!!! congrats, your first java program, it might seem lame, but its a start :D so now lets get into variables... dun dun dun!

start out with the same format, you can use hey.java if you want, but if you make a new file make sure its public clas followed by the name of the java file not including .java now in the middle prackets put

Code: Select all

 int num = 6
and then put

Code: Select all

System.out.println(num);
so it should look like this(num in this case is the name of the int, you could name it whatever you want though, it doesnt matter at all as long as there are no punctuation marks in the name, this goes for all variable types)...

Code: Select all

public class hey
{
	public static void main(String args[])
	   {
                      int num = 6;
                      System.out.println(num);	 
	   }
}
compile and run and you should get a command prompt that says 6. so now you can define numbers, but what about Strings and doubles!? well i will show you

Code: Select all

public class hey
{
	public static void main(String args[])
	   {
                      String name = "The Amazing Stephen";
                      double decimal = 6.32154;
                      int num = 6;
                      System.out.println(name);
                      System.out.println(decimal);
                      System.out.println(num);	 
	   }
}
compile and run and it should say...
The Amazing Stephen
6.32154
6

as you can see int is for numbers with no decimals, double is for numbers with decimals, and String is for words and sentences. that is all the variables we will learn for now, because i dont want it to be too confusing. So last but not least... OPERATIONS WITH VARIABLES!!! im gonna give you the code to a program and i should look familiar for the most part, it will have a few minor discrepancies though, but i will explain them.

Code: Select all

public class hey
{
	public static void main(String args[])
	   {
                      double abooga = 3.1415926535;
                      int iAmAwsome = 9;
                      double decimal = 6.32154;
                      int num = 6;
                      double total = 0;

                      total = abooga * iAmAwsome + decimal - num;
                      System.out.println(total);	 
	   }
}
compile and run and the command prompt should say...
28.595873881499998

so what is that jibberish about changing total from zero to 28.595873881499998? they are called variables for a reason, they can change!!! and what changed it was...

Code: Select all

 total = abooga * iAmAwsome + decimal - num;
if you want to do that sort of operation you do not need a double in front of total, because total has already been defined.

well thats all for now unless anyone wants more, have a good day :D... and here are the pics of compiling and running as i said at the top

Image
i dont want a sig!
User avatar
VoiDeD
Readers Club




Socialist

Posts: 1866
Joined: Thu Jan 15, 2004 4:46 pm
Location: Gurnee, IL
Contact:

Post by VoiDeD »

Ew java.
Image
Post Reply