import, static import

  • when using class, can skip package name.

  • inform compiler the package where class is in.

  • command+shift+O : automatically add import statement.

  • class of java.lang package dont need import statement. ex) String, Object, System, Thread ...

import (package).(class);
import (package).*;
  • location : between package declaration and class declaration.

package com.codechobo.book;

import java.text.SimpleDateFormat;
import java.util.*;

public class PackageTest{
    public static void main(String[] args) {
        Date today = new Date();
        SimpleDateFormat date = new SimpleDateFormat("yyyy/mm/dd");
    }
}
  • Add package name if there are same class name and they are in different package.

  • static import statement

omitable class name when using static member.

Last updated

Was this helpful?