0

I want to open separate console per class.

I have three classes. One main class, one class where I read the arguments and the other class which does the print job.

public class MainClass {
 public static void main(String[] args) {
  Readarguments arg = new Readarguments();
  String str = null;
  do{
   str = arg.readargs();
   PrintVals pv =new PrintVals();       
   pv.print(str);
  }while(!str.equalsIgnoreCase("exit"));
 }
}

This class prints onto console

public class PrintVals {
 void print(String val){
  System.out.println(val);
 }
}

This one reads the arguments from console

public class Readarguments {
 String readargs(){
 System.out.print("enter the val :");
 InputStreamReader in = new InputStreamReader(System.in);
 BufferedReader br = new BufferedReader(in);
 String str = null;
 try {
  str = br.readLine();
  } catch (IOException e) {
   e.printStackTrace();
  }
  return str;
 }
}

Now, I am planning to launch all three classes from three different consoles. The console with Readarguments.class will be used to feed the input. while the console with PrintVals.class will print out the values.

All three java files and their respective class files are in same folder.

I am trying to open class files in separate console through command line

java Class<Readarguments>.class

As mentioned in one of the answers in here How to run multiple consoles from one class?

But I am getting a error message

The system cannot find the file specified

Thanks in advance.

Community
  • 1
  • 1
deepak
  • 49
  • 1
  • 2
  • 7

2 Answers2

0

Every Java program needs an entry point which usually is the main method. Since here you have only one class with main method only java MainClass will work and others wont.

Well the MainClass internally uses the other two, but they will use the same console obviously.

If at all of them are launched in 3 different terminals assuming they had their own main methods, they wont be able to call each other out of the box as they would be in 3 different jvms. In case you can provide some more clarity as to what you are trying to do and why so, may be we can help.

Kedar Parikh
  • 1,241
  • 11
  • 18
0

You are trying to run incorrect file. Your entry point is in MainClass so you should start/execute that class to start your program.

Using java MainClass

Also go through following answers/tutorials for more information

Entry point for Java applications: main(), init(), or run()?

http://www.tutorialspoint.com/java/java_basic_syntax.htm

http://www.programmingsimplified.com/java-source-codes

Community
  • 1
  • 1
Sachin Gorade
  • 1,427
  • 12
  • 32