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
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.

Discussions

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
process - Java: Open console programmatically and execute commands from it - Stack Overflow
I need to programmatically open a console (in windows) and from there I need to execute a large command in the console just created. I tried to write to the output stream but had no luck. Here is the More on stackoverflow.com
๐ŸŒ stackoverflow.com
September 24, 2014
How to open the command prompt and insert commands using Java? - Stack Overflow
Is it possible to open the command prompt (and I guess any other terminal for other systems), and execute commands in the newly opened window? Currently what I have is this: Runtime rt = Runtime. More on stackoverflow.com
๐ŸŒ stackoverflow.com
macos - Where is my Java console on OS X? - Ask Different
I can't find the Java console in Preferences nor in Utilities. Can I open the Java console from a Terminal command? Running OS X 10.7.5 and Java version 1.6.0_65 More on apple.stackexchange.com
๐ŸŒ apple.stackexchange.com
June 24, 2014
๐ŸŒ
Oracle
java.com โ€บ en โ€บ download โ€บ help โ€บ enable_console_linux.html
How do I enable and view the Java Console for Linux or Solaris?
Open the Java Control Panel. Enter: ./ControlPanel ยท In the Java Control Panel, click the Advanced tab. Select Show console under the Java Console section.
๐ŸŒ
Oracle
java.com โ€บ en โ€บ download โ€บ help โ€บ javaconsole.html
How do I enable and view the Java Console?
Select Show Console and click OK. NOTE: These instructions apply if you've chosen to place the Java icon in the system tray through the Java Control Panel (Advanced tab) ... Select Open Console.
๐ŸŒ
SolVPS Hosting Blog
solvps.com โ€บ blog
Open Java Control Panel Settings from CMD (Windows) | SolVPS Hosting Blog
August 30, 2017 - 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. Open Command Prompt (Start > Run > cmd) Copy the following into the command line, including quotes: โ€œc:\Program ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to open Java Control Panel with cmd / Java Control Panel - YouTube
This video has been prepared for learning purposes.Video URL- https://youtu.be/z9o2odY3dfgEmail- practicetobeperfect@gmail.com
Published ย  July 31, 2017
Views ย  54K
๐ŸŒ
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
๐ŸŒ
Princeton CS
introcs.cs.princeton.edu โ€บ java โ€บ 15inout โ€บ windows-cmd.html
Java and the Windows Command Prompt
From the Command Prompt, type the java command below. C:\introcs\hello\>java HelloWorld Hello, World If all goes well, you should see the output of the program - Hello, World. If your program gets stuck in an infinite loop, type Ctrl-c to break out. If you are entering input from the keyboard, ...
๐ŸŒ
Quora
quora.com โ€บ Can-we-open-a-command-prompt-using-Java-program
Can we open a command prompt using Java program? - Quora
You can use Runtime to open command line using Java. For example when making my project, I wanted to open cmd from my program and execute command javac <inputted program name>.java .
๐ŸŒ
CodingNomads
codingnomads.com โ€บ how-to-run-java-from-command-line
Executing Java applications from the CLI
A Java application can be entirely written and run from the CLI. In this article, you learned how to write a basic app that prints to the command line.
๐ŸŒ
Shekhar Gulati
shekhargulati.com โ€บ 2010 โ€บ 06 โ€บ 11 โ€บ running-java-control-panel-through-command-line-in-windows-vista
Running Java Control Panel through command line in Windows Vista โ€“ Shekhar Gulati
June 11, 2010 - i work with vista. i lost my teacup ... i am not so savvy in this. ... Go to the place where you installed JRE. Open command prompt and type javaws -version....
๐ŸŒ
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.
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
    
๐ŸŒ
Linux Mint Forums
forums.linuxmint.com โ€บ board index โ€บ main edition support โ€บ software & applications
How do I open Java Control Panel? - Linux Mint Forums
October 31, 2016 - If updatedb is set to run, which I'm assuming is the default, you should be able to type on the command line locate -i controlpanel and locate -k bin/java. ./NAME says to run the executable (bash script, python script, compiled program) from the current directory (A dot is the current directory - ./). Your PATH (echo $PATH) does not need to be searched to locate the executable file. Therefore in this case, the file "ControlPanel" must exist in the directory. If not in your console prompt, the command pwd displays the current directory.