Compiling and running files in a package
Page 1 of 1
Compiling and running files in a package
Story(Skip this part and continue to main part if you have a short time):
Today I wrote a program in Java that takes String arguments in main method.
Big deal.
And I was successful executing it using eclipse as well.
However, I faced a new problem now. I don't know how to give runtime arguments in main method using eclipse.
So..
I decided to compile it using javac command.
And it was sending me errors saying that it can't find main method when I tried
java MyJava
Main Part
Actually, you have to insert package description in Javac command like this.
Notice the . after -d
if the Myjava.java has package ios; at its starting, the MyJava.class file will be created in ios folder.
Now you have to execute the class file like this:
and voila You have learnt how to execute java file using package!!
Today I wrote a program in Java that takes String arguments in main method.
Big deal.
And I was successful executing it using eclipse as well.
However, I faced a new problem now. I don't know how to give runtime arguments in main method using eclipse.
So..
I decided to compile it using javac command.
- Code:
javac MyJava.java
And it was sending me errors saying that it can't find main method when I tried
java MyJava
Main Part
Actually, you have to insert package description in Javac command like this.
- Code:
javac -d . MyJava.java
Notice the . after -d
if the Myjava.java has package ios; at its starting, the MyJava.class file will be created in ios folder.
Now you have to execute the class file like this:
- Code:
java ios/MyJava
and voila You have learnt how to execute java file using package!!
Similar topics
» Compiling java Using Notepad++
» creating and running applet
» Recover files 2.02
» How to download the files
» undelete your files
» creating and running applet
» Recover files 2.02
» How to download the files
» undelete your files
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford