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.
Answer Posted / 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 View All Answers
What is the purpose of the wait(), notify(), and notifyall() methods in java programming?
Can we declare the static variables and methods in an abstract class?
Can you access non static variable in static context?
What is percentage in java?
Can we use string in switch case in java?
What about static nested classes in java?
What is autoboxing and unboxing?
What are "class access modifiers" in Java?
Is null or empty java?
Can we define constructor in inner class?
What is abstraction in java?
What is the difference between stringbuffer and stringbuilder?
Is break statement can be used as labels in java?
What is a void method java?
What are the types of collections in java?