Yes, you can run a class file that is compiled in lower environment.
For example, Let me compile a class in JDK1.7 and try to run in JDK1.8.
HelloWorld.java
public class HelloWorld {
  
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}
Compile the class using jdk1.7 compiler.
$/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/javac HelloWorld.java 
$
$ls
HelloWorld.class	HelloWorld.java
Let’s run the class using JDK1.8 runtime.
$/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home/bin/java HelloWorld
Hello World
You may like
StackOverFlowError vs OutOfMemoryError in Java
Different ways to iterate over a map using for-each loop
How for-each or enhanced for loop works in Java?
How to solve UnsupportedClassVersionError in Java?
How to find the Java major and minor versions from a .class file
No comments:
Post a Comment