the basics of java for the beginners
Posted: Wed Jan 10, 2007 8:44 pm
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
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!!! so... how do you change that? by putting stuff between the middle brackets of cource!
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 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 and then put 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)...
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
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.
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... 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 ... and here are the pics of compiling and running as i said at the top
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[])
{
}
}
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!!! 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");
}
}
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
Code: Select all
System.out.println(num);
Code: Select all
public class hey
{
public static void main(String args[])
{
int num = 6;
System.out.println(num);
}
}
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);
}
}
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);
}
}
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;
well thats all for now unless anyone wants more, have a good day ... and here are the pics of compiling and running as i said at the top