Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Main Index FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: Java:
The Basics of Java

 

 


Mr. Java
Newbie


Oct 10, 2007, 6:34 AM

Post #1 of 5 (254 views)
Shortcut
The Basics of Java Can't Post

Java Basics

You will need to download an IDE.

NetBeans

Eclipse

JBuilder

JCreator

Notepad


I use NetBeans, but its up to you what you want to use.
I am going to explain this tutorial as if I was using Notepad.

Open up you're IDE and enter this code:

NOTE: You do NOT learn from copy and pasting. Type it out yourself.


Quote




public class HelloWorld {

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




What it means:
System.out.println("Hello World!"); - It's pretty self explanatry. It wants the System to (output) print the line "Hello World". End code with ';'.


Now to move onto Strings and Integers. (Strings hold text, Integers hold numbers)


Quote

public class HelloWorld {

public static void main(String args[]) {
String STR = "Hello World!";
int INT1 = 5;
int INT2 = 3;

System.out.println(STR);
System.out.println(INT1);
System.out.println(INT1+INT2);

}
}


What it means:
String STR = "Hello World!"; - To create a string you need to start with 'String'. 'STR' is the name of the String which can be replaced to what you want. "Hello World" is the message that will be displayed.

int INT1 = 5; - To create an Integer you have to start with 'int'. Again, 'INT1' is the name of the Integer, which can be replaced to what you want. The number '5' is held in the Integer. Line 10 adds the two Integers together. (INT1+INT2);


Now to learn about Else..If.
NOTE: '==' means Equal to


Quote

public class ElseIf {

public static void main(String args[]) {
String DAY = "Tuesday";
String NOT = "The day is not Tuesday";

if (DAY == "Tuesday"){
System.out.println(DAY);
}
else{
System.out.println(NOT);
}

}
}


What it means:

if (DAY == "Tuesday"){ - This line of code is just pretty much saying: If the String 'Day' is/equals to 'Tuesday' then do the code below.

else{ - This line of code pretty much is saying: If the DAY isn't 'Tuesday' then do the code below.



Now you understand the basics, lets create a simple 'Odd or Even' application . I added some comments in the code. (Lines starting with '//' are comments, these are not debugged with the application.


Quote

import javax.swing.JOptionPane;

public class OddEven {
private int input;

public OddEven() {
// Creates the Input Dialog
input = Integer.parseInt(JOptionPane.showInputDialog("Enter a Number:"));
}

public void calculate() {
// If the 2% of the inputted number is equal to 0 then print "Even"
if (input % 2 == 0)
System.out.println("Even");
else
// If not, print "Odd"
System.out.println("Odd");
}

public static void main(String[] args) {
OddEven number = new OddEven();
number.calculate();
}
}




If you have any questions concerning this tutorial, please reply to this thread.

This tutorial was created completely from scratch by ME.
Do NOT use this tutorial on other forums WITHOUT my permission.
If you ask I will most likely say 'Yes' anyway. So theres no point in just stealing it ;)

I will be adding stuff to this. But I am tired right now.

END

EDIT:
Thanks for the sticky ;)


(This post was edited by Mr. Java on Oct 12, 2007, 4:32 AM)



Peach Pit
Veteran / Moderator


Oct 10, 2007, 8:10 AM

Post #2 of 5 (243 views)
Shortcut
Re: [Mr. Java] The Basics of Java [In reply to] Can't Post

Hi, thanks for the post. Just a tip if you wanted to edit it (I would but i'm not java literate), there are tags specifically for code:

Use them, and it will keep your formatting all nice and lined up.


bye.


Mr. Java
Newbie


Oct 10, 2007, 11:57 PM

Post #3 of 5 (236 views)
Shortcut
Re: [Peach Pit] The Basics of Java [In reply to] Can't Post

Thank you for the useful reply Peach Pit. I didn't see that ;)

I'll edit it now.

EDIT:
Gah, I'll edit it in a bit.


(This post was edited by Mr. Java on Oct 11, 2007, 12:14 AM)


Heix
Senior Member


Jan 2, 2008, 6:47 AM

Post #4 of 5 (172 views)
Shortcut
Re: [Mr. Java] The Basics of Java [In reply to] Can't Post

mr java was drunk last night




linkski23
Newbie

Aug 29, 2008, 4:37 AM

Post #5 of 5 (6 views)
Shortcut
Re: [Mr. Java] The Basics of Java [In reply to] Can't Post

[url=http://www.fallensword.com/?ref=1995902]

 
 
 


Search for (options) Web Design by Web Ideas - Page loaded in: 0.16 s on (CGI/1.1)