Search code examples
javacompiler-errorspackage

I am having an issue with java package compile error


im getting this error when i am compileing a package declaration in java in the command line

javac -d .\java_shorts.java


.\java_shorts.java:3: error: class, interface, enum, or record expected
package shorts;
^
1 error
//java_shorts.java file
import java.io.Printwriter;

package shorts;
public static class java_shorts
{

public static void command_line_output(String string_input)
{
  System.out.print(string_input);

}
public static int random_number_generator_range_exclude_data_base()
{

}
public static void hello_world()
{

  command_line_output("hello_world \n\n");
}

}
//////////////////// 

/////main call file

import account_methods.account_core;
import shorts.java_shorts;



public class account_main
{
public static void main (String args[])
{
  java_shorts short_java = new java_shorts();

  short_java.hello_world();


}


}

I was hoping to import a class from a external file.


Solution

  • Package definition should be before the import definitions.

    package shorts;
    
    import java.io.Printwriter;