Post: Java Programming Tutorials
06-15-2014, 07:14 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); I've notice that this section is dead, and all of the 'C# Devs' post on the PS3 Sections, so I decided to type up some tutorials for this section for a few reasons.

1.) Bring some more people to this section
2.) Get some new developers developing in a different language other than C#

So let's begin shall we?

Downloading the JDK

In order to compile Java programs, you're going to need to download/install the JDK. So to get the JDK head over to You must login or register to view this content. and download the JDK for your platform. After you have it downloaded, just install it via the install wizard.

After that we can go ahead and download Eclipse. Eclipse is a tool that you can use to write and compile java programs. You can also use Eclipse to make simple Java games and even program your own Android Applications!

To find Eclipse head over to You must login or register to view this content. and download the 'Eclipse IDE for Java EE Developers'

You must login or register to view this content.


Download that for your OS and it should come in a rar file like this

You must login or register to view this content.


Just extract that to your desktop or where ever you see fit! Then to start Eclipse, simply run 'eclipse.exe'

If it's your first time running eclipse it will ask you to set up a workspace, this is where all your coding and projects will go. You can set it to where ever you want!

You must login or register to view this content.


After that, to start a new project, navigate to 'File' > 'New' > 'Project' > 'Java Project'. After that, you can name the project whatever you want. After that, just click Finish. After that you will have your new project opened.

Next, navigate to your project folder and expand it, you should see two folders called 'src' and 'JRE System Library' What you want to do, is right click on 'src' > 'New' > 'Class'. After that you will see this:
You must login or register to view this content. Just name the class whatever you want and click finish. After that you will be able to see some pre-written code.

Congratulations, you have successfully downloaded/installed the JDK Smile



Making A Hello World Program


If you completed the first step properly, you should have some pre-written code that looks like this:

    

public class FirstClass {

}


Now, if you're some what familiar with any other programming languages, you will know that the most basic of programs use some sort of a 'main' function. We are going to make that in our class. To make this main function all you need to do is write the following:

    

public class FirstClass {
public static void main(String args[]){

}
}


Now for the final part of this 'mini tutorial' we are going to print a line with our 'Hello World' text. For this we use the 'System.out.println function.

    

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


Now to compile/Run this program just click the green arrow under the 'Refactor' tab. After that you should see the output here:
You must login or register to view this content.

Felicidades, you have made your first hello world program in Java!


Variables

Variables are an easy concept to grasp. If you ever been in the most simplest algebra class you should know what a variable is. A variable pretty much is just a place holder. It holds information. Just like the equation
'9=x*2' x is the variable because it holds the value of 4.5.

In java you can use variables to hold the values of text (String), integers (int), floats (float), decimal numbers (double), chars, etc.

Let's make a simple function to add a double and an integer together, hell, let's even use a string in there too.

Now, this isn't the best way to code this, but since if you're reading this, you're probably not the best at coding so it's too show you.

First, declare a double and call it whatever you want, I'll call mine 'a', set this to whatever you want. Next declare an int and set it to whatever you want, and for mine, I'm going to use a string with the text of '4.5 + 4 = " (Those being the numbers I am using) After that just make another double that equals the int and the first double together, and then print a line adding the string and the sum of the int + 1stDouble.

Like this:
    

public class FirstClass {
public static void main(String args[]){
double a = 4.5;
int b = 4;
double c = a + b;
String d = "4.5 + 4 = ";
System.out.println(d + c);
}
}

If you did this correctly you should output '4.5 + 4 = 8.5'

There are more variables that can be used in Java but for now I will stick to using these simple vars.


Scanners

A Scanner is a type of variable you can use to gather input from the computer or whatever the user is typing, etc. But to use this, you're going to need to import it. To do this, just type this about your class 'import java.util.Scanner;' After this you are going to want to declare the scanner like this.

    
import java.util.Scanner;

public class FirstClass {
public static void main(String args[]){
Scanner getIn = new Scanner(System.in);//You Can Name it whatever you want
System.out.println(getIn.nextLine() + " was your input");//You need the .nextLine()
}
}

Basically what this function is doing, is declaring the Scanner 'getIn' and printing a line with the input from getInt with the text ' was your input'.

Your output should look like this:
You must login or register to view this content.


If Statements

If statements are an easy concept to handle. You can use if, else if, and else statements for a few different uses. Usually you use them to check the state of something. To see if something equals a certain value we use the operator '=='. You can also use '!=' when trying to see if something Doesn't equal, you can use the greater than or less than symbols '>', '<', '<=', '>='

    
int x = 3;
if(x == 3)
{
System.out.println("X is 3");
}
else if(x != 3)
{
System.out.println("X doesn't equal 4");
}


The code above checks if the value of x is equal to 3 and if it is, it prints out 'X is 3' but in the else if statement if checks if x doesn't equal 3. And if you run this code you should get the output of 'X is 3'.

You can also use the symbols '&&' which means 'and' or you can use '||' which means 'or'.

    
int x = 3;
double y = 3.14;
if(x == 3 && y > x){
System.out.println("x is 3 and y is greater than x");
}

This checks if x equals 3 and if y is greater then x.
    
int x = 4;
if(x == 3 || x < 5)
{
System.out.println("X is either 3 or is less than 5");
}

This checks if x is 3 or if x is less than 5.



Math Operators + Increment Operator

While programming, you're probably going to use math operators frequently. Math operators are the simplest things to understand if you've ever been in a math class. You can use them for stuff like adding (+), subtracting (-), multiplication (*), dividing (/), you can even use the % to find the remainder of two numbers.

Here is a simple function adding two two ints together.
    
int cats, dogs, animals;
cats = 3;
dogs = 4;
animals = cats + dogs;
System.out.println(animals);


Increment operators allow you to add 1 to a variable. So say you had an int called bob and its value was 5, to add one to it you could do the following:
    
int bob = 5;
++bob;
System.out.println(bob);

This would output 6, because you're adding one to bob which is at 5. ( 5 + 1 = 6). You also could have done:
    
int bob = 5;
System.out.println(++bob);

This is called pre incrementing. This outputs 6 as well because it increases by one before it prints the line.

Now if you were to do that like this
    
int bob = 5;
System.out.println(bob++);

It would output 5 instead of 6 because bob is increased by one After it is printed. This is called post incrementing. So if you ran the following code
    
int bob = 5;
System.out.println(bob++);
System.out.println(bob);

It would output 5 then 6 because bob is increased by 1 after the first println.

Sorry for cutting this tutorial short, but it's current 3:12am and I'm tired as shit, so I'll continue this tutorial series tomorrow. My plans for future lessons are:
    
if statements
Math Operations
Logics
switch statements + more!




Want more tutorials? Don't worry after this one I'll be doing:
    
Javascript
C
And Possibly some simple game programming
Last edited by Black Panther ; 06-15-2014 at 08:21 PM.

The following 5 users say thank you to Black Panther for this useful post:

Complete Speed, Conveyy, DS, Notorious, Source Code
06-15-2014, 08:21 PM #2
Updated with more lessons.
06-22-2014, 12:35 PM #3
Notorious
Caprisuns Is Back
Originally posted by BlackPanther View Post
I've notice that this section is dead, and all of the 'C# Devs' post on the PS3 Sections, so I decided to type up some tutorials for this section for a few reasons.

1.) Bring some more people to this section
2.) Get some new developers developing in a different language other than C#

So let's begin shall we?

Downloading the JDK

In order to compile Java programs, you're going to need to download/install the JDK. So to get the JDK head over to You must login or register to view this content. and download the JDK for your platform. After you have it downloaded, just install it via the install wizard.

After that we can go ahead and download Eclipse. Eclipse is a tool that you can use to write and compile java programs. You can also use Eclipse to make simple Java games and even program your own Android Applications!

To find Eclipse head over to You must login or register to view this content. and download the 'Eclipse IDE for Java EE Developers'

You must login or register to view this content.


Download that for your OS and it should come in a rar file like this

You must login or register to view this content.


Just extract that to your desktop or where ever you see fit! Then to start Eclipse, simply run 'eclipse.exe'

If it's your first time running eclipse it will ask you to set up a workspace, this is where all your coding and projects will go. You can set it to where ever you want!

You must login or register to view this content.


After that, to start a new project, navigate to 'File' > 'New' > 'Project' > 'Java Project'. After that, you can name the project whatever you want. After that, just click Finish. After that you will have your new project opened.

Next, navigate to your project folder and expand it, you should see two folders called 'src' and 'JRE System Library' What you want to do, is right click on 'src' > 'New' > 'Class'. After that you will see this:
You must login or register to view this content. Just name the class whatever you want and click finish. After that you will be able to see some pre-written code.

Congratulations, you have successfully downloaded/installed the JDK Smile



Making A Hello World Program


If you completed the first step properly, you should have some pre-written code that looks like this:

    

public class FirstClass {

}


Now, if you're some what familiar with any other programming languages, you will know that the most basic of programs use some sort of a 'main' function. We are going to make that in our class. To make this main function all you need to do is write the following:

    

public class FirstClass {
public static void main(String args[]){

}
}


Now for the final part of this 'mini tutorial' we are going to print a line with our 'Hello World' text. For this we use the 'System.out.println function.

    

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


Now to compile/Run this program just click the green arrow under the 'Refactor' tab. After that you should see the output here:
You must login or register to view this content.

Felicidades, you have made your first hello world program in Java!


Variables

Variables are an easy concept to grasp. If you ever been in the most simplest algebra class you should know what a variable is. A variable pretty much is just a place holder. It holds information. Just like the equation
'9=x*2' x is the variable because it holds the value of 4.5.

In java you can use variables to hold the values of text (String), integers (int), floats (float), decimal numbers (double), chars, etc.

Let's make a simple function to add a double and an integer together, hell, let's even use a string in there too.

Now, this isn't the best way to code this, but since if you're reading this, you're probably not the best at coding so it's too show you.

First, declare a double and call it whatever you want, I'll call mine 'a', set this to whatever you want. Next declare an int and set it to whatever you want, and for mine, I'm going to use a string with the text of '4.5 + 4 = " (Those being the numbers I am using) After that just make another double that equals the int and the first double together, and then print a line adding the string and the sum of the int + 1stDouble.

Like this:
    

public class FirstClass {
public static void main(String args[]){
double a = 4.5;
int b = 4;
double c = a + b;
String d = "4.5 + 4 = ";
System.out.println(d + c);
}
}

If you did this correctly you should output '4.5 + 4 = 8.5'

There are more variables that can be used in Java but for now I will stick to using these simple vars.


Scanners

A Scanner is a type of variable you can use to gather input from the computer or whatever the user is typing, etc. But to use this, you're going to need to import it. To do this, just type this about your class 'import java.util.Scanner;' After this you are going to want to declare the scanner like this.

    
import java.util.Scanner;

public class FirstClass {
public static void main(String args[]){
Scanner getIn = new Scanner(System.in);//You Can Name it whatever you want
System.out.println(getIn.nextLine() + " was your input");//You need the .nextLine()
}
}

Basically what this function is doing, is declaring the Scanner 'getIn' and printing a line with the input from getInt with the text ' was your input'.

Your output should look like this:
You must login or register to view this content.


If Statements

If statements are an easy concept to handle. You can use if, else if, and else statements for a few different uses. Usually you use them to check the state of something. To see if something equals a certain value we use the operator '=='. You can also use '!=' when trying to see if something Doesn't equal, you can use the greater than or less than symbols '>', '<', '<=', '>='

    
int x = 3;
if(x == 3)
{
System.out.println("X is 3");
}
else if(x != 3)
{
System.out.println("X doesn't equal 4");
}


The code above checks if the value of x is equal to 3 and if it is, it prints out 'X is 3' but in the else if statement if checks if x doesn't equal 3. And if you run this code you should get the output of 'X is 3'.

You can also use the symbols '&&' which means 'and' or you can use '||' which means 'or'.

    
int x = 3;
double y = 3.14;
if(x == 3 && y > x){
System.out.println("x is 3 and y is greater than x");
}

This checks if x equals 3 and if y is greater then x.
    
int x = 4;
if(x == 3 || x < 5)
{
System.out.println("X is either 3 or is less than 5");
}

This checks if x is 3 or if x is less than 5.



Math Operators + Increment Operator

While programming, you're probably going to use math operators frequently. Math operators are the simplest things to understand if you've ever been in a math class. You can use them for stuff like adding (+), subtracting (-), multiplication (*), dividing (/), you can even use the % to find the remainder of two numbers.

Here is a simple function adding two two ints together.
    
int cats, dogs, animals;
cats = 3;
dogs = 4;
animals = cats + dogs;
System.out.println(animals);


Increment operators allow you to add 1 to a variable. So say you had an int called bob and its value was 5, to add one to it you could do the following:
    
int bob = 5;
++bob;
System.out.println(bob);

This would output 6, because you're adding one to bob which is at 5. ( 5 + 1 = 6). You also could have done:
    
int bob = 5;
System.out.println(++bob);

This is called pre incrementing. This outputs 6 as well because it increases by one before it prints the line.

Now if you were to do that like this
    
int bob = 5;
System.out.println(bob++);

It would output 5 instead of 6 because bob is increased by one After it is printed. This is called post incrementing. So if you ran the following code
    
int bob = 5;
System.out.println(bob++);
System.out.println(bob);

It would output 5 then 6 because bob is increased by 1 after the first println.

Sorry for cutting this tutorial short, but it's current 3:12am and I'm tired as shit, so I'll continue this tutorial series tomorrow. My plans for future lessons are:
    
if statements
Math Operations
Logics
switch statements + more!




Want more tutorials? Don't worry after this one I'll be doing:
    
Javascript
C
And Possibly some simple game programming


Nice tutorial Smile
07-02-2014, 06:37 PM #4
m3u
Save Point
Originally posted by BlackPanther View Post
I've notice that this section is dead, and all of the 'C# Devs' post on the PS3 Sections, so I decided to type up some tutorials for this section for a few reasons.

1.) Bring some more people to this section
2.) Get some new developers developing in a different language other than C#

So let's begin shall we?

Downloading the JDK

In order to compile Java programs, you're going to need to download/install the JDK. So to get the JDK head over to You must login or register to view this content. and download the JDK for your platform. After you have it downloaded, just install it via the install wizard.

After that we can go ahead and download Eclipse. Eclipse is a tool that you can use to write and compile java programs. You can also use Eclipse to make simple Java games and even program your own Android Applications!

To find Eclipse head over to You must login or register to view this content. and download the 'Eclipse IDE for Java EE Developers'

You must login or register to view this content.


Download that for your OS and it should come in a rar file like this

You must login or register to view this content.


Just extract that to your desktop or where ever you see fit! Then to start Eclipse, simply run 'eclipse.exe'

If it's your first time running eclipse it will ask you to set up a workspace, this is where all your coding and projects will go. You can set it to where ever you want!

You must login or register to view this content.


After that, to start a new project, navigate to 'File' > 'New' > 'Project' > 'Java Project'. After that, you can name the project whatever you want. After that, just click Finish. After that you will have your new project opened.

Next, navigate to your project folder and expand it, you should see two folders called 'src' and 'JRE System Library' What you want to do, is right click on 'src' > 'New' > 'Class'. After that you will see this:
You must login or register to view this content. Just name the class whatever you want and click finish. After that you will be able to see some pre-written code.

Congratulations, you have successfully downloaded/installed the JDK Smile



Making A Hello World Program


If you completed the first step properly, you should have some pre-written code that looks like this:

    

public class FirstClass {

}


Now, if you're some what familiar with any other programming languages, you will know that the most basic of programs use some sort of a 'main' function. We are going to make that in our class. To make this main function all you need to do is write the following:

    

public class FirstClass {
public static void main(String args[]){

}
}


Now for the final part of this 'mini tutorial' we are going to print a line with our 'Hello World' text. For this we use the 'System.out.println function.

    

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


Now to compile/Run this program just click the green arrow under the 'Refactor' tab. After that you should see the output here:
You must login or register to view this content.

Felicidades, you have made your first hello world program in Java!


Variables

Variables are an easy concept to grasp. If you ever been in the most simplest algebra class you should know what a variable is. A variable pretty much is just a place holder. It holds information. Just like the equation
'9=x*2' x is the variable because it holds the value of 4.5.

In java you can use variables to hold the values of text (String), integers (int), floats (float), decimal numbers (double), chars, etc.

Let's make a simple function to add a double and an integer together, hell, let's even use a string in there too.

Now, this isn't the best way to code this, but since if you're reading this, you're probably not the best at coding so it's too show you.

First, declare a double and call it whatever you want, I'll call mine 'a', set this to whatever you want. Next declare an int and set it to whatever you want, and for mine, I'm going to use a string with the text of '4.5 + 4 = " (Those being the numbers I am using) After that just make another double that equals the int and the first double together, and then print a line adding the string and the sum of the int + 1stDouble.

Like this:
    

public class FirstClass {
public static void main(String args[]){
double a = 4.5;
int b = 4;
double c = a + b;
String d = "4.5 + 4 = ";
System.out.println(d + c);
}
}

If you did this correctly you should output '4.5 + 4 = 8.5'

There are more variables that can be used in Java but for now I will stick to using these simple vars.


Scanners

A Scanner is a type of variable you can use to gather input from the computer or whatever the user is typing, etc. But to use this, you're going to need to import it. To do this, just type this about your class 'import java.util.Scanner;' After this you are going to want to declare the scanner like this.

    
import java.util.Scanner;

public class FirstClass {
public static void main(String args[]){
Scanner getIn = new Scanner(System.in);//You Can Name it whatever you want
System.out.println(getIn.nextLine() + " was your input");//You need the .nextLine()
}
}

Basically what this function is doing, is declaring the Scanner 'getIn' and printing a line with the input from getInt with the text ' was your input'.

Your output should look like this:
You must login or register to view this content.


If Statements

If statements are an easy concept to handle. You can use if, else if, and else statements for a few different uses. Usually you use them to check the state of something. To see if something equals a certain value we use the operator '=='. You can also use '!=' when trying to see if something Doesn't equal, you can use the greater than or less than symbols '>', '<', '<=', '>='

    
int x = 3;
if(x == 3)
{
System.out.println("X is 3");
}
else if(x != 3)
{
System.out.println("X doesn't equal 4");
}


The code above checks if the value of x is equal to 3 and if it is, it prints out 'X is 3' but in the else if statement if checks if x doesn't equal 3. And if you run this code you should get the output of 'X is 3'.

You can also use the symbols '&&' which means 'and' or you can use '||' which means 'or'.

    
int x = 3;
double y = 3.14;
if(x == 3 && y > x){
System.out.println("x is 3 and y is greater than x");
}

This checks if x equals 3 and if y is greater then x.
    
int x = 4;
if(x == 3 || x < 5)
{
System.out.println("X is either 3 or is less than 5");
}

This checks if x is 3 or if x is less than 5.



Math Operators + Increment Operator

While programming, you're probably going to use math operators frequently. Math operators are the simplest things to understand if you've ever been in a math class. You can use them for stuff like adding (+), subtracting (-), multiplication (*), dividing (/), you can even use the % to find the remainder of two numbers.

Here is a simple function adding two two ints together.
    
int cats, dogs, animals;
cats = 3;
dogs = 4;
animals = cats + dogs;
System.out.println(animals);


Increment operators allow you to add 1 to a variable. So say you had an int called bob and its value was 5, to add one to it you could do the following:
    
int bob = 5;
++bob;
System.out.println(bob);

This would output 6, because you're adding one to bob which is at 5. ( 5 + 1 = 6). You also could have done:
    
int bob = 5;
System.out.println(++bob);

This is called pre incrementing. This outputs 6 as well because it increases by one before it prints the line.

Now if you were to do that like this
    
int bob = 5;
System.out.println(bob++);

It would output 5 instead of 6 because bob is increased by one After it is printed. This is called post incrementing. So if you ran the following code
    
int bob = 5;
System.out.println(bob++);
System.out.println(bob);

It would output 5 then 6 because bob is increased by 1 after the first println.

Sorry for cutting this tutorial short, but it's current 3:12am and I'm tired as shit, so I'll continue this tutorial series tomorrow. My plans for future lessons are:
    
if statements
Math Operations
Logics
switch statements + more!




Want more tutorials? Don't worry after this one I'll be doing:
    
Javascript
C
And Possibly some simple game programming


I like this.
07-02-2014, 06:49 PM #5
Originally posted by m3u View Post
I like this.


Thanks I totally forgot about this. Since you reminded me I'll continue

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo