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

What is unmodifiable collection in java?

0 Answers  


What is member in java?

0 Answers  


What is a default package ?

7 Answers  


What is the difference between an if statement and a switch statement?

0 Answers  


Define "Access specifiers" in java.

0 Answers   HCL,






what value will be return by the read() method once it reaches the end-of-file? a. Throws EOException b. Return null c. Return -1 d. Read method return nothing, because it is void method

1 Answers  


Tell me about your ability to work under pressure

0 Answers   AXA,


1).Is Object class abstract or not? 2).Is main method(public static void main(String args[])low priority thread or high priority thread?

3 Answers   TCS,


Can a lock be acquired on a class?

3 Answers  


What is the method in java?

0 Answers  


does java support default argument in Method?

1 Answers  


what is the form of storage space in java?

5 Answers  


Categories