I created simple java project by using Intellij and it works in both command prompt and intellij as well. here is the code:
public class HelloWorld {
    public static void main(String[]args){
        System.out.println("Hello World!");
    }
}
Then I created a package and moved main class into it and it works in intellij but not in command prompt.my codes are,
package com.attempt;
public class HelloWorld {
    public static void main(String[]args){
        System.out.println("Hello World!");
    }
}
this is what appears in command prompt:
>  Directory of
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt
> 
> 03/31/2020  10:07 PM    <DIR>          . 03/31/2020  10:07 PM    <DIR>
> .. 03/31/2020  11:57 PM               438 HelloWorld.class 03/31/2020 
> 10:06 PM               152 HelloWorld.java
>                2 File(s)            590 bytes
>                2 Dir(s)  408,375,992,320 bytes free
> 
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt>javac
> HelloWorld.java
> 
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt>java
> HelloWorld Error: Could not find or load main class HelloWorld Caused
> by: java.lang.ClassNotFoundException: HelloWorld
> 
> C:\Users\dylanMj\Desktop\Coding2\src\main\java\com\attempt>
 
    