Saturday, May 22, 2010

I have a problem with my first java program...i have installed latest javasdk and java runtime environment als

this is my prog


class printer


{


public void print()


{


System.out.println("Hello from java");


}


}





public class app


{


public static void main(String[] args)


{


printer printer1 = new printer();


printer1.print();


}


}





when i tried to run it it didn't work....


then i entered the sdk bin path in the path(using the environmental variable setting) and also noticed that there is no CLASSPATH variable in the list!!!


any way after adding the sdk bin path it get compiled...


and generated the clases files for printer and app


but when i tried to run it with the java app command it get an error


(Exception in thread "main" java.lang.NoClassDefFoundError: C:\work\New\app)





also when i tried to place them in seperate files printer.java and app.java and compiled separatly printer.java get compiled but when tried to run app.java i got an error message


C:\work%26gt;javac app.java


app.java:1: '.' expected


import printer;


^


1 error


Please help..i will gave u more info if needed

I have a problem with my first java program...i have installed latest javasdk and java runtime environment als
Your code is fine. The problem is that the interpreter cannot locate the class file (app.class). Either add the path of the class to the classpath environment variable (if it does not exist then just create one), or run the interpreter (i.e type java app) from inside the directory in which the class file resides.
Reply:Go to the directory where the class app resides and give command java app
Reply:do like this





in command prompt go to the directory where app.java is stored


type this





%26gt;set path="d:/j2sdk1.4.2_04/bin";


%26gt;javac app.java


%26gt;set classpath=%classpath%;


%26gt;java app





substitute your installation path of java/bin folder in place of "d:/j2sdk1.4.2_04/bin"





want more help? contact me on silentsakky@gmail.com
Reply:Why aren't you trying to start with more easy programs....you started your first program with clases.....try something more easy and then dezvolt it....it will be more easy for you to learn.
Reply:Make sure u have the following setup:


1) Command javac recognized on command prompt without giving the any file name.


2) when u complile u will get a .class file created in the same path where ur .java file is located.


3) During execution the java will look for the class files in the path mentioned in ur CLASSPATH.


4) if u do not have any CLASSPATH varible u can add it as follows:


on command prompt. C:\set CLASSPATH=your .java dir path.


5) Run the program just by giving


C:\java filename(without .class or .java)





Hope it helps


No comments:

Post a Comment