To view the Java console, right click on the Java icon in the system tray (assuming you're using Windows) and choose "Open console" - as pictured at the bottom of this page

Answer from George3 on Stack Exchange
🌐
Oracle
java.com › en › download › help › javaconsole.html
How do I enable and view the Java Console?
You can enable the Java Console for the Windows platform using the Java Control Panel or the Java icon displayed in the Windows system tray. ... In the Java Control Panel, click the Advanced tab. Expand the Java console option. Select Show Console and click OK.
Discussions

How do I make my java application open a console/terminal window? - Stack Overflow
Are you talking about a window ... like a console, or you are talking about an actual command line window like the cmd from Windows? 2019-10-22T20:01:40.74Z+00:00 ... @carloswm85 A Swing window. I do not know if it is possible to open a command line window using Windows specific API calls. 2021-01-19T12:07:18.74Z+00:00 ... Double-clicking a jar opens it with whatever application you've associated to it in your OS. By default, javaw[.exe] is normally ... More on stackoverflow.com
🌐 stackoverflow.com
cmd - How do I run a Java program from the command line on Windows? - Stack Overflow
For sure, you should be using a ... . Run java mypackage.Main 2017-08-14T04:09:56.06Z+00:00 ... @ElizabethTurner, I had the same error, and it was because I had opened the grandparent folder and I used a project with local packages at the start of the code. The result: I had multiple projects in the working directory. If you use package [projectfoldername]; in the first lines of your code ... More on stackoverflow.com
🌐 stackoverflow.com
How to get right to "Java" in control panel from cmd line in win7? - Stack Overflow
win +r "control" puts me right into control panel, and into search - I can type 'JAVA', still fast,but is there way to jump right into "java" from cmdline? I just wanna add bit more efficiency to it. More on stackoverflow.com
🌐 stackoverflow.com
Running Java Programs in Windows 10 Command Prompt - Stack Overflow
I recently downloaded Java SDK 8.0 on my computer running Windows 10. However, when I looked on the Internet for how to use Java in the Windows 10 Command Prompt, I was only able to get the javac c... More on stackoverflow.com
🌐 stackoverflow.com
March 22, 2016
🌐
SolVPS Hosting Blog
solvps.com › blog
Open Java Control Panel Settings from CMD (Windows) | SolVPS Hosting Blog
August 30, 2017 - There is a strange bug on Windows 10 / Server 2016 where, after installing Java, one can't find Java in the start menu. As a a workaround, or if you need to launch the Java Control Panel from a script or for other reasons, follow the steps below.
🌐
Ixiasoft
ixiasoft.com › documentation › IXIASOFT_CCMS › 5.0 › Administration_Guides › per1389986400062_7.html
Turn on the Java Console
This procedure describes how to turn on the Java Console and enable its debugging and logging options.
🌐
Make Tech Easier
maketecheasier.com › home › computing › windows › how to run a java program from the command prompt
How to Run a Java Program from the Command Prompt - Make Tech Easier
July 16, 2025 - Before you can run a Java program on your computer, you’ll need to have Java installed, which you can verify as shown. Open Command Prompt in Administrator mode, and type: java -version.
🌐
Oracle
docs.oracle.com › javase › 10 › deploy › java-control-panel.htm
9 Java Control Panel
To start the Java Control Panel from the command line, enter <JRE installation home>\bin\javacpl.exe on Windows, or <JRE installation home>/bin/jcontrol on macOS or Linux.
Find elsewhere
Top answer
1 of 14
21

I found this while looking for an answer myself, I ended up writing this bit:

/**
 * This opens a command line and runs some other class in the jar
 * @author Brandon Barajas
 */
import java.io.*;
import java.awt.GraphicsEnvironment;
import java.net.URISyntaxException;
public class Main{
    public static void main (String [] args) throws IOException, InterruptedException, URISyntaxException{
        Console console = System.console();
        if(console == null && !GraphicsEnvironment.isHeadless()){
            String filename = Main.class.getProtectionDomain().getCodeSource().getLocation().toString().substring(6);
            Runtime.getRuntime().exec(new String[]{"cmd","/c","start","cmd","/k","java -jar \"" + filename + "\""});
        }else{
            THEMAINCLASSNAMEGOESHERE.main(new String[0]);
            System.out.println("Program has ended, please type 'exit' to close the console");
        }
    }
}

not sure if my answer is still relevant, but feel free to use it with the comment kept in o/

Only flaw I can think of is that it leaves the cmd window open after the program completes.

Usage: place this class in the same package as your main class and set it as the main class, it will open a command prompt window if one is not open, or if one is open launch the main class. Name / location of jar file is automatic. Designed for windows, but if you want it for another system just message me and I'll fix it. (I could do OS detection but I'm lazy and just making this so I can turn in a double-click jar file to my professor who uses windows).

2 of 14
5

If you want full control, you can implement a Console window in Swing which does what you have now.

If you cannot open said window (if headless) or the user asks for it on the command line, then just default to your current behaviour.

Top answer
1 of 13
274

Source: javaindos.

Let's say your file is in C:\mywork\

Run Command Prompt

CopyC:\> cd \mywork

This makes C:\mywork the current directory.

CopyC:\mywork> dir

This displays the directory contents. You should see filenamehere.java among the files.

CopyC:\mywork> set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin

This tells the system where to find JDK programs.

CopyC:\mywork> javac filenamehere.java

This runs javac.exe, the compiler. You should see nothing but the next system prompt...

CopyC:\mywork> dir

javac has created the filenamehere.class file. You should see filenamehere.java and filenamehere.class among the files.

CopyC:\mywork> java filenamehere

This runs the Java interpreter. You should then see your program output.

If the system cannot find javac, check the set path command. If javac runs but you get errors, check your Java text. If the program compiles but you get an exception, check the spelling and capitalization in the file name and the class name and the java HelloWorld command. Java is case-sensitive!

2 of 13
121

To complete the answer :

  1. The Java File

    CopyTheJavaFile.java
    
  2. Compile the Java File to a *.class file

    Copyjavac TheJavaFile.java
    
    • This will create a TheJavaFile.class file
  3. Execution of the Java File

    Copyjava TheJavaFile
    
  4. Creation of an executable *.jar file

    • You've got two options here -

      1. With an external manifest file :

        • Create the manifest file say - MANIFEST.mf

        • The MANIFEST file is nothing but an explicit entry of the Main Class

        • jar -cvfm TheJavaFile.jar MANIFEST.mf TheJavaFile.class

      2. Executable by Entry Point:

        • jar -cvfe TheJavaFile.jar <MainClass> TheJavaFile.class
  5. To run the Jar File

    Copyjava -jar TheJavaFile.jar
    
🌐
Codemia
codemia.io › home › knowledge hub › how do i run a java program from the command line on windows?
How do I run a Java program from the command line on Windows? | Codemia
January 27, 2025 - Save this file as HelloWorld.java in a convenient location, such as C:\JavaPrograms\. Open the command prompt, navigate to the directory where your Java file is located, and compile the Java program using the javac command:
Top answer
1 of 2
1

Java doesn't actually have to be installed. You can run any Java that's available to you.

This is sometimes useful for running Java from a network share.

Try running the java.exe program by fully qualifying it. If it runs that way, your problem is with your PATH.


To illustrate that you can run any Java by qualifing it, I have 9 JDK's and 1 JRE installed:

  • 32-bit JDK: Versions 1.4, 5, 6, 7, and 8
  • 64-bit JDK: Versions 5, 6, 7, and 8
  • 32-bit JRE: Version 8

Copied from a single command prompt window:

C:\>"C:\prog\java32\jdk1.4.2_19\bin\java.exe" -version
java version "1.4.2_19"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_19-b04)
Java HotSpot(TM) Client VM (build 1.4.2_19-b04, mixed mode)

C:\>"C:\prog\java32\jdk1.5.0_22\bin\java.exe" -version
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) Client VM (build 1.5.0_22-b03, mixed mode)

C:\>"C:\prog\java32\jdk1.6.0_45\bin\java.exe" -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)

C:\>"C:\prog\java32\jdk1.7.0_79\bin\java.exe" -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) Client VM (build 24.79-b02, mixed mode, sharing)

C:\>"C:\prog\java32\jdk1.8.0_51\bin\java.exe" -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) Client VM (build 25.51-b03, mixed mode)

C:\>"C:\prog\java64\jdk1.5.0_22\bin\java.exe" -version
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)

C:\>"C:\prog\java64\jdk1.6.0_45\bin\java.exe" -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

C:\>"C:\prog\java64\jdk1.7.0_79\bin\java.exe" -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

C:\>"C:\prog\java64\jdk1.8.0_51\bin\java.exe" -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

C:\>"C:\Program Files (x86)\Java\jre1.8.0_51\bin\java.exe" -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) Client VM (build 25.51-b03, mixed mode, sharing)
2 of 2
1

Open command prompt cmd and type where java , this will output where java executable is, then you can go to System Propreties>Advanced>Environement Variables> (Right click on computer and click on Propreties) and add the where java output to the PATH variable separated with a semi-colon ;

🌐
Oracle
java.com › en › download › help › win_controlpanel.html
Where is the Java Control Panel on Windows?
Platform(s): Windows 10, Windows 2008 Server, Windows 7, Windows 8, Windows Server 2012, Windows Vista, Windows XP · Starting with Java 7 Update 40, you can find the Java Control Panel through the Windows Start menu. ... Right-click on the Start button and select the Control Panel option. In the ...
🌐
Princeton CS
introcs.cs.princeton.edu › java › 15inout › windows-cmd.html
Java and the Windows Command Prompt
Prepend C:\Program Files\Java\jdk1.6.0_27\bin; to the beginning of the PATH variable. Click OK three times. You will type commands in an application called the Command Prompt. Launch the command prompt via All Programs -> Accessories -> Command Prompt. (If you already had a command prompt window ...
🌐
Helpserve
pearsonsupport.helpserve.com › knowledgebase › article › View › 479 › 2 › how-do-i-enable-and-view-the-java-console
How do I enable and view the Java Console? -
September 7, 2011 - Product(s): General ISBN: -- Category: General User Type: General Item: How do I enable and view the Java Console · The Java Console provides information about the Java version, user home directory, and any error message that occurs while running product which supports Java plug-in.
🌐
Stack Overflow
stackoverflow.com › questions › 23655606 › java-console-window-not-appearing
java console window not appearing - Stack Overflow
... Sign up to request clarification or add additional context in comments. ... Bring up the Windows Charms bar through Windows key + W. Search for "Java Control Panel" and open that up.
🌐
Reddit
reddit.com › r/javahelp › running java in command prompt?
r/javahelp on Reddit: Running Java in Command Prompt?
February 2, 2021 -

Second Edit: May have fixed the Environment Variables to work with JAVA_HOME. Minor change to what was printed but was able to run the file like so:

C:\Users\Test>cd Documents\MyFirstProgramFolder

C:\Users\Test\Documents\MyFirstProgramFolder>java MyFirstProgram
We did it! Again! Number 3!

Again, making sure I was in the right directory was the first issue, but now I may have the Environment Variables fixed. I hope at least. Thank you again everyone.

Edit: Have my issue mostly solved. I am able to compile and run the code. cd-ing to the correct directory seemed to be the issue in the command prompt and that is all I really need for now. Thank you to everyone who took the time try to help me!

Hello! I am new to learning Java but have been stuck on a single issue for the past day and a half. I have recently started reading Head First Java to try and teach myself Java. I took a single programming class that was taught in Java 3-4 years ago. All of the programming experience I have has always been in some sort of IDE. In Head First Java they want you to work through the command line after writing code. I have been entirely unsuccessful at setting up Java to work through the command prompt. I have now tried to download 2-3 different JDK's, followed 2-3 tutorials on how to just get "Hello World" to print, and followed a guide on how to set up the Java Environment. None have been successful and I am frequently met with the below errors/issues when I try to parse together my understanding trying to fix the issue. I would really like to learn how to actually do things without the need of an IDE. Any help at all would be greatly appreciated! So the question summed up, is more or less where am I going wrong for setting up the Java environment, or JVM?

In the Command Prompt:

C:\Users\Test>"C:\Program Files\Java\jdk1.8.0_161\bin"\Javac MyFirstProgram.java

javac: file not found: MyFirstProgram.java

Usage: javac <options> <source files>

use -help for a list of possible options

In Windows Powershell:

PS C:\Users\Test\Documents\MyFirstProgramFolder> "C:\Program Files\Java\jdk1.8.0_161\bin"\javac MyFirstProgram.java

At line:1 char:41

+ "C:\Program Files\Java\jdk1.8.0_161\bin"\javac MyFirstProgram.java

+ ~~~~~~

Unexpected token '\javac' in expression or statement.

+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException

+ FullyQualifiedErrorId : UnexpectedToken

Below are some of the websites I have tried:

https://www.instructables.com/How-to-Make-Your-First-Computer-Program/ - This instructables link is what I just used to receive the above responses.

https://www.tutorialspoint.com/java/java_environment_setup.htm

https://www.geeksforgeeks.org/setting-environment-java/

The Code:

class MyFirstProgram {

    public static void main(String[] args) {
            System.out.println("Hello, World");
    }
}
Top answer
1 of 6
2
move the quote to the end of the args[0] "C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe" MyFirstProgram.java Java is a compiled language and not interpreted, so there is no actual IDE - but maybe a Java-pro knows one. There are some websites, where you can play around with classes...
2 of 6
2
First, I would add C:\Program Files\Java\jdk1.8.0_161\bin to your system PATH environment variable - this will allow you to use the Java commands without including the entire path: Right click Computer Click the properties On the left pane select Advanced System Settings Select Environment Variables Under the System Variables, Select PATH and click edit,and then click new and add path as C:\ProgramFiles\Java\jdk1.8.0_161\bin (depending on your installation path)and finally click ok (credit to https://stackoverflow.com/questions/32241179/setting-up-enviromental-variables-in-windows-10-to-use-java-and-javac for putting in the steps so I didn't have to) Once done, you should be able to use javac MyFirstProgram.java instead of putting the entire path in for javac and mucking about with quotes :) Note: you will need to restart the command prompt for the path update to take effect :) Second, in your examples above your error is file not found for the command prompt, and your folder is different than the one showing for powershell ( C:\Users\Test for command prompt and C:\Users\Test\Documents\MyFirstProgramFolder for powershell) so I'm guessing the error was due to MyFirstProgram.java not being in the folder the command prompt was in. So if you are in C:\Users\Test\Documents\MyFirstProgramFolder (assuming this is the location of your java file) and did the Path fix above, you can just use javac MyFirstProgram.java or "C:\Program Files\Java\jdk1.8.0_161\bin\javac.exe" MyFirstProgram.java if you didn't modify the path. Edit to add: both of those commands should work in powershell as well depending on whether you set the PATH variable or not assuming you are in the folder containing MyFirstProgram.java.