I'm trying to run a simple client-server program written in Java through Ubuntu terminal. I could compile the code successfully unfortunately, I can't run the code.
Server class code:
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server
{
public static void main(String[] args)
{
try
{
//create server Socket with demo port
ServerSocket server = new ServerSocket(20);
//wait for server connection
Socket s = server.accept();
//upon establishing connection, print
// successful message
System.out.println("connection eastablished");
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Client class code:
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
public class Client
{
public static void main(String[] args)
{
try
{
//create client socket
Socket client = new Socket("127.0.0.1", 20);
//upon establishing connection, print
//successful message
System.out.println("connection eastablished");
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
During running the complied class, I'm getting the following error:
mamun@mamun:~$ java Test Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: Test has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
I've tried to search stackoverflow and other forum and blogs to find a solution, I've find some similar questions, tried the answers provided to those question but could find a solution for my problem. That's why I'm adding this question here.
Later, I've try to write a very simple Java program, like just to print a greeting, this program also could be compiled but would not run producing the same error. I've tried to execute the program from different folders except from the root folder. But all efforts produce the same result.
public class Test
{
public static void main(String[] args)
{
System.out.println("Hello...");
}
}
I can perfectly work in Eclipse where my java version 8, problem occurs only when working in terminal.
In my Ubuntu jdk version is 11 (which has been automatically been updated without my knowledge); My Ubuntu version:18.04.1 LTS