Java After Intro: Getting Your Hands Dirty
Java After Intro: Getting Your Hands Dirty
The classloader
An object responsible for loading classes
Converts a named class into the bits responsible for implementing that class
Classes are introduced into the JVM when they are referenced by name in a class
that is already running. (just a bit of magic is required to get the main class loaded)
For the defauld ClassLoader classes must be on the Classpath .
The Classpath defines what you can use in your program. Java SE classes are
automatically added.
Name collisions
Im Bob!
Im Bob
lowercase
words separated by dots
uniqueness comes from reversing the organization domain name (which is unique) -> ro.academyplus.Bob
ro, ro.academyplus, ro.academyplus.people etc. are independent packages, although ro. academyplus is called a subpackage of
ro there is no relationship between them
Access modifiers can be applied also to classes not only members of a class
1 public class / file
Arrays
Efficient
Fixed size that cannot be changed after creation
Can store primitives
Arrays are Objects
Primitive autoboxing
int a = 2;
Integer b = 2;
Integer c = new Integer( 2);
String two = "2";
boolean doStuff() {
return a == b; //true
}
boolean doMoreStuff() {
return b == c; // false;
}
boolean doMagicStuff() {
return b.equals(Integer. parseInt(two)); // true
}
Overloading stuff
int compute( int a, int b){
return a*2+b*3;
}
int compute( int a){
return a*(a+1)/2;
}
float compute( int a){ // nope this is not overloading
return a*(a+1)/2.2;
}
float compute( float r) {
return 3.14f * r * r;
}
String compute( float r, boolean area) {
return (area ? 3.14f * r * r : 2 * 3.14 * r) + "";
}
Exercises
Heroes: Orc, Elf, Knight, Mage
Villains: Devil, Goblin, Necromancer, Dark mage
Artifacts: Amor, Helm, Sword, Staff, Bow, Axe
Implement: toString, constructors
What you should have in your classes: a way to compute the damage, a way to take damage, artifacts .