April 25, 2024, 04:57:01 pm

Author Topic: Java for beginners - The very first steps  (Read 5709 times)

0 Members and 1 Guest are viewing this topic.

bigbeno37

  • Sr. Member
  • **
  • Posts: 318
  • We are all born with a purpose in life
    • View Profile
Java for beginners - The very first steps
« on: May 04, 2012, 07:45:14 am »
--------------BEFOREHAND--------------

Tutorial 2: Learning about integers!
At http://www.opticraft.net/index.php/topic,9697.0.html
We learn about integers, doubles, and even scanners!

Tutorial 3: Making the calculator!
At http://www.opticraft.net/index.php/topic,9729.0.html
We 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 steps

VIDEO IS UP! GO VISIT IT AT http://www.youtube.com/watch?v=-NULQU2U2qU&feature=youtu.be

So, 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.html
Once 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:

Code: [Select]
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.

Code: [Select]
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
« Last Edit: May 19, 2012, 09:17:11 am by bigbeno37 »


"We are all born on this planet with a purpose in life," This quote keeps me going during the day, always trying to find that answer.

DeeKay

  • Owner
  • Champion Member
  • *****
  • Posts: 2162
    • View Profile
Re: Java for beginners - The very first steps
« Reply #1 on: May 04, 2012, 07:50:38 am »
I'm learning java too, and although I may know half of this, it's still a great help for noobs like me :P

bigbeno37

  • Sr. Member
  • **
  • Posts: 318
  • We are all born with a purpose in life
    • View Profile
Re: Java for beginners - The very first steps
« Reply #2 on: May 04, 2012, 07:52:51 am »
Thanks xDeeKay. I do sincerely hope that this helps newbies start off in the big world of Java programming. Oh, and by the way, if this gets enough demand, I could do further tutorials, each progressively getting more and more advanced.


"We are all born on this planet with a purpose in life," This quote keeps me going during the day, always trying to find that answer.

omaroo2

  • OptiCraft's Pharaoh.
  • Hero Member
  • **
  • Posts: 927
  • PSN: UnlimitedEra Steam: UnlimitedEra
    • View Profile
Re: Java for beginners - The very first steps
« Reply #3 on: May 08, 2012, 10:47:04 am »
Awesome :P
I will learn java once I finish HTML and XHTML and Dreamweaver CS4 :P


bigbeno37

  • Sr. Member
  • **
  • Posts: 318
  • We are all born with a purpose in life
    • View Profile
Re: Java for beginners - The very first steps
« Reply #4 on: May 08, 2012, 11:05:23 am »
Awesome :P
I will learn java once I finish HTML and XHTML and Dreamweaver CS4 :P

Best of luck with that, and thanks at looking my guide

Shall I continue on with the tutorials? I can start teaching regarding the implementation of Integers.
Merged topic ~Omaroo2
« Last Edit: May 08, 2012, 11:56:21 am by omaroo2 »


"We are all born on this planet with a purpose in life," This quote keeps me going during the day, always trying to find that answer.

omaroo2

  • OptiCraft's Pharaoh.
  • Hero Member
  • **
  • Posts: 927
  • PSN: UnlimitedEra Steam: UnlimitedEra
    • View Profile
Re: Java for beginners - The very first steps
« Reply #5 on: May 08, 2012, 11:56:42 am »
Sure, why not?


Unholy_Gibbon

  • The Nocturnal Op
  • Full Member
  • *
  • Posts: 210
    • View Profile
Re: Java for beginners - The very first steps
« Reply #6 on: May 08, 2012, 12:16:41 pm »
Shall I continue on with the tutorials? I can start teaching regarding the implementation of Integers.
Yes! I've wanted to get into coding for a while but all the books that I've come across go in at the deep end and don't explain the very basics at all.

On that note, does anyone know of any website, book or video series that can help out complete noobs such as myself to get to grip with the basic concepts of coding with java?

bigbeno37

  • Sr. Member
  • **
  • Posts: 318
  • We are all born with a purpose in life
    • View Profile
Re: Java for beginners - The very first steps
« Reply #7 on: May 08, 2012, 09:19:26 pm »
Shall I continue on with the tutorials? I can start teaching regarding the implementation of Integers.
Yes! I've wanted to get into coding for a while but all the books that I've come across go in at the deep end and don't explain the very basics at all.

On that note, does anyone know of any website, book or video series that can help out complete noobs such as myself to get to grip with the basic concepts of coding with java?

There is a video series by a fellow YouTuber called Thenewboston. Here is a link to his tutorials:

http://www.youtube.com/watch?v=Hl-zzrqQoSE

And on that note, it is time to make this prettier amd add in tutorial number 2!


"We are all born on this planet with a purpose in life," This quote keeps me going during the day, always trying to find that answer.

Xeadin

  • Board Gamer
  • Champion Member
  • ***
  • Posts: 2791
  • dip dip dip dip dip
    • View Profile
    • @Xeadin
Re: Java for beginners - The very first steps
« Reply #8 on: May 10, 2012, 02:18:51 am »
Bookmarked :3

This will come in handy in the near future. I have yet to delve into the coding world of Java itself.

bigbeno37

  • Sr. Member
  • **
  • Posts: 318
  • We are all born with a purpose in life
    • View Profile
Re: Java for beginners - The very first steps
« Reply #9 on: May 10, 2012, 04:11:13 am »


"We are all born on this planet with a purpose in life," This quote keeps me going during the day, always trying to find that answer.

Unholy_Gibbon

  • The Nocturnal Op
  • Full Member
  • *
  • Posts: 210
    • View Profile
Re: Java for beginners - The very first steps
« Reply #10 on: May 10, 2012, 04:09:40 pm »
Ok I think I'm gonna be the designated noob for these threads. I've already got 3 questions on this so far:

1. Is the "main" unrelated to the "Main" that we use for the name of the class/program? Also, why do I get errors if I alter the "Main" and "main" (even just by capitalising or de-capitalising the m/M)?

2. What does it mean when a method is "public" to any outside methods?

3. Am I right in assuming that what this code is effectively doing is naming the program, designating the way to run it, then assigning a task to be run using the method coded for? (In this case outputting the words "Hello World").

I'll get the hang of this coding lark one day.  ;D

SpikeyThorn

  • “Get your facts first, then you can distort them as you please.”
  • Hero Member
  • **
  • Posts: 525
  • -Griefer impaler-
    • View Profile
Re: Java for beginners - The very first steps
« Reply #11 on: May 10, 2012, 05:22:47 pm »
From my experience with python, Capitalization always seems to matter, not sure why

Might take up java :) I've found it a somewhat interesting language, i remember getting eclipse and JDK before, just altering minecraft, EG) dirt that gave of light, or faster breaking obsidian, but that was a while ago, and honestly, requires merely finding the breaking values, and light, and such...

Great guide though :)

bigbeno37

  • Sr. Member
  • **
  • Posts: 318
  • We are all born with a purpose in life
    • View Profile
Re: Java for beginners - The very first steps
« Reply #12 on: May 10, 2012, 09:24:38 pm »
Ok I think I'm gonna be the designated noob for these threads. I've already got 3 questions on this so far:

1. Is the "main" unrelated to the "Main" that we use for the name of the class/program? Also, why do I get errors if I alter the "Main" and "main" (even just by capitalising or de-capitalising the m/M)?

2. What does it mean when a method is "public" to any outside methods?

3. Am I right in assuming that what this code is effectively doing is naming the program, designating the way to run it, then assigning a task to be run using the method coded for? (In this case outputting the words "Hello World").

I'll get the hang of this coding lark one day.  ;D

Finally! Some questions!

Okay, so:

1) Java is a very...VERY strict programming language. If you forget to capitilize one word, the program falls to shreds. And when you do 'class Main', that's setting the class and the 'public static void main(String[] args)', that's setting the method called 'main'. Without the 'main' method, the java program WILL NOT run, as it needs somewhere to start.

2) Well, as I said in the tutorial, that there is a bit...advanced for complete beginners but basically of you make a public method, you're allowing outside classes to access it. Making outside classes is for a much later tutorial, so don't worry about it.

3) Yes, pretty much! Except for the 'naming the project'. In java, you can't really name a project, but instead you are naming the class and the methods.

I hope my answers answer your questions, and if you need any further help / advice, do not hesitate to PM me or reply to this forum.

Oh, and thanks for the compliment SpikeyThorn!  Means alot to me   ;D
« Last Edit: May 10, 2012, 09:27:22 pm by bigbeno37 »


"We are all born on this planet with a purpose in life," This quote keeps me going during the day, always trying to find that answer.

Unholy_Gibbon

  • The Nocturnal Op
  • Full Member
  • *
  • Posts: 210
    • View Profile
Re: Java for beginners - The very first steps
« Reply #13 on: May 11, 2012, 12:36:12 am »
Thanks for the answers, I think most of the things I don't understand at the moment will be clearer later on.

Saying that, I've already encountered difficulties on your 2nd tutorial. :S

Smiteme69

  • Full Member
  • *
  • Posts: 207
    • View Profile
Re: Java for beginners - The very first steps
« Reply #14 on: May 11, 2012, 08:10:13 am »
Very nice Bigbeno, I've not long done a course at Uni using Visual Studio coding in vb.net, and I fancy a go at java.
 Always game to gain more knowledge.