Java SE 7 Programmer I

This course is based on the exam topics for Java SE 7 Programmer I. You will get a solid Java programming base and preps you for the exam.

Basics

Define the scope of variables

Variables can hold all kinds of data. Java provides a way to limit access to them. These scope rules are as follows:

public: everyone
private: only this class
protected: only this class, this package, or subclass
static: globally without instance
final: cannot be changed or overridden
no modifier: only this class or this package

Scope is also limited to start and ending braces.

{
...
}

Define the structure of a Java class

BasicClass.java
package nl.code4all.basics;
 
class BasicClass {
 
    // fields/members/variables represent state
    int number;    
 
    // methods/functions represent possible interaction
    void methodA() {
    }
}

Create executable Java applications with a main method

BasicApp.java
package nl.code4all.basics;
 
public class BasicApp {
 
    // start point of application
    public static void main(String[] args) {
        System.out.println("Hi there");     
    }    
}

Import other Java packages

Create two new packages/folders nl.code4all.basics.a and nl.code4all.basics.b. Create two classes.

ClassA.java
package nl.code4all.basics.a;
 
public class ClassA {
 
}
ClassB.java
package nl.code4all.basics.b;
 
import nl.code4all.basics.a.ClassA;
 
public class ClassB {
 
    private void importFromOtherPackage() {
        ClassA a = new ClassA();
    }
}

Using the import nl.code4all.basics.a.ClassA; statement we can import and use code from another package.

Navigation
Print/export
Toolbox