Shortcut: Run a Java program from source code file

preview_player
Показать описание
Experiment the new feature in JDK 11: Launch Single-File Source-Code Programs.
Now you can run a Java program directly from source code - very convenient for small, utility programs that are contained in a single source file.

#javaforbeginners #javaprogramming #javatips
Рекомендации по теме
Комментарии
Автор

I tried to use -cp (classpath) with single source code. But java command didn't work.

I thought single source code only work with single file.

For example, I have a Test.java. And another file called Data.java. So I have 2 files. I tried to run single source code on Test.java and -classpath with Data.java.

java --classpath Data.java Test.java

// Test.java
public class Test{


public static void main (String args[]){
Data data;
System.out.println("Hello World");

}
}

// Data.java
public class Data{


}

HenryLeu
visit shbcf.ru