--------------BEFOREHAND--------------Tutorial 2: Learning about integers!
At
http://www.opticraft.net/index.php/topic,9697.0.htmlWe learn about integers, doubles, and even scanners!Tutorial 3: Making the calculator!
At
http://www.opticraft.net/index.php/topic,9729.0.htmlWe use what we have learnt and summarize it to make a simple, yet good program!Changelog:
0.1: Made the first template for my Java tutorials
0.2: Improved on the template
0.3: Made a 'BEFOREHAND' section at the top of the template.
CURRENT: 0.3.1: Making all my posts have the same ending, beforehand, and question score guide.
JAVA TUTORIAL #1 - The very first stepsVIDEO IS UP! GO VISIT IT AT http://www.youtube.com/watch?v=-NULQU2U2qU&feature=youtu.beSo, I have been learning Java now for a little while, and, although I am not an expert at it yet, I would like to start helping beginners start coding some basic Java.
--------------INSTALLING THE JDK--------------First of all, before we even begin, I will need you to go get the JDK. The JDK stands for
Java Developmental Kit, and it is essential for us to even start coding Java.
To get the JDK, go to
http://www.oracle.com/technetwork/java/javase/downloads/index.htmlOnce there, press on the 'Java' icon. It will take you to a new page. Once here, scroll down a little bit until you see
Java SE Development Kit X, with X being the version number. Underneath, you should see an 'Accept license agreement' option. Press on that, and scroll down some more. Now choose the correct JDK for your system and proceed to downloading it. It will be about 100 - 300 MB's, all depending on what OS you choose. Once downloaded, proceed to installing it.
--------------INSTALLING ECLIPSE--------------Once completely finished with the JDK, you will need to download a proper Java coding program. We will use one by the name of
Eclipse.
Eclipse is the program most people use to code and develop Java programs. To get Eclipse, go to the downloads page:
http://www.eclipse.org/downloads/ Once at the Eclipse site, download the specific Eclipse for your version of OS. If you an operating system besides Windows, at the top it will say
Eclipse Indigo (X.X) Packages for, with X.X being once again the version number. Press on the box next to this and it will contain the other supported OS's.
--------------SETTING UP ECLIPSE--------------Once downloaded, extracted, and Eclipse is up and running, you are ready to start programming your first piece of Java code. This will be the simple 'Hello World' program.
To start writing code, we must create a new class. To do this, look to the top of Eclipse and you will press file > new > Java Project. This will open up a window with a variety of different options. All you need to worry about is the project name. Name it whatever you want, and finish by pressing 'Finish'.
Now on the left side of Eclipse you should see the name of the project you made. If you hover over this, you will see an arrow. Press on it, and it should contain two things; src and JRE System Library. Right click on src and press new > Class. Name it 'Main' and press Finish.
Now a blank white window should have popped up, allowing you to type. Now that we're at this stage, let's begin with basically the first piece of code any Java programmer started off with.
--------------'HELLO WORLD' PROGRAM--------------To start off with, please type in the following code:
class Main{
public static void main(String[] args){
System.out.println("Hello World");
}
}
Now, at first, you will not get it if you have never done any programming before, so I will explain to you now what it does. If you copy the below code into Eclipse, the green notes will be the notes you should look at. Otherwise, the text after the '//' is what you need to look at.
class Main{
//Here we're starting up a new program, or class, by the name of 'Main' by using class [Name].
public static void main(String[] args){
//Here we are setting up the 'main' code. When running programs, Java first looks for this, and without it, the program
//will not run. Instead, it will pop up error after error. Do not worry about what 'public', 'static', 'void', or 'String[] args'
//is, as you are only jsut beginning Java. This is for more advanced users.
System.out.println("Hello World");
//Here we are printing out, or displaying, 'Hello World' to the console. We do this by using the inbuilt Java
//code 'System.out.println(""). Whatever is in the speaking marks will be what is output.
}
}
Either copy these or try to type these into Eclipse, and look for the green cirle with a white triangle in it. This is the 'run' icon, and it will be how you run future Java programs.
When ran, it shouldn't give any errors and just display at the bottom 'Hello World'. If that's what happened, then congratulations. You are on your way to learning the language of Java. To get this into your head, try re-writing this code and replacing 'Hello World' with something else.
--------------(Not necessary but advisable) PRACTISING YOUR LEARNT JAVA--------------To practise your Java so far, please answer these following question either in your head, on a piece of paper, or on a new word document:
1. What is a Method?
2. How do we print off some text on the screen?
3. What happens if instead of putting 'main(String[] args)', we put 'app(String[] args)'?
4. How many methods can there be of 'main' without any errors?
5. Take an educated guess regarding what the 'public' does in 'public static void main(String[] args)'.
The answers:
1. What is a Method?
A: A method is a way to run a certain program.
2. How do we print off some text on the screen?
A: To print off some text on the screen, we first make the class, then the 'main' method, then put 'System.out.println("Hello World");'
3. What happens if instead of putting 'main(String[] args)', we put 'app(String[] args)'?
A: Java will produce an error, as Java won't be able to find the 'main' method.
4. How many methods can there be of 'main' without any errors?
A: There can only be 1, due to the fact that if more than one 'main' method is declared, Java won't be able to tell which one to go to, thus producing an error.
5. Take an educated guess regarding what the 'public' does in 'public static void main(String[] args)'.
A: (Don't blame yourself if you don't get this right) 'public' in the line 'public static void main(String[] args)' means that that method is public to any outside methods.
SCORES:
< 3: Try to re-read this tutorial and keep more notes in your brain.
3: Okay, but perhaps try looking briefly over the tutorial and re-writing the code.
4: Good job! You are ready to move onto the next tutorial.
5: Outstanding! You are more than ready to move onto the next tutorial.
Regarding question 5, do not worry at all if you didn't get that right. That is going up quite a few tutorials, so once again, don't worry.
--------------END SECTION--------------This has been tutorial #1 of my Java for beginners series, so please leave a reply containing constructive criticism and if you need any help, don't fret to either PM me or leave a message on this forum. I will get back to you ASAP!
Next lesson:
http://www.opticraft.net/index.php/topic,9697.0.html