Answers for "how to run java in terminal"

3

run java from terminal

//Run this line to compile
javac programName.java

//Run this line to run
java programName
Posted by: Guest on March-23-2021
1

how to run a java file in terminal

javac FirstJavaProgram.java
Posted by: Guest on August-25-2020
0

java in terminal

jshell
|  Welcome to JShell -- Version 12.0.1
|  For an introduction type: /help intro

jshell> int i=99;
i ==> 99

jshell> System.out.println(i);
99
Posted by: Guest on September-11-2020
0

how to make java run terminal commands

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExecuteShellCommandRuntimeExec {
	public static void main (String [] args) {
		try {
			Process process = Runtime.getRuntime().exec("ls -l"); 
			
			StringBuilder output = new StringBuilder(); 
			
			BufferedReader reader = new BufferedReader(new InputStreamReader (process.getInputStream()));
			
			String line;
			
			while((line = reader.readLine()) != null) {
				output.append(line + "\n");
			}
			
			int exitVal = process.waitFor();
			if (exitVal == 0) {
				System.out.println("Success");
				System.out.println(output);
				System.exit(0);
			} else {
				System.out.println("Something abnormal has haapened :( ");
			}
				
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
Posted by: Guest on October-26-2021

Code answers related to "how to run java in terminal"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language