Is it possible to run a java program from command line on windows?How?

0 votes

I'm trying to execute a Java program from the command line in Windows. Is this possible? Any help? Thanx

Apr 18, 2018 in Java by Daisy
• 8,110 points
1,007 views

1 answer to this question.

0 votes

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

Run Command Prompt (Windows+R)

C:\> cd \myprogram

This makes C:\myprogram the current directory.

C:\myprogram> dir

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

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

This tells the system where to find JDK programs.

C:\myprogram> javac filenamehere.java

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

C:\myprogram> dir

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

C:\myprogram> 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!  

answered Apr 18, 2018 by sophia
• 1,400 points

Related Questions In Java

0 votes
1 answer

How to run a Java program from the command line on Windows?

Hello @kartik, In case your Java class is ...READ MORE

answered Apr 9 in Java by Niroj
• 78,520 points
136 views
0 votes
1 answer

How to run a .java file from command line passing arguments in Maven?

Hello @kartik, You could run: mvn exec:exec -Dexec.args="arg1". This will ...READ MORE

answered Jun 3 in Java by Niroj
• 78,520 points
1,639 views
0 votes
1 answer

Is it possible to create a memory leak with Java

Here's a good way to create a memory ...READ MORE

answered May 30, 2018 in Java by Parth
• 4,630 points
1,319 views
0 votes
2 answers

Why it is not possible to define a static method in a Java interface?

Interfaces are concerned with polymorphism which is ...READ MORE

answered Aug 27, 2019 in Java by Sirajul
• 58,210 points
284 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 6, 2018 by Omkar 33,469 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,520 points
4,650 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
10,745 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
1,995 views
0 votes
2 answers

When I am running eclispe on my computer it is throwing error. How to resolve it?

If you have downloaded the 64 bit ...READ MORE

answered Dec 10, 2018 in Java by Sushmita
• 6,890 points
268 views
0 votes
1 answer

What is ?: this operator called in java ? how dose it function?

? :  is the Conditional operator and is ...READ MORE

answered Jun 11, 2018 in Java by sophia
• 1,400 points
241 views