MaestroLuke Posted October 11, 2009 Posted October 11, 2009 Hi guys this guide is made for the little advanced user that have problem understanding the langauge So you take the shared code here,compile it successfully but you don't know how it works? Just a really brief look on the code don't expect anything good So We start We all see that in each java file there is always the word class So what's the class anyway? We define a class as an object and we can call it later by making a instance of it So let's take an example from our life now we are going to implement things on it for example our bank account got some money in it - A class's name (the main class) has the same name of the file. All other classes (inner classes or nested classes) can be named whatever you want. public class Account { int moneyAmount; } NOTE the code here isn't ready i just show some examples so we made a field named moneyAmount type int int means integer so it can be 1,2,3,4,5,6,8,9,0 although it stops somewhere and you must use for example long int Now we are able to make functions(methods) that we can retrieve and take money back pretty simple to make a method public class Account { int moneyAmount; public void withdraw() { ; //here we insert out statements what we want the method do // this can be done with multiple lines } //close the brackets } //close class brackets So here we simple created a method Now how do i call that method? In your main just call it Account.withdraw(); we inserted account to show that it is a method from account class and called withdraw with ; in the end Good till now You can also pass arguments in the methods for example public void withdraw(int money) { ; } Now you can call it like Account.withdraw(123); Let's move to constructors Constructors are used to create instances Also constructors must have the same name with the class let's make an example public class Account { Account() { ; //our code } } so you declared an constructor now to build an account from another class we call Account acc; acc = new Account(); Now we are going to talk about imports packages and the extend word To use the code from other classes we have first to import them how do i import classes? at the top of your code you use import packagename; What's this pack anyway? A package you can imagine is the folder that your java file exists take a look package com.server; import com.server.Account; Remeber package goes first the imports then classes to access folders as you saw we use . not / Let's take a look at the word extend that i am sure you have seen many times By using extend in our class we automaticall get the code from the class we extended let's take an example from l2j public final class L2PcInstance extends L2PlayableInstance ye you found it ^^ Something i want to point is L2PcInstance is subclass of l2playable instance and so it goes on when another class extends l2pcinstance it becomes subclass of it and from l2playable Also super class is the class that it is extened by another but it doesn't extend something else Now let's talk about those public,private and all this crap public,private,protected are name access specifiers we use them to change the accessibility of the class variable etc so public: can been seen from everywhere protected: can be used only by itself and his subclasses private: can been seen only by itself public class Car private class Car so goes on same happens with fields (int,float,bool,etc)and our methods Let's go to Modifiers they are used after access specifiers <acess specifiers> <modifiers> <type or class> <variables>; Modifiers are final: it makes the variables constants static: those make the vars/methods able to be called without having a instance made abstract: it means that methods aren't going to have body in this class There are others too though in l2j you won't need them Operators: What are those and why we need them You already know the most Let's Start + - * (multiplies) / (divides) % ^ powers Bigger,less equal to <= less or equal to < less than >= bigger or equal to > bigger Now something that ppl confuse == means equal to != means not equal And the last && which means and ! which means NOT || which means OR Be sure you are not using == with = because it's different == means equal to and = is used to set values for example if (moneyAmmount == 100) { System.out.println("You got 100 euros"); } It's not the same with if (moneyAmmount = 100) { System.out.println("Wrong!you set money to 100"); } In the second example we set money to 100 and it automaticall executes the statements because the condition it's true! That's All hope you got learned something from here feel free to ask me any question Credits goes to me Quote
SySt3MGaM3RFr3aKs Posted October 11, 2009 Posted October 11, 2009 Owsome Guide... Give Credits If Its Not Yours :) Quote
MaestroLuke Posted October 11, 2009 Author Posted October 11, 2009 Owsome Guide... Give Credits If Its Not Yours :) it's mine rofl Quote
Horus Posted October 11, 2009 Posted October 11, 2009 Luke don't forget to explain them the obvious: - A class's name (the main class) has the same name of the file. All other classes (inner classes or nested classes) can be named whatever you want. Quote
MaestroLuke Posted October 11, 2009 Author Posted October 11, 2009 Luke don't forget to explain them the obvious: - A class's name (the main class) has the same name of the file. All other classes (inner classes or nested classes) can be named whatever you want. thnx forgot to add that Quote
Versus Posted October 11, 2009 Posted October 11, 2009 Nice one, so many shares but non explanation. +1 karma. You could improve the "extends" part a lil bit. Quote
Coyote™ Posted October 11, 2009 Posted October 11, 2009 Nice one, so many shares but non explanation. +1 karma. You could improve the "extends" part a lil bit. It's for competition, you shouldn't give the karma. He will either recieve it from the competition, or he won't recieve any karma at all. Anyway I don't have problem for this xD Quote
xXSkillerXx Posted October 11, 2009 Posted October 11, 2009 It's for competition, you shouldn't give the karma. Yes, Reve. said that too : 4)You can't take karma for your guide if it doesn't win the competition. So, i have to smite Maestro's karma , for now. The guide is really good, so you have many chances of taking your karma point back. :) Anyway, good luck and keep sharing! Quote
MaestroLuke Posted October 11, 2009 Author Posted October 11, 2009 Yes, Reve. said that too : So, i have to smite Maestro's karma , for now. The guide is really good, so you have many chances of taking your karma point back. :) Anyway, good luck and keep sharing! Np guys you know i am really happy that ppl learn from here Nice one, so many shares but non explanation. +1 karma. You could improve the "extends" part a lil bit. i will and i will update it till max characters xD Quote
Horus Posted October 11, 2009 Posted October 11, 2009 The extend class modifier is EXTREMELY simple. Picture this: - You want to make a lot of cars, but all cars have common parts, like an engine, wheels,body,etc. So you make a new Class File named "CarClass" which contains basic information for all cars (engine,wheels,body,llala); - When you make a new car Class File e.g. "SubaruImpreza" you extend the CarClass so that now, this file can access the CarClass's containers,methods, variables and classes, hence, avoiding unnecessary work. Its like a base template from which you start building other sites. Quote
MaestroLuke Posted October 12, 2009 Author Posted October 12, 2009 The extend class modifier is EXTREMELY simple. Image this: - You want to make a lot of cars, but all cars have common parts, like an engine, wheels,body,etc. So you make a new Class File named "CarClass" which contains basic information for all cars (engine,wheels,body,llala); - When you make a new car Class File e.g. "SubaruImpreza" you extend the CarClass so that now, this file can access the CarClass's containers,methods, variables and classes, hence, avoiding unnecessary work. Its like a base template from which you start building other sites. shit i forgot overriding w/e i gonna remake it tonight ;p Quote
KenLar Posted April 19, 2010 Posted April 19, 2010 nice guide ;D ;D...that's the base to get into codes and understand them... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.