I want to run a simple hello world java (HelloWorld.java)
program using a batch file. How can i run it and how to
construct a batch file.



I want to run a simple hello world java (HelloWorld.java) program using a batch file. How can i ru..

Answer / abdul hannan

Make a source file suppose Hello.java at particular location
C:\javasrc

class Hello {
public static void main(String args[]) {
System.out.println("Hello World");
}

}

open a notepad and write the below command

cd C:\javasrc
javac Hello.java
java Hello > ab.log

Save this file with extension .bat (e.g "run.bat")

double click on run.bat file to run the Hello.java file. You
can see the output in ab.log file on the same path.

if you want to run bat file on command prompt, just remove
the log file(> ab.log) from the batch file and type run. You
can see the output on command prompt.

Is This Answer Correct ?    19 Yes 3 No

Post New Answer

More Core Java Interview Questions

explain me with a code snippet about the generation and handling of null point exceptions.

1 Answers  


what is translator and it types

1 Answers  


What is hashmap and map?

0 Answers  


What is r * in math?

0 Answers  


Is 64bit faster than 32 bit?

0 Answers  


What is the difference between interpreter and compiling ?

7 Answers   TCS,


What is scope of a variable?

0 Answers   TCS,


Explain the differences between static and dynamic variables?

0 Answers   Fidelity,


What is boolean false?

0 Answers  


Explain about Superclass and Subclass?

6 Answers  


Difference between JDK, JRE, JVM

16 Answers   Deloitte, HCL, Mind Tree, Oracle, Reliance, TCS, ThinkBox,


what is anonymous class in java?

0 Answers  


Categories