Results 1 to 5 of 5
  1. #1
    xXH4XM@ST3RXx's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    22
    Reputation
    10
    Thanks
    121
    My Mood
    Sleepy

    [Tutorial]The Ultimate Java Tutorial

    The Ultimate Java Tutorial

    Mission:To re-engage and teach the users of MPGH the syntax, design, and implementation of the fantastic programming language of Java.

    This thread is not the guide. This thread is an intro, and it will have a TOC with links to other threads I will make that will guide you from outputting strings to putting threads to sleep.

    Table of Contents
    Chapter 1 - Basic Java Syntax



    Now, lets begin.

    Java takes you to new places. From its humble release to the public as the (wimpy) version 1.02, Java seduced programmers with its friendly syntax, object-oriented features, memory management, and best of all-the promise of portability. The lure of write-once/run-anywhere is just too strong. A devoted following exploded, as programmers fought against bugs, limitations, and, the fact that it was horribly slow. But that was ages ago. If you're just starting in Java, you're lucky. Some of us has to walk five miles in the snow, uphill both ways (barefoot), to get even the most trivial applet to work. But you, why you, get to ride the sleeker, faster, much more powerful Java of today.

    The way Java Works...

    1. Source - Create a source document. Use an established protocol (in this case, the Java language)
    2. Compiler - Run the document through a source code compiler. The compiler checks for errors and won't let you compile until its satisfied that everything will run correctly.
    3. Output (code) - The compiler creates a new document, coded into Java bytecode. Any device capable of running Java will be able to interpret/translate this file into something it can run. The compiled bytecode is platform-independant (can run on Mac OS, Linux, Windows, anything that will come out).
    4. Virtual Machines - Your friends don't have a physical Java machine, but they all have a virtual Java machine (implemented in software) running inside their electronic gadgets. The virtual machine reads and runs the bytecode.

    What you'll do in Java...

    1. Source - Type in your source code (.java)
    2. Compiler - Compile the source code by running javac (the compiler application). If you don't have errors, you'll get a second document (.class). The compiled .class file is made up of bytecodes
    3. Output (code) - Compiled code of .class.
    4. Virtual Machines - Run the program by starting the Java Virtual Machine (JVM) with the .class file. The JVM translates the bytecode into something the underlying platform understands, and runs your program.

    A very brief history of Java

    CSB = Classes in the standard binary

    Java 1.02 - CSB = 250. Slow. Cute name and logo. Fun to use. Lots of bugs. Applets are the Big Thing.

    Java 1.1 - CSB - 500. A little faster. More capable, friendlier. Becoming very popular. Better GUI code.

    Java 2 (versions 1.2 - 1.4) - CSB = 2300. Much faster. Can (sometimes) run at native speeds. Serious, powerful. Comes in three flavors: Micro Edition (J2ME), Standard Edition (J2SE), and Enterprise Edition (J2EE). Becomes the language of choice for new enterprise (especially web-based) and mobile applications.

    Java 5.0 (versions 1.5 and up) - CSB = 3500. More powerful, easier to develop with. Besides adding more than a thousand additional classes, Java 5.0 (known as "Tiger") added major changes to the language itself, making it easier (at least in theory) for programmers giving it new features that were popular in other languages.

    Code structure in Java
    Java consists of objects, classes, source files, and methods.

    Source file - A source code file (with the .java extension) holds one class definition. The class represents a piece of your program, although a very tiny application might need just a single class. The class must go within a pair of curly braces - EXAMPLE
    Code:
    public class Dog {
    
    // Do stuff here.
    // By they way, putting "//" before something makes the program ignore that particular line. Its called a "comment"
    
    }
    Class - A class has one or more methods. In the Dog class, the bark method will hold instructions for how the Dog should bark. Your methods must be declared inside a class (in other words, within the curly braces of your class). EXAMPLE

    Code:
    public class Dog {
    
    voice bark() {
    
    
    }
    
    }
    Method - Within the curly braces if a method, write your instructions for how that method should be performed. Method code is basically a set of statements, and for now you can think of a method kind of like a function or procedure.

    Code:
    public class Dog {
    
    void bark {
        statement1;
            statement2;
    }
    
    }
    Anatomy of a class
    When the JVM starts running, it looks for the class you give it to command line. Then it starts looking for specifically written method that looks exactly like:

    Code:
    public static void main (String[] args) {
        // Put your code here
    }
    Next, the JVM runs everything in between the curly braces { } of your main method. Every Java application has to have at least one class, and at least one main method (not one main per class, one main per application).

    Look at the following code snippet:
    Code:
    public class MyFirstApp {
    
          public static void main (String[] args) {
              System.out.print("I rule!");
    }
    }
    Now, lets dissect it.

    public - Public means that everyone can access it, meaning every developer, and every class.
    class - This is a class.. Duh.
    MyFirst App - The name of this class
    First { - Opening curly brace of the class (This is where JVM begins compiling code)
    static - doesn't change. (we will cover this one later, its a lot more than we can fit here)
    void - The return type. All methods have to have something they "return". Void simply means it returns nothing.
    main - the name of this method
    (String[] args) - Arguments to the method. This method must be given an array (covered later) of Strings, and the array will be called "args"
    Second { - Opening brace of the method. Everything between this and the next } belongs to the method code.
    System.out.print - This says print to standard output. "." seperates classes, packages (collection of classes) and methods. This tells us that the "print" method is in the "out" class of the "System" package.
    ("I Rule!") - The string (series of words) you want to print.
    ; - EVERY STATEMENT MUST END IN A SEMICOLON (!
    First } - Closing brace of the main method.
    Second } - Closing brace of the MyFirstApp class.

    This is just to get you started, don't worry about memorizing this yet.


    Useful Links
    Eclipse - Most Popular Java Compiler/IDE
    Netbeans - Personally recommended by Me. My favorite Compiler/IDE
    Java Download
    Java Development Kit (Required to Compile)
    Java SE 6 API References

    This thread will be updated with the latest additions to the Tutorial in the "TOC" at the top of the thread.



    Last edited by why06; 03-28-2010 at 05:38 PM.

  2. The Following 7 Users Say Thank You to xXH4XM@ST3RXx For This Useful Post:

    Houston (03-26-2010),MJLover (04-28-2010),NextGen1 (04-24-2010),odoacer (09-18-2010),shaheer123 (03-30-2010),sienfiman (06-27-2011),why06 (03-26-2010)

  3. #2
    Houston's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    The Netherlands
    Posts
    1,941
    Reputation
    175
    Thanks
    2,470
    My Mood
    Blah
    Great Explain of Java
    Thx

  4. #3
    Itz Yogibear's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    11
    Reputation
    10
    Thanks
    0
    My Mood
    Happy
    Fix your conventions:
    Code:
    public class MyFirstApp {
    
          public static void main (String[] args) {
              System.out.print("Bad convention");
    }
    }
    Code:
    public class MyFirstApp {
    
          public static void main (String[] args) {
              System.out.print("Good convention");
          }
    
    }

  5. #4
    shadowkiller210's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    act australia
    Posts
    347
    Reputation
    10
    Thanks
    5
    My Mood
    Blah
    u should write a full tutorial. is there a good 1 on the net?

  6. #5
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Woot, someone bumped it for me so I don't have to ,Some of this is word for word straight out of the book "head first into Java"

    authors do not like plagiarism, offer credits....Cite the original author maybe?.
    Last edited by NextGen1; 04-24-2010 at 04:15 AM.


     


     


     



    The Most complete application MPGH will ever offer - 68%




Similar Threads

  1. The ULTIMATE! Tutorial.
    By Massive in forum CrossFire Tutorials
    Replies: 16
    Last Post: 07-20-2010, 05:04 AM
  2. [Tutorial]The Ultimate Java Tutorial
    By xXH4XM@ST3RXx in forum Programming Tutorials
    Replies: 2
    Last Post: 03-29-2010, 12:19 AM
  3. The Ultimate Sig Tutorial.
    By Nexulous in forum Tutorials
    Replies: 5
    Last Post: 10-11-2009, 09:57 AM
  4. The Ultimate Showdown Of Ultimate Destiny
    By m164life in forum Entertainment
    Replies: 18
    Last Post: 09-24-2006, 05:06 PM
  5. Soul of the Ultimate Nation
    By vir2000 in forum General Gaming
    Replies: 5
    Last Post: 01-05-2006, 03:40 AM