GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes not able to run my first java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "not able to run my first java program" Watch "not able to run my first java program" New topic
Author

not able to run my first java program

dhruv garg
Greenhorn

Joined: Dec 24, 2011
Posts: 7

my program is able to pass the compilation test.but when i run the program its gives error

"C:\Users\DHRUV\My Documents\java>javac innerclass.java

C:\Users\DHRUV\My Documents\java>java innertest
Error: Could not find or load main class innertest

here the file name is innerclass.java and the main class name is innertest.

kindly help me out
vinayjg kumar
Greenhorn

Joined: Dec 24, 2011
Posts: 5
As I know, The file name should match the name of class. Try with that...
dhruv garg
Greenhorn

Joined: Dec 24, 2011
Posts: 7

file name should be same as main class only when the main class is public.
anyways i changed the file name too but its not working.
vinayjg kumar
Greenhorn

Joined: Dec 24, 2011
Posts: 5
Can you post your code?
dhruv garg
Greenhorn

Joined: Dec 24, 2011
Posts: 7

it is happening with every program.
if you want to see my code you can see but i think it will be of no use.there must be some problem with system...i dont know...

here is the code:-

class A
{
private int a;
A(int a)
{
this.a =a;
}
void show()
{
System.out.println("a="+a);
} // End of show()
}// End of class A
public class innertest
{
public static void main(String args[])
{

A a1 = new A(20){
public void show()
{
super.show();
System.out.println("Hello");
}
public void display()
{
System.out.println("Hi");
}
};
a1.show();
// a1.display();
}
}
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Dhruv, You got to check this tutorial to help you with your first java program.

And please UseCodeTags for posting the code. That way it makes the code more presentable and readable. You can your post and add the code tags


Mohamed Sanaulla | My Blog
dhruv garg
Greenhorn

Joined: Dec 24, 2011
Posts: 7

i did what was told in the tutorial but still my program is not working
dhruv garg
Greenhorn

Joined: Dec 24, 2011
Posts: 7

it is happening with every program....not with a particular program
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Have you set the classpath variable? If yes what is the value that you have set?
dhruv garg
Greenhorn

Joined: Dec 24, 2011
Posts: 7

thank you for your advice. i didnt reboot my system after changing the path and JAVA_HOME variables. now every thing is working fine.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

dhruv garg wrote:thank you for your advice. i didnt reboot my system after changing the path and JAVA_HOME variables. now every thing is working fine.


I dont think a reboot is required. Just restarting the terminal/cmd should work Anyways glad that you got it working
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39045
    
  23
Mohammed was on about classpaths, but you need to realise that setting a system classpath can cause more harm than good. If you don’t already have a system classpath, leave well alone.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Is there a possiblity that a virus can infect the JDK in the System?

I had a simple netbean application and when i tried to run that application the page was blank i just restarted the machine and it was working fine


http://www.lifesbizzare.blogspot.com || OCJP:81%
 
GeeCON Prague 2014
 
subject: not able to run my first java program