0

I have a simple Java code:

package com.company;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println("Please enter number of the days");
        Scanner scanner = new Scanner(System.in);
        int days = scanner.nextInt();

        System.out.println("The number of seconds in the entered days number is "+days*86400);
    }
}

The folder structure is: src\com\company

Inside folder company, there are Main.java and Main.class files.

When I run the app in IDE it runs, when I try to run it on the terminal, I get:

Error: Could not find or load main class Main.class Caused by: java.lang.ClassNotFoundException: Main.class

The execution of commands in any of the following ways

  • From inside company folder:
java Main.class
  • From inside src folder:
java com.company.Main.class
java.com.company.Main

give the same error.

What is wrong here?

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
  • Try ```java Main``` while in src folder. I think that is the command . Before running you need to compile using ```javac Main.java``` . – Umeshwaran Jan 20 '21 at 20:02

1 Answers1

0

Complile a Java file to generate a class:

javac filename.java

Execute the generated class:

java filename

Example

javac Main.java

java Main

Detailed answer can be found here How do I run a Java program from the command line on Windows?

Umeshwaran
  • 627
  • 6
  • 12