- BASICS
- Classes
- Objects
- Arrays
- Variables
- Loops
- Numbers
- Strings
- Exceptions
- Regexp
- OOP
- Inheritance
- Polymorphism
- Static Keyword
- Abstract Keyword
- Interfaces
- Constructors
-
Packages
- Nested Classes
- Final Keyword
- SWING
- Frame
- Panel
- Listener
- Combo Box
- Label
- Image
- Menu
- Table
- Layout
- Drawing
- Timer
- Designer
- COLLECTIONS
- Lists
- Comparable
- Sets
- Maps
- Generics
- Properties
- Streams
- Json
- COMPILER
- Sublime Text
- Apache Ant
- I/O
- Streams IO
- Socket
- Watching Files
- Logger
- Clipboard
- Encrypt
- JAVAFX
- Openjfx
- Scene Builder
- First App
- Jar Archive
- On Action
- Change Listener
Import package
To import a specific package into the current file, use import statement.
/**
* If you do not use a package statement ...
* your type (your class) 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
*/
package com.minte9.oop.packages;
import java.util.ArrayList;
public class Import {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
System.out.println(list); // [1, 2]
}
}
Hierarchy
At first, packages appear to be hierarchial, but they are not.
/**
* Importing java.uitl.* imports all of the types ...
* in the java.util package but it does not import ...
* java.util.regex package
*/
package com.minte9.oop.packages;
//import java.util.*; // not used
//import java.util.regex.Matcher; // Look Here
import java.util.regex.Pattern;
public class Hierarchy {
public static void main(String[] args) {
Pattern p = Pattern.compile("Java");
java.util.regex.Matcher m = p.matcher("Java SE 8");
System.out.println(m.find()); // true
}
}
Last update: 531 days ago