DATA228 Lecture Notes Week 2
DATA228 Lecture Notes Week 2
Sangjin Lee
Just Enough Java(TM)
Why Java?
• Just enough to get you going nd st rting writing M pReduce pplic tions
• Stop me nd sk questions!
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
What we will not cover
• closures
• modules
• etc. etc.
• Use of IDEs
a
a
a
a
a
a
a
a
a
Java programming language
• J v != J v script
• B sic types: int, boolean, long, char, double, float, byte, short
• J v comments
• int someNumber = 1;
• numbers[2] = ?
....
}
a
a
a
a
Java programming language
• Everything is class
• Interfaces
• Member v ri bles
• Methods
• Constructors
• Abstr ct methods
• St tic methods
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
Java programming language
Class
public class Student { // class
private static int studentCount = 0; // static member
• All inst nce members re initi lized to their def ult v lues (0, null, …)
• Inst nce member v ri bles nd methods (someStudent s n inst nce of the Student
cl ss)
• someStudent.id
• someStudent.getName()
• Student.studentCount
• Student.someStaticMethod()
a
a
a
a
a
a
a
a
a
a
a
a
a
a
Java programming language
• Strings
• Unicode
• Immut ble
• Iter tion
• for-e ch
• while
• do-while
• B se cl ss —> extends
• J v h s g rb ge collector
• E se of progr mming
• At runtime, bytecode is re d nd compiled into ctu l bin ries by the J v Virtu l M chine (JVM)
Compile-time Runtime
JVM
JIT N tive
Code Compiler Bytecode
Compiler bin ry
OS/H rdw re
a
a
a
a
Java programming language
Dependencies and classpath
• How do you use other people’s code (libr ries)? —> dependencies
• Cl ssp th: speci ies how you use others’ libr ries vi p th
• J v comes with ton of built-in libr ries (APIs): https://docs.or cle.com/en/j v /j v se/21/
docs/ pi/index.html
• Superset of JRE
• Build tools
• Most j v libr ries in the world re discover ble nd v il ble through the m ven
ecosystem
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
Java programming language
Demo
• Build j r