The course gives a tender introduction to Java.
Java supports the following control structures.
while
for
if/else
A class which works exclusively with int
in Java can be defined in the following way.
public class A {
// Instance Variable
public int instance_var;
// Static Variable
public static int static_var;
// Constructor
public A (int param) {
instance_var = param;
}
// Instance Method
public int instance_method (int x) {
// ...
}
// Static Method
public static int static_method (int x) {
// ...
}
}
When a variable of a class type is declared, it can then be assigned to the memory address of an instance of that class.
A a_Object = new A(arg);
// declaration assignment instantiation
Classes in Java use certain keywords to control what its members can do. These keywords are known as modifiers and this course covers 2 types: access and static.
Access modifiers tell the compiler who can access a certain member.
public
members can be accessed by anyone, whereasprivate
members can only be accessed within the class.
Static modifiers help the compiler tell if a member belongs to a specific instance of a class or to the class itself.
static
members are invoked through class name andstatic
methods cannot access instance variables. Instance members sharing the same name asstatic
members are prioritized when accessed through an instance.
A Java program Program.java
is compiled into a byte code file Program.class
which is then interpreted through the Java Virtual Machine, an intermediary environment between Java code and low level hardware.