Jump to content

Sigma

Trade With Caution
  • Posts

    61
  • Joined

  • Last visited

  • Feedback

    0%

Everything posted by Sigma

  1. Internal client error, all the methods are obfuscated. The error means it's trying to access something in a data structure while modifying it.
  2. It was not a setting before.
  3. Poison is not a setting (config). The only way to check for this currently is to check the color of the hp orb which is not always reliable.
  4. Start up appreciation threads again
  5. This is only true if the fields inside the enum are not bit fields.
  6. Sigma

    Class hierarchy

    The lesson was trying to teach what class hierarchies are, and indirectly referenced the concept of inheritance, so yes you're correct here.
  7. Use the keyword this for get methods for consistency and redundancy, it makes it easier to see which variable you're actually accessing (I know most if not all IDE's will make sure they are the same color anyways).
  8. Focus on what an individual can accomplish rather than on what they cannot.
  9. RuneSupply is an inner class of Magic so you cannot anonymously instantiate it like that.
  10. Why do you want to do this?
  11. Spell Cinnamon right and they might help you.
  12. I have a hunch this is what he's trying to do.
  13. There is no getAllTiles method inside the Area class. You could write that yourself, though.
  14. Me coming off like a dick is subjective. If you feel that way, oh well; that was not my intention. Maybe you should work on that? I don't really know because I'm not a psychologist.
  15. Good catch, it was pretty late when I was writing this. Of course. If you want me to make a tutorial of "your level", please let me know and I'd be happy to have you learn something new.
  16. Sigma

    Class hierarchy

    http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html That is subjective. During this tutorial, hierarchy seems more appropriate. I could have gone further and added the CollegeStudent and CollegeTeacher classes which would have provided a slightly larger tree of classes to look at, though.
  17. One of the most basic examples of this is the Person, Student, Teacher lesson which I will go over briefly. To start, we'll create the Person class: public class Person { private final String name; private int age; public Person(final String name, final int age) { this.name = name; this.age = age; } public String getName() { return this.name; } public int getAge() { return this.age; } public void setAge(final int age) { this.age = age; } @Override public String toString() { return "Name: " + getName() + ", Age: " + getAge(); } } A person has a name and an age. For the sake of this tutorial, a Person's name cannot change, but their age can. As an added foot-note (you don't have to do this), I added a toString to the Person class, so if you ever want to have access to that you can. Now, a Person is pretty bland and very ambiguous. Anyone can be a Person, so let's create two more classes that will extend Person (they will essentially "be" Person's). Student class: public class Student extends Person { private final int id; public Student(final int id) { super("Default", 50); this.id = id; } public Student(String name, int age, final int id) { super(name, age); this.id = id; } public int getId() { return this.id; } @Override public String toString() { return super.toString() + ", Id: " + getId(); } } In the class above, we have Student extend Person. This allows for the name and age fields to be inherited so we don't need to re-define them inside the Student class. Person is Students 'parent/super class', so the keyword 'super' is referring to the Person class. After we create the Teacher class, I will provide example usage of these three classes. Teacher class: public class Teacher extends Person { private final String className; public Teacher(final String className) { super("Default", 50); this.className = className; } public Teacher(String name, int age, final String className) { super(name, age); this.className = className; } public String getClassName() { return this.className; } @Override public String toString() { return super.toString() + ", Class Name: " + getClassName(); } } Now that we have all three classes defined, we can use them as we please. Example usage: import static java.lang.System.out; public class Test { public static void main(String[] args) { Person p = new Person("Bob", 20); Student s = new Student("Bob2", 25, 128396); Teacher t = new Teacher("Bob3", 40, "OSBot"); out.println(p); out.println(s); out.println(t); /* The following output is recorded: Name: Bob, Age: 20 Name: Bob2, Age: 25, Id: 128396 Name: Bob3, Age: 40, Class Name: OSBot */ } } Now you know basic class hierarchy. You can have as many parent and child classes as you want so long as what you're writing makes sense for what you're trying to accomplish. Per request: Java is always pass-by-value. Here's a short example of what this means: Take class Cat: public class Cat { private String name; public Cat(final String name) { this.name = name; } public String getName() { return this.name; } public void setName(final String name) { this.name = name; } @Override public String toString() { return getName(); } } Now, take class ReferenceTutorial: public class ReferenceTutorial { public static void main(String[] args) { Cat cat = new Cat("Bob"); //LINE 1 foo(cat); System.out.println(cat); //LINE 3 Cat cat2 = new Cat("Bob"); //LINE 9 foo2(cat2); System.out.println(cat2); //LINE 10 } public static void foo(Cat c) { c = new Cat("Bob2"); //LINE 2 System.out.println(c); //LINE 4 } public static void foo2(Cat c) { c.setName("Bob3"); //LINE 5 c = new Cat("Bob4"); //LINE 6 c.setName("Bob5"); //LINE 7 System.out.println(c); //LINE 8 } } On LINE 1, we create a pointer to a Cat called cat. This Cat has a memory address. If we pass that address into a method, such as foo() and then on LINE 2 we set that address to be a new Cat (which has a separate address), the name of the passed in Cat will not change because the two fields have different memory addresses. LINE 3 and LINE 4 will print out "Bob" and "Bob2" respectively. Why does LINE 4 print out "Bob2"? Because when we called println on the field c, we are still in the scope of the method and it will be referencing the new memory address we created. Now on LINE 5, we are referencing the original memory address we passed in by calling c.setName(). This will actually change the name of the Cat we created in the main method called cat2. Now on LINE 6, we create a new pointer that points to an entirely new memory address and then set that cat's name and print it out (remember, we created an entirely new address, so the Cat (pointer) we created on LINE 9 will not have its name changed twice and it will remain as "Bob3"). LINE 8 and LINE 10 will print out "Bob5" and "Bob3" respectively. Why does LINE 10 print out "Bob3"? Because we changed the name of cat2 on LINE 5 (we were referencing the original memory address). The recorded output will be: /* Bob2 Bob Bob5 Bob3 */ This should give you a general idea of what pass-by-value is. If you have any further questions, feel free to post them.
  18. That isn't wrong, it's just more code.
  19. thisIsCamelCase You use the above syntax to denote a field that is not final, examples: int numOne; Object objOne; public protected private abstract static final synchonized The above are modifiers you use before defining a field or method, examples: public static final String NAME; protected void method1() { } That is the order you should be putting them in, omitting any unused modifiers. You'll probably never use transient, volatile, or native modifiers, so they won't be included in the above order. byte short int long float double boolean char The above are primitive data types that you are able to compare equality with the == operator, examples: int numOne = 1; int numTwo = 2; public static void main(String[] args) { System.out.println(numOne == numTwo); //If you run the above code, it will print out as 'false' } ClazzName The above is the correct syntax for class names; the first letter of each word should be capitalized, examples: class TestClazz { } class TipsOnHowToNotBeBad { } I_AM_A_FINAL_FIELD The above is the correct syntax for defining a final field, examples: int MAX_VALUE = Integer.MAX_VALUE; int MIN_VALUE = Integer.MIN_VALUE; .equals(Object obj) The above is a method that is inherited from the Object class. It is used to compare two objects for equality (do not use the == operator, as stated in a previous lesson above it is for primitive data types only), examples: String cheese = "Cheese"; String cheese2 = "Cheese"; public static void main(String[] args) { System.out.println(cheese.equals(cheese2)); //If you run the above code, it will print out as 'true' } public void method1() { } public void method2() { } public void method3(){ } The above are three different ways to format your braces in java. All 3 are correct, but you should never mix one with another. if (booleanValue) method1(); The above is an if statement that has the braces omitted. You should only do this if there is only one line of code that is executed inside the if statement (note that you can also do this with for and while loops). int numOne; String stringOne; public Clazz(int numOne) { this(numOne, "Default); } public Clazz(int numOne, String stringOne) { this.numOne = numOne; this.stringOne = stringOne; } The above is an example of Constructor overloading. In the first constructor, you are only required to pass in an int, and the String field is automatically assigned whereas in the second constructor you are required to provide both an int and a String. If you learned anything from this, congratulations, you're less bad than you were before.
  20. First of all, multiple class files might be created from one java file. If your IDE automatically added it and someone who doesn't know anything puts that in, it will confuse them. Your third point makes no sense as it's not an argument, it's just a statement; a statement I most certainly agree with, however it was provided in a mediocre manner. I am communicating like an adult. I simply pointed out things that are wrong with your tutorial, and you should fix them. You are the only one who looks like a dumb teen swearing at me because you found out someone disagrees and knows more than you.
  21. Doing anything besides initializing variables in a constructor is bad. Just do switch(getState()) { } You create a new instance of a class every time the loop runs, that is an incredible waste of resources and memory. Why do you call the method onStart from the parent class inside the overridden method onStart from the parent class? That makes no sense. Why is this thread pinned?
×
×
  • Create New...