A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Java tuts

3.1k views · started by God ·
#1
Java tuts
Please note that this will have pics soon its just ubuntu is a pain in the ass to take screenies. I may make a few video tuts if asked.

Part 1 \n Installing the jsdk.
Note if anything sounds unclear look up "The new bostons" tuts on youtube.


Download "JDK 6 Update 17" (The 17 part doesn't matter) from here.
Set that up on your OS. (Note if using ubuntu or a debian based linux dist just look up Sun sdk in synapic.)


After that you should setup a ide sense it gives you useful debugging tools and such.

I suggest eclipse which can be found here.

After you have your workspace setup and everything it is time to get on to the real tut.
#2
Part 2
Looking at hello world.


Here is out basic hello world script.

class nexx {
public static void main(String[] args) {
System.out.println("Hello World!");
}

}

Its very basic and easy to understand.
Lets look at it line by line.

Heres the first line.
class nexx {

What this is is it tells java what class it is going to make when it compiles. Don't worry we will talk more about this later for now just remember that the class name must be the file name for example this would be called "nexx.java".

Heres our second line.
	public static void main(String[] args) {

This is a method for now just note that the method called main is automatically executed.

Heres out third line where all the magic happens.
		System.out.println("Hello World!");

The "out" in this code means that it will output something to the console the "println" says print this with these parameters on a new line. Notice that using "print" would print on the same line as the last one instead of a new line.
and the closing brackets for the opening brackets. (Note: You always must have the same amount of opening brackets as you do closing.)

Now lets get to executing this program. Open up that eclipse program that you set up earlier and just click next and use the defaults for all settings.

Make a new project using file-new-java project and call it whatever and make a new class with file new class and call it "nexx" and leave the rest default.

Copy and paste all of the script that is up there into the main box and click the green play button. If asked press "Java application". Then in the box below you should see "Hello World!".

Congrats you have just made your first java program.
#3
Part 3
Variables


Now we are going to take a look at variables in java.

Here are some basic types.

String
int

There are many more kinds but for now lets stick with those to make it simple.
The first is a String. A String holds letters and numbers and such. Your going to not use this for just numbers due to speed and other issues which you will learn about in a while.

A String might look like this.
String test = "I am a string";

(Note: after every line that does not end with a { put a semicolon.}

Now for a int.
A int holds a whole number like 1 or 2 but not 1.4535697878469385936.
A int cannot hold any letters.
Example of a int.

int lulwut = 18;

Now you know a little bit about ints and strings, Lets put them to use.

Take your hello world script from the last part and change a few things up.
Before our
System.out.println("Hello World!");
put these 2 lines.
String stringtest = "This a is string.";

and
int inttest = 187;


So now your script should look like this.
class nexx {
public static void main(String[] args) {
String stringtest = "This is a string";
int inttest = 187;
System.out.println("Hello World!");
}

}

Now lets use our string and our int.

To do this we are going to modify our System.out line.

Lets edit our line to
System.out.println("This is my string " + stringtest + " This is my int " + inttest);


Now lets look at that to use out vars we just use them out of quotes and to combine multiple things like text and a string or a string and a string we use a a "+".

If we exucute this we should get
This is my string This is a string This is my int 187
. Thus we just called out vars.


Well this is about it on vars for now.
#4
Arghh Im tired.
#5
nice tut very helpful
#6
God wrote:
Arghh Im tired.


Spam, and you don't need 3 posts to post a tutorial. And video's that arent yours don't count.