• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding main is not found in command prompt but executed in IDE

 
subash subbu
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
Public class Test{ void disp(){Sop("hello")}}
class TestApp{ public static void main(String[] args){Test obj=new Test(); obj.disp(); Sop("hi");}}
FILE NAME: Test.java
It is not executed in command prompt.But executed in Myeclipse IDE. Tel me reason.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this has nothing to do with jobs, i'll move it to a better forum...

Please try and choose more carefully which forum you post in next time.

Can you please elaborate on what the problem is, and post your actual code? What does "It is not executed in command prompt" mean - do you get an error message of some kind?
 
subash subbu
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It compiles successfully with Test.java file name.But when we run we get an error main() is not found. But it successfully executed in IDE Myeclipse how?
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Radha Krishnna wrote:...successfully executed in IDE Myeclipse how?


IDEs(like MyEclipse) do something for you. Like setting classpath

May be you would like to visit this thread as well.
 
subash subbu
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply buy i want some more clarity
 
subash subbu
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think maybe it is not related to classpath. in this code main method is not there in public class of the file name
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you presented will not compile. "Public" isn't valid. you are missing a semi-colon. "Sop" is not a valid method call.

Yes, i know what you mean in all cases, but if you can't be bothered to give us the ACTUAL code you are running, do you really expect anyone here to offer you much help? Your job, when asking a question, is to make it as EASY as possible for someone to help you. You are much more likely to get your question answered.
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Radha Krishnna wrote:It compiles successfully with Test.java file name.But when we run we get an error main() is not found. But it successfully executed in IDE Myeclipse how?

When we run...... I think you running your Test class which does not have the main() method. So compile and execute your TestApp file.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rameshwar Soni wrote:
Radha Krishnna wrote:It compiles successfully with Test.java file name.But when we run we get an error main() is not found. But it successfully executed in IDE Myeclipse how?

When we run...... I think you running your Test class which does not have the main() method. So compile and execute your TestApp file.


There are few things with it,
1. file name and public class (should they be same or different, if same why and if different how?)
2. do i want to run a class or do I want to run a method or do I want to run one and only main method, is it possible that I can run both a class and method?

 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the IDE is capable of locating and running the main types - in this case the TestApp class. When you compile your Test.java you should get two classes created - Test.class and TestApp.class... so try running the cmd - java TestApp
 
subash subbu
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi john i already tested java TestApp on command prompt but it gives class not found...
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you have posted real code with the commands and the errors you got as Fred suggested, you should have got the answer by this time.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic