The course gives a tender introduction to Java.
Java supports the following control structures.
whileforif/elseA 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.
publicmembers can be accessed by anyone, whereasprivatemembers 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.
staticmembers are invoked through class name andstaticmethods cannot access instance variables. Instance members sharing the same name asstaticmembers 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.