[OTHER] [Java] An Introduction to Java

jumper7224

Newbie
Messages
71
Reaction score
0
[Java] An Introduction to Java

Hey guys, I haven't seen anything about Java, so this is for anybody looking for a brief introduction :smile: I'll try to keep things short and concise. This is just a brief introduction to Java, and should get you up and running, this is for any beginner who wants to learn a language, or for a returning veteran wanting to pick up something new.

Alright, let's get started...

What Is Java?
In short, the child of C++ and SmallTalk, two programming languages. Anybody wanting to learn Java, who knows C++, will have to learn a couple of small differences, but the syntax is generally the same.
In not so short, Java takes the best of both C++ and SmallTalk to form an object-oriented byte language. (stay with me, I'll explain) This means that the creator of Java (Sun Microsystems, "Sun" from now on) took the best of C++ and SmallTalk, throwing out some things as they went. "Object-oriented" is almost as complicated as it sounds; it means that the computer does not just follow the instructions laid out in the program, it can create "objects" which are programmer-created variables with their own member variables and member functions (all functions are called methods, so I'll use that from now on). Member variables are variables (such as x = 5) that belong to an object, and a method is like a process that the programmer has defined. If you have no idea what I'm talking about, don't worry about it- I'll explain later.

Advanced Note: Java is also a byte level language, this means that a Java source file is NOT translated into machine code, but byte code for faster compilation and better debugging capabilities, with this comes a draw back; you cannot do any sort of machine-level code functions, such as make a .exe file from Java source code.

What Do I Need to Get Started?
A compiler. I STRONGLY recommend JCreator LE for two reasons; 1- It does everything you've ever wanted (compiles, debugs, has built-in console for programs), 2- I'm going to use it from here on out. You can find it here: JCreator — Java IDE (download the correct version... if you can't figure that out than you shouldn't be reading this :biggrin: )
Once that's done install. When you first boot up JCreator it asks you for some java files so JCreator knows what it's doing...
so lets go hunt them down, shall we?
Note: use Configure -> Options -> JDK Profiles. to edit the files if you lost the pop-up.
Here's how mine are set up:
C:\Program Files\Java\jdk1.6.0_12\jre\lib\rt.jar;
C:\Program Files\Java\jdk1.6.0_12\lib\dt.jar;
C:\Program Files\Java\jdk1.6.0_12\lib\tools.jar;
C:\Program Files\Java\jdk1.6.0_12\jre\lib\ext\dnsns.jar;
C:\Program Files\Java\jdk1.6.0_12\jre\lib\ext\localedata.jar;
C:\Program Files\Java\jdk1.6.0_12\jre\lib\ext\sunjce_provider.jar;
C:\Program Files\Java\jdk1.6.0_12\jre\lib\ext\sunmscapi.jar;
C:\Program Files\Java\jdk1.6.0_12\jre\lib\ext\sunpkcs11.jar;
and...
C:\Program Files\Java\jdk1.6.0_12\src.exe

the src.exe goes under the "source" tab (surprise) and the .jar files go under the "classes" tab.

So Where Do I Get the Files?
I'm going, I'm going- you'll thank me for this stuff later. Right, remember Sun? Time to stop in and grab some stuff. Sun's site is sometimes a pain, so let me make it super simple: download the one labeled "JDK 6 Update 17". Yes, that means the abbreviation is jdk1.6.0_17 which isn't jdk1.6.0_12, it doesn't matter. Download and install to the STANDARD path. (Faster compilation, easier to find. "But I wanna install it to my desktop!" Well little Johnny, don't listen to the guy writing the tutorial- see where that gets you.)

***The above step is CRITICAL and VERY ANNOYING***
So if you need help follow these steps;
1- look below to see if anybody had the same problem and do what someone replied to them said to do.
2- make a new post on the end of this tutorial, I will check often because I have no life.
3- PM me...

Right, you (hopefully) have everything set up and you're ready for your first program!

Staying with tradition, we'll be doing a "Hello World" program.

-Start up JCreator (or whatever you decided to use)
-I personally close the tab that comes up... mainly because it doesn't say anything useful. Thank you Sun.
-File -> New -> File -> Java Classes (folder, left box) -> Empty Java File (right box)
-Name the new file HelloWorld
***name it this or the code won't work, i'm kidding... kinda***
-Here's the code:
Code:
//programmer: YOUR NAME 
//***this is a note comment, all of my note comments start with ***
//<--- anything after the "//" will be IGNORED by the compiler
//so you can write notes in here, or talk to yourself, like i'm technically doing.
/* This is a block comment or a multi line comment, they begin with /* 
and end with */
/*shocker,
you can write comments for multiple lines
weird...
*/

public class HelloWorld{
//*** an explanation of the previous line, bit by bit
/*public - a privacy modifier, not important to know right now, I'll explain later
class - a variable identifier, also not important right now, will explain later
HelloWorld - where have I seen this before? 
Answer: it's the name of the source code file you created, 
and you thought i was joking...
this MUST match your file name EXACTLY, as in CASE SENSITIVE 
(so x doesn't equal X) */

public static void main(String[] args){
//***don't worry about this line, for now just know that this is a method
//named main, and that it's the first method called by the computer
//NO MATTER WHAT

System.out.println("Hello World, I work");
//***ah, the meat of our first program
/*System.out.println(STRING) - a little advanced, but you got it rookie
this method is passed a string which is outputted to the console
nothing to fancy- try playing with the string
note how this line end in a semi colon (;)
this is taken from C++, everything that doesn't end in a curly bracket 
ends in a semicolon */ 

} // curly brackets tell the compiler where to start and end things
// in this case main

// end of program curly bracket
}

So, you're officially a Java programmer. Hat's off to you good sir / madam. Now, you have homework: completely mess with this code. What happens when you delete something, like a semi colon? or a curly bracket? Yes, I'm telling you CREATE YOUR OWN ERRORS. This is so when you do forget a semicolon for real, you'll recognize the error given and be able to fix it rather quickly.


That said... this is my first tutorial, so multiple things; sorry if I'm not allowed to post tutorials, I'll gladly take this down and submit it if I have to do something like that. Please give me feedback... but not "ZOMGWTFBBQ" crap, real stuff- I would like to improve this tutorial.

Thanks,
Jumper
 

TehPhelix

VIP
VIP
Retired
Messages
7,665
Reaction score
7,350
Re: [Java] An Introduction to Java

Not a bad tutorial, very simple and such. I personally prefer Eclipse as I find it a better GUI and simpler overall but they both get the task done. Just as a future FYI use /* rather then // every line, makes it a bit easier to read in my opinion.
 

jumper7224

Newbie
Messages
71
Reaction score
0
Re: [Java] An Introduction to Java

Thanks mate :smile:

haha i forgot about block comments :tongue: *updated*

I'm in a class right now learning C++, and we're using eclipse... I have to say, I'm not a fan- it's nice and everything, but I'm WAY to use to JCreator, not a whole lot of bells and whistles to mess around with in JCreator, so I think it's a little nicer for a beginner; not as much of a shock.
 

TehPhelix

VIP
VIP
Retired
Messages
7,665
Reaction score
7,350
Re: [Java] An Introduction to Java

jumper7224 said:
Thanks mate :smile:

haha i forgot about block comments :tongue: *updated*

I'm in a class right now learning C++, and we're using eclipse... I have to say, I'm not a fan- it's nice and everything, but I'm WAY to use to JCreator, not a whole lot of bells and whistles to mess around with in JCreator.
I think it really comes down to what you used first and got use to the most. They all do relatively the same thing just some have more advanced features to tweak and add things. Either way the job gets done.
 
Top Bottom