How to import a class in Java?

To import a dev.whaa.HelloWorld class in Java, write import dev.whaa.HelloWorld; at the top of your .java file.

Here's how you do it:

import dev.whaa.HelloWorld;

public class YourClass {
  public static void main(String[] args) {
    new HelloWorld().sayHello(); // Hello World!

// dev/whaa/
package dev.whaa;

public class HelloWorld {

  public void sayHello() {
    System.out.println("Hello World!");