PROGRAMMING

MINTE9
REMEMBERS




Last update:   23-07-2021

Packages

! If you do not use a package statement, your type goes in an unnamed package. Java compiler automaticaly imports three packages:
 
(1) the package with no name
(2) the java.lang package
(3) the current package

Import

To import a specific package into the current file, use import statement.
 RunCode
// unnamed package

import java.util.List;
import java.util.ArrayList;

class LearningApp {

    public static void main(String[] args) {
        
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);

        System.out.println(list);   
    }
}
... 5 lines
˄˄˄

Hierarchy

! At first, packages appear to be hierarchial, but they are not. For example, java.util.ArrayList is not included in java.util.List package.
 RunCode
// unnamed package (default)

import java.util.List;
import java.util.ArrayList; // Look Here

class LearningApp {

    public static void main(String[] args) {
        
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);

        System.out.println(list);  // [1, 2]
    }
}
... 5 lines
˄˄˄
Task

 CompleteTask
/**
 * Import libraries required by the following code

class App {

    public static void main(String[] args) {
        
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        System.out.println(list);  // [1, 2]
    }
}
*/


// SOLUTION

???
solution code
Questions    
18. Sublime Text
17 . Packages
Last update:   23-07-2021

        A B C D E F
🔔
1/2