Java program isn't showing output on Linux terminal [duplicate] - java

This question already has answers here:
How to run and compile java program?
(1 answer)
How to run Java Programs
(4 answers)
Closed 4 months ago.
I'm running a Java program on a Chromebook, and I'm trying to run the file in the Linux terminal. I ran the command javac Main.java, but it shows nothing, not an error, but just straight up nothing.
I have Java installed. The file I'm running has no bugs. I did not make a typo. Everything is perfectly right.
Is there something I'm missing?
user#penguin:~$ javac Main.java
user#penguin:~$

Related

Java Compiler on Windows wont create executable, only .class [duplicate]

This question already has answers here:
How do I run a Java program from the command line on Windows?
(13 answers)
Closed 2 years ago.
Disclaimer: The question has a similar solution and arguably duplicated from "How do I run a Java program from the command line on Windows?", but I still believe it can be helpful to those whom asked the same wrong questions like me.
My mistake, as it can be found in the comments, was to be expecting the compiler to spill out an extensionless executable file (like in C), but instead, I only saw a .class file being created, leading me to run mistakenly java filename.class
If that happens, just run java filename with no extension and the code will run correctly.
I'm a very beginner at java and don't have the option of using it in Linux, so I was following the tutorial from an algorithm course on Coursera from Princeton Uni, and I installed the jdk-11.0.2 from here: https://lift.cs.princeton.edu/java/windows/
Just to see myself getting a class file instead of an executable after running javac file.java
I searched around and couldn't find anything so far, so I hope someone here saw a similar issue at some point.
The code, just to avoid suspiciousness over it:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
NB: IntelliJ on Windows compiles and runs it perfectly through the following command:
"C:\Program Files\Java\jdk-11.0.2\bin\java.exe" "-javaagent:{PATH_TO_INTELLIJ}\lib\idea_rt.jar=64104:{PATH_TO_INTELLIJ}\bin" -Dfile.encoding=UTF-8 -classpath {PATH_TO_MY_PROJECT};{PATH_TO_MY_PROJECT}\.lift\stdlib.jar;{PATH_TO_MY_PROJECT}\.lift\introcs.jar HelloWorld
A java compiler produces compiled code (.class) files.
To run it, you invoke it w/o the extension (i.e. java HelloWorld)
More details: https://beginnersbook.com/2013/05/first-java-program/

I am having trouble using command prompt for java program execution [duplicate]

This question already has answers here:
I could not understand why "javac: file not found: HelloWorld.java"
(2 answers)
Closed 2 years ago.
Can anyone tell me that why when I'm providing the whole path after typing like "javac C:\Java\MyFirstApp.java" then it is compiling. But when I directly go for "javac MyFirstApp.java" it is showing me file not found.
Because you are not in same directory where .java is placed. Change directory to app folder using cd command and type only javac MyfirstApp.java
From what I remember, to execute the program you don't need to inform the extension.
Go to your project's folder and try:
javac Main.java
java Main

Java Program not running in cmd [duplicate]

This question already has answers here:
Java path..Error of jvm.cfg
(23 answers)
Closed 2 years ago.
I am able to compile the java program but not able to run it.
The problem is that java cannot open the .cfg file which is part of JRE 8.
Firstly check if you have permission for running jar.
Then check it your runtime is same as JDK.
Check if you are typing command correctly:
java -jar file.jar
Edit:
It seems like your .cfg file doesn’t exist or it’s corrupted.
Check it and try rebuild it. If it didn’t work you have syntax error somewhere int cfg file.

invoking class file from java program [duplicate]

This question already has answers here:
Java Runtime.getRuntime(): getting output from executing a command line program
(12 answers)
Closed 5 months ago.
Similar question
This question had an issue with filename vs classpath.
I am using classpath in my program and yet was not getting the output.
I searched a lot through various posts, but I was unable to resolve my error.
I have a class file in my D: The file just prints "hello world".
When I run it through command prompt as:
java -cp D:/ Test
it works fine.
But when I run the same inside a main method of another java program as:
Process p = Runtime.getRuntime().exec("java -cp D:/ Test");
I get no output, nor errors.
Can someone help me whats going wrong here?
You need to get InputStream out of the Process and read the input.

compiling java programs [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
javac not recognized
I'm starting in the world of programming in java and I have run across a big problem: i cant compile my programs. when I type the javac command in cmd.exe(im using Windows 7) it displays this:
'javac' is not recognized as an internal or external command, operable program or batch file.
So I can't even test my first program.
I found in a book the following command:
set path=%path%;c:\java\jdk1.6.0\bin
but it doesnt work either.
I downloaded the newest version of the Jdk package just 2 weeks ago.
Look through your C drive for the c:\java folder and make sure you have version 1.6.0 of the jdk
c:\java\jdk1.6.0\bin
This will only work if you give it a path that actually exists. If you don't have 1.6.0, then type in:
set path=%path%;c:\java\<YOUR_ACTUAL_JAVA_VERSION_DIRECTORY>\bin

Categories

Resources