Ramen
Active Member
I see people constantly requesting other peoples help due to an inability to program on their own, so I figured I'd lay down the basics of Java. If you already know java, no need for you to continue, this will bore the hell out of you. For beginners, pay close attention and read this carefully to fully understand.
What is Java?
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. (source : http://en.wikipedia.org/wiki/Java_(programming_language))
What will you benefit from this tutorial
If you pay close attention and read this fully, you should be able to learn the basics of Java programming. Enough at least to begin working on one of the public RuneScape private servers sources, anyways.
Alright! Enough of this, let's begin.
Part 1: New file.
To create a new file, you must ALWAYS name the file the same name you see in the first line of coding. For example, if the file was named "NewClass.java", the first line of coding (besides imports), would look something like this:
Anywhere beneath this is where you can put any source coding. Declare variables, methods, etc. below this point. Here is an example class file:
Part 2: Breaking it down.
In the above you will see five different variables. You should see an integer, boolean, string, character, and string array. Let's take a look at what each of those actually does.
Integer:
An integer is a whole number which value is less than or equal to the Java max integer (a bit over two billion). It can not be a decimal, and is declared as "int".
Boolean:
A boolean is a basic on-off switch. It can only be true or false. It is declared as "boolean".
String:
A string is generally a phrase and is contained in quotation marks. It is declared as "String".
Character:
A character is an alphabetical or numerical character. For example, the letter A would be enclosed in single quotation marks such as 'a'. It is declared as "char".
Arrays:
An array is a little trickier than the others simply because it can return more than one value. Let's take a closer look at the String[] in the example class.
When creating an array (of any type), it is enclosed in brackets and the information on the inside is separated by commas. The first piece of data an array ALWAYS starts at zero, not 1. For example, if you were to call upon exampleStringArray[0], it would return "First line of text.", just as exampleStringArray[1] would return "Second line of text.".
Voids:
A void is generally a block of coding where several commands are executed inside it. You can do just about anything inside of a void. A void can also be declared with an argument. (See exampleVoid2 in the example class).
Executing a class file:
To have an executable class file, it always has to contain this block of code:
Where the commented area (The text after the "//") is where you would put any coding required to boot up the program. For example, to make a program state "Example program." in the debug window, the main void would look like this:
Another key factor when programming is that every block of code where you add a "{", you ALWAYS have to have a "}" later on to close the block.
This tutorial has been a basic example of declarations, making a basic class file, executing a class file, and making blocks of code inside.
Further information
Say good bye to notepad! Get an IDE. Some good ones are Netbeans, Eclipse, JCreator, and many others.
Is you java up to date? http://www.java.com/en/download/index.jsp
Do you have the Java Development Kit (JDK) required to start java programming? http://java.sun.com/javase/downloads/index.jsp
I hope this tutorial will help some people interested in beginning java programming. It's simple, but it should clear up what's what in those files you look through.
Happy programming.
What is Java?
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture. (source : http://en.wikipedia.org/wiki/Java_(programming_language))
What will you benefit from this tutorial
If you pay close attention and read this fully, you should be able to learn the basics of Java programming. Enough at least to begin working on one of the public RuneScape private servers sources, anyways.
Alright! Enough of this, let's begin.
Part 1: New file.
To create a new file, you must ALWAYS name the file the same name you see in the first line of coding. For example, if the file was named "NewClass.java", the first line of coding (besides imports), would look something like this:
Code:
public class NewClass {
Anywhere beneath this is where you can put any source coding. Declare variables, methods, etc. below this point. Here is an example class file:
Code:
public class NewClass {
public int exampleInteger = 0;
public boolean exampleBoolean = false;
public String exampleString = "This is a line of text.";
public char exampleCharacter = 'a';
public String[] exampleStringArray = {"First line of text.","Second line of text."};
public void exampleVoid1() {
exampleVoid2(true);
}
public void exampleVoid2(boolean boolean_) {
if (boolean_) {
System.out.println("The variable 'boolean_' is"+boolean_+".");
} else {
return;
}
}
public boolean exampleBoolean2() {
if (exampleBoolean) {
return true;
}
return false;
}
public static void main(String args[]) {
// Main program execution
}
}
Part 2: Breaking it down.
In the above you will see five different variables. You should see an integer, boolean, string, character, and string array. Let's take a look at what each of those actually does.
Integer:
An integer is a whole number which value is less than or equal to the Java max integer (a bit over two billion). It can not be a decimal, and is declared as "int".
Boolean:
A boolean is a basic on-off switch. It can only be true or false. It is declared as "boolean".
String:
A string is generally a phrase and is contained in quotation marks. It is declared as "String".
Character:
A character is an alphabetical or numerical character. For example, the letter A would be enclosed in single quotation marks such as 'a'. It is declared as "char".
Arrays:
An array is a little trickier than the others simply because it can return more than one value. Let's take a closer look at the String[] in the example class.
Code:
public String[] exampleStringArray = {"First line of text.","Second line of text."};
When creating an array (of any type), it is enclosed in brackets and the information on the inside is separated by commas. The first piece of data an array ALWAYS starts at zero, not 1. For example, if you were to call upon exampleStringArray[0], it would return "First line of text.", just as exampleStringArray[1] would return "Second line of text.".
Voids:
A void is generally a block of coding where several commands are executed inside it. You can do just about anything inside of a void. A void can also be declared with an argument. (See exampleVoid2 in the example class).
Executing a class file:
To have an executable class file, it always has to contain this block of code:
Code:
public static void main(String args[]) {
// Do any arguments here.
}
Where the commented area (The text after the "//") is where you would put any coding required to boot up the program. For example, to make a program state "Example program." in the debug window, the main void would look like this:
Code:
public static void main(String args[]) {
System.out.println("Example program.");
}
Another key factor when programming is that every block of code where you add a "{", you ALWAYS have to have a "}" later on to close the block.
This tutorial has been a basic example of declarations, making a basic class file, executing a class file, and making blocks of code inside.
Further information
Say good bye to notepad! Get an IDE. Some good ones are Netbeans, Eclipse, JCreator, and many others.
Is you java up to date? http://www.java.com/en/download/index.jsp
Do you have the Java Development Kit (JDK) required to start java programming? http://java.sun.com/javase/downloads/index.jsp
I hope this tutorial will help some people interested in beginning java programming. It's simple, but it should clear up what's what in those files you look through.
Happy programming.










