Thread: How to Java the short version.

Results 1 to 7 of 7
  1. #1 How to Java the short version. 
    Registered Member
    Join Date
    Jul 2015
    Posts
    150
    Thanks given
    0
    Thanks received
    7
    Rep Power
    0
    Hello, I am a veteran developer with over 10 years experience in Java and specifically originating in the creation of RSPS servers my goal here is to write a brief
    yet hopefully illuminating article on Java for beginners

    Note: This article is based only upon my understanding and experience and I'm not the best at explaining things although I have my moments.
    If you understand better then me or have a simpler way to rephrase this then please feel free to reformat my thread and send me a paste bin link via pm

    Spoiler for Is this for you?:

    Are you a new Java developer who has probably downloaded a file and had some success understanding how code works? THEN YES!

    Note: THIS IS NOT A COMPLETE GUIDE ON JAVA JAVA IS A LANGUAGE THERE IS NO 5 MINUTE QUICK FIX.

    However with that said I hope this can illuminate one or two of the things I personally got stuck on when I started coding from RSPS servers (Yes the bad method open and read.)
    With time and much help I learned and struggled through and now want to provide a small shortcut.


    Spoiler for Basic terminology:


    API - An API is a collection of code usually presented in the form of a non executable jar file didn't you ever wonder why the words
    System.out.println(); were so magical anyways? They aren't! This to is part of a API included by default in Java.

    There will be a link to Java's default API at the bottom of this article in resources!

    void() boolean() int() double() etc... - These are all return types a void is a method that runs the code inside the brackets when called.

    public private - these are types of visibilities if something in the cat class is marked as private even if its private static you won't be able to call it
    from another class the reason for this is because its marked as private and belongs only to the cat class private should be abused as much as possible
    whenever you don't need a particular piece of code for another class.

    variable - a variable is a boolean int or anything else which you record in your code for use later.


    Call - A call is when you call for a method a good example is right below this.
    Method - A named place in code that can be called upon at a later time.
    Code:
     
    public class Main {
    	public static void main(String[] args) { //the starting point of any program
    		/*
    		 * Calls method printHello(); from class OtherClass
    		 * args is a array of strings args[0] reffers to the first string in the array (we start at 0)
    		 * my argument 0 from the command line is "Hello I am arguemnt 0."
    		 * Java src.main "Hello I am argument 0."
    		 * */
    		OtherClass.printHello(args[0]); 
    	}
    }
    Code:
    public class OtherClass {
    
    	/*For this example printHello() is a method and String s is a argument passed to the method.
    	 * s is passed to the method from the point of its call look back to main.java
    	 * note that args[0] a string was between the parentheses OtherClass.printHello(args[0]);
    	 */
    	public static void printHello(String s) {
    		System.out.println("Hello World!");
    		System.out.println("This class was an attempt to show the relation between java classes!");
    		System.out.println("This was the first argument passed to the program: " + s); //s is a string
    	}
    	
    }
    Object - A object is a class that has a constructor the creation of a object is always instanced meaning it gets its own set of values. Two cats will never be the same!
    Constructor - A constructor is a set of values a object needs for instance a cat(the object) needs to have a age and a color (among other things):

    Code:
    public class Main {
    	public static void main(String[] args) { //the starting point of any program
    		int age = 1;
    		String color = "PurpleBecauseWhyNot.";
    		/*
    		 * Create a new cat use the age variable defined as 1 and the color variable defined as
    		 * "PurpleBecauseWhyNot."
    		 */
    		Cat fluffy = new Cat(age, color);
    		
    		/*
    		 * Because this method was a return type of String we can use this here and it will 
    		 * print to the console "PurpleBecauseWhyNot." because thats the fur color of the cat object
    		 * named fluffy that we gave it when we created it using
    		 * 
    		 * String color = "PurpleBecauseWhyNot.";
    		 * Cat fluffy = new Cat(age, color);
    		 */
    		System.out.println(fluffy.getColor());
    	}
    }
    Code:
    public class Cat {
    	/*
    	 * The below is a example of a constructor the object Cat is constructed with the values
    	 * int age and String color because all cats have ages and colors!
    	 */
    	
    	private int age; //this is seen below getting set to the value of the passed variable of passedAge
    	private String color; // ^ what that guy said.
    	
    	public Cat(int passedAge, String color) {
    		this.age = passedAge;
    		this.color = color;
    	}
    	
    	/*
    	 * This is a example of using a return type if we used a void the code would have been executed
    	 * and Java would have continued on top down but since we used string when it returns to where it was
    	 * it will pull the value of color along with it!
    	 */
    	public String getColor() {
    		return color;
    	}
    }


    Spoiler for The basics:

    Before we get started there are just a few other things you should understand:

    I literally cannot stress this enough as a new developer:
    --->A IDE IS 1000% ABSOLUTELY VITAL!!!<---

    If you are scratching your head with compiler errors an IDE will be your best friend in the world you will dump you girl and marry your computer yes that's legal someone married a video game character fun world now a days

    Here are some of the most basic compiler errors and their fixes courtesy of shoes @ rune-server: Common errors and fixes.

    - > Most of this is repeated.

    1. Methods belong to classes and can be called from other classes ex: Cat.walkForward();
    2. Code is not magical it usually comes from API sitting elsewhere read the API and you will be able to manipulate more then player.startTeleport()();
    3. Private variable can not be called from outside classes.
    4. A object is instanced for example every player is a Player() object if not you wouldn't be any different from the next guy.
    5. When you create a variable and mark it static this means it will always stay the same not to say it can't be changed thats the first assumption and it is WRONG
    static means that this variable whatever its value will be the same between all objects of the same name so if your gold stack is static anyone who gets
    any gold will add to it!

    Spoiler for Defining Java:
    Java is a top down object oriented programming language. This means code at the top is executed and considered first it also means whenever there is a call to another class
    Java will jump to that call and execute that methods code until the end at which point it will return to where it was before and continue it's top down executions.


    Spoiler for Choosing an IDE:

    Note: before reading the next few lines I would like to just say that when I started I personally used notepad++ and supported it all the way however...

    Spoiler for My loss of composure 18+:

    Notepad++ everyone... IS NOT AN IDE ITS A BAD HABIT AND A MANGLED PIECE OF GARBAGE REGURGITATED AND DEVOURED OVER AND OVER BY THE LOWEST FILTH OF THE DEVELOPMENT COMMUNITY. - Coughs and regains composure -

    You are not cool for using Notepad++++ you are not skilled for using Notepad++++ and trust me if you believe it you are the ONLY one!

    Summary of above spoiler: notepad++ is bad use a IDE.

    Now then onto what is a good development IDE which will help you in ways you could have never dreamed of your choices are pretty much two titans for Java:
    Net beans (A more complex however more seemingly functional solution might not be the best choice for beginners.)
    Eclipse (Super straight forward maybe not as functional as net beans but the interface is beautiful this functions nicely its basically for anyone who prefers windows. (Same principle pretty, easy, best for common folk.)) <- What I use and my recommendation.


    about the this. this. uses the instance of whatever class you happen to be in so if you are in a instanced version of cat this.setColor()("Black"); is going to scare the shit out of your cat because its fur is about to change color (but not its friends because not every cat has the same fur (color is not static))


    Spoiler for Starting a program:

    A class with a main method is the main class the main method is also the starting point of a program this is also where arguments are passed from command line to the program example:
    Code:
     Java com.rs.server true false
    In this example Java is the Java path com.rs.server is the path to the main class(being server) and true and false are arguments if we opened up the main method of this example it would look something like this.
    Code:
    public static void main(String[] args) {
        this.debugMode = args[0]; //this is where the value true gets used from the command line code above.
        this.useGui  = args[1]; // this is where the value false gets used from the command line code above.
    }






    Spoiler for Java fun facts just because:

    Java can read side to side also (don't ever do this LOL!)
    Code:
    public class Test { public static void main(String[] args) { System.out.println("Hello World!"); } }
    ^ Valid and executable.
    Reply With Quote  
     

  2. #2  
    Ex Rune-Scaper

    Join Date
    Jun 2008
    Posts
    3,534
    Thanks given
    457
    Thanks received
    1,257
    Rep Power
    990
    No offense but this is really bad. You're better off looking for free PDF books on Java to learn.
    Attached image
    Reply With Quote  
     

  3. Thankful users:


  4. #3  
    Registered Member
    Join Date
    Jul 2016
    Posts
    186
    Thanks given
    76
    Thanks received
    39
    Rep Power
    41
    Agree with Free. Java beginners should start at the official oracle site:The Javaâ„¢ Tutorials which is more detailed

    and https://www.rune-server.org/runescap...tter-java.html by Major contains useful information that can be used for improving your java skills

    And of course there are plenty of tutorials and tips using google like you mentioned.
    Reply With Quote  
     

  5. #4  
    Registered Member
    The Reverse's Avatar
    Join Date
    Nov 2014
    Posts
    936
    Thanks given
    168
    Thanks received
    289
    Rep Power
    520


    What did you mean by this? Like Free said, there are better tutorials and PDF explaining more in depth with better examples. Thanks for trying.

    Darkness cannot drive out darkness; only light can do that. Hate cannot drive out hate; only love can do that.
    Martin Luther King, Jr.

    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Registered Member
    Join Date
    Jul 2015
    Posts
    150
    Thanks given
    0
    Thanks received
    7
    Rep Power
    0
    I do agree you are better off with books or video tutorials but that's not how learning java works here is it?

    This is:
    Some 12 year old kid wants to program so he downloads a server opens it up reads a tutorials and thinks hes a pro because he can move a npc then he reposts it as a fully developed server.
    ^- This is a waste of time and a bad way to learn but this is unfortunately how it usually happens and so my guide is meant to help a person in this state to gain a small working understanding of java and save them time.

    And where exactly is your guide? hmm...

    @The Reverse that's not particularly relevant I was just messing around one day and wondered if a one line program was possible my solution was basically to see if it could read side to side... It could fun fact that's all.
    Reply With Quote  
     

  8. #6  
    'Slutty McFur'

    Owain's Avatar
    Join Date
    Sep 2014
    Age
    26
    Posts
    2,894
    Thanks given
    2,360
    Thanks received
    2,200
    Rep Power
    5000
    Thanks for putting the time and effort in, but there's a million and one guides on learning java.
    Reply With Quote  
     

  9. #7  
    Registered Member
    thim slug's Avatar
    Join Date
    Nov 2010
    Age
    28
    Posts
    4,132
    Thanks given
    1,077
    Thanks received
    1,137
    Rep Power
    5000
    u misspelled "shit" bro. Better change the title.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. How to know the current runescape version
    By mr code in forum Configuration
    Replies: 15
    Last Post: 06-05-2013, 03:06 PM
  2. [OpenRS Editor] How to generate the version table
    By Discardedx2 in forum Snippets
    Replies: 10
    Last Post: 06-26-2011, 01:46 AM
  3. Java: How to get the best performance
    By 03data in forum Informative Threads
    Replies: 2
    Last Post: 04-16-2010, 12:47 AM
  4. How to get the full version of ZDsoft free!
    By Owner of Hunterscape in forum Chat
    Replies: 6
    Last Post: 05-07-2008, 06:18 AM
  5. How to get the full version of hypercam2 free!
    By Owner of Hunterscape in forum Chat
    Replies: 0
    Last Post: 05-05-2008, 03:01 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •