Java: Check if command line arguments are null

The arguments can never be null. They just wont exist.

In other words, what you need to do is check the length of your arguments.

public static void main(String[] args) {
  // Check how many arguments were passed in
  if (args.length == 0) {
    System.out.println("Proper Usage is: java program filename");
    System.exit(0);
  }
}

Leave a Comment