Buy VPN

Thursday, August 23, 2012

learn java 7 for android

AD: Create your own Programming Language


NOTE: If you are seeing this, this is a WIP so let me know what you think

You know, I've really been slacking on my java studies.  Shame too 'cause by now I should have been writing games and making apps. Sigh.  So you know what? I'm putting tutorials up on my blog to get myself motivated to get going again.  Maybe someone out there can learn better from someone on their level so here it goes.

tutorial 1)
Setting up your environment and writing your first app
 
I recommend linux.  Seriously F windows, go here right now

http://www.ubuntu.com/download/desktop/windows-installer

And get one of the most popular linux distros around.  I prefer slackware myself BUT Ubuntu makes it very easy for people new to linux.  This installs in windows and hurts nothing, you dont like it?  Simply uninstall.

Ok now that you have Ubuntu first thing you want to do it update ubuntu if you have the time or just go straight into setting up.

- Install the Java Development Kit, JDK by following the instructions here

http://www.webupd8.org/2011/09/how-to-install-oracle-java-7-jdk-in.html

it's simple, easy.

Once thats finished open up your terminal program
- Click dash home which is the very top icon on the left menu bar
- In search type terinal, click on terminal

- Type in the terimal: cd
 to make sure you are in your home directory
- Type: mkdir workspace
  or whatever you want to call your workspace
- Type: cd workspace
  to change into your folder/directory that you will use for your workspace

So I am a gamer and I want to make games so I will make these game oriented.  So lets write your first java program.

- In the terminal, type: nano Start.java
  This will bring up an editor where we will write the source code and will save it to Start.java upon exit.

- Inside the editor type:

/**
* Quick note here, anything here between the /** */  or anything on a line after // *is called a *comment.  You can use this space to write what this block of code is used for so when you come *back to it you will know what it is.  It is good *practice.
*This is a traditoinal hello world app with a gaming twist
*/

class StartApp {
// the class name must be the same as the file name
    public static void main(Strings[] args) {
        System.out.println("Press Start to begin");
    }
}

- Now hit Ctrl-X and it will prompt you to save and it should save to Start.java and drop you back to the terinal.
- In the terminal type: javac StartApp.java
  to compile StartApp.java into a .class file

- If there are no errors type: java StartApp
  and it should print the string "Press Start to Begin"

 Another way is to create a string variable that stores the string "Press Start to Begin" like so

   String start = "Press Start to Begin";
   System.out.println(start);

And what that does there is it stores the text "Press Start to Begin" to the variable "start" so when you tell it to print "start" to the screen it prints the text stored in the start variable.

Give it a try and let me know if you want more.

Source:
http://docs.oracle.com/javase/tutorial/getStarted/index.html  read up on some of this if you do not know what the JVM is.



No comments:

Post a Comment