Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Java problem: Could not find or load class

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to java but previously i did some basic programs on my system.... i never got this error message....so i removed java sdk and reinstalled it...
i set PATH variable as C:\Program Files\Java\jdk1.7.0\bin
CLASSPATH variable as C:\Program Files\Java\jdk1.7.0\lib
JAVA_HOME as C:\Program Files\Java\jdk1.7.0

i am unable to run even programs which i executed earlier...
when i compile them ... it is not showing any error message but when i tried to run them(by using java command in command prompt) iam getting error message as "Error: Could not find or load main class Applicant"

PLZZZZ Help me Guys........... sorry for my poor english

THANKS IN ADVANCE
 
Greenhorn
Posts: 6
Eclipse IDE Java Linux
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To check whether JDK got installed properly or not..open command prompt and type javac ->enter
You should get some list of options instead of an error message like javac is not an internal command.
Then you have installed your JDK properly.

Differences between PATH and CLASSPATH is: (both are environmental variables)
PATH - points to bin of your java installation (system variable to tell the OS where is your JDK installed)
CLASSPATH - can say java variable, which is used to tell locations of all jar/zip(classes) files to Compiler.
Classpath is nothing but setting up the environment for Java. Java will use to find compiled classes
eg: If we are using JDBC Driver then we need to keep classes12.jar in classpath, If we are using sevlets future then we need to keep servlet-api.jar in classpath ..
like these so many places we use this.
 
bolisetti sriharsha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply..... when i typed javac and pressed enter.... it shows ..as you said a list of options.... so jdk is installed properly..


BUT STILL I AM UNABLE to exceute java programs
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This might help - https://coderanch.com/t/412282/java/java/we-change-tha-java-version and http://download.oracle.com/javase/tutorial/getStarted/problems/index.html and https://coderanch.com/how-to/java/how-to-create-java-program

If you still have a problem, please post the simple java class you intend to run and copy paste the exact error shown in the cmd prompt.
 
bolisetti sriharsha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

MY PROGRAM



The error i am getting in command prompt

D:\stuff\prgms>java hello
Error: Could not find or load main class hello




 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bolisetti,

1. You have to compile your java class first using the javac command before running it using the java command.
2. I hope you have placed the hello.java (or the .java file you have named) in the D:\stuff\prgms folder.
3. After you compile using javac hello.java you check whether a class file Hello.class is generated in the D:\stuff\prgms folder
4. Then you can execute the class using the command java Hello

Additionally, you do not need to import java.lang package as automatically all the classes in the package gets imported.

And please UseCodeTags

And a warm welcome to the Ranch
 
Ganesh Akondi
Greenhorn
Posts: 6
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes..i second John.

D:\stuff\prgms>javac hello
check manually whether hello.class got created in that folder
then
D:\stuff\prgms>java hello

and as John said, java.lang in base package for java... no need of importing it explicitly.
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ganesh - Welcome to the Ranch
 
Marshal
Posts: 79632
380
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you writing java hello or java Hello? If the class is called Hello, you must not try hello, because Java is case-sensitive.

Try java -cp . Hello

If that works:
Have you set a classpath? Try ECHO %CLASSPATH% (Windows®) or echo $CLASSPATH (*nix). If you have a CLASSPATH set at all, who set it? If you set it yourself, you are probably best off deleting it. If it was set by another application (for example, Quicktime sets itself a system CLASSPATH), edit it by adding . (dot meaning "current working directory") at its beginning, followed by the separator (; for Windows® or : for *nix).

Lots of people, and some books, tell you about the importance of a system CLASSPATH, but it usually does more harm than good, and that advice is mistaken.
 
bolisetti sriharsha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks every one for your answers....
Campbell Ritchie .....Thank You Very Much...you really solved my problem.... But i have a small query what is -cp. and how should i set classpath .....



 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome

cp is an option to specify the class path - the path where to find the class files.

Campbell has suggested to use java -cp . Hello which means search for the class "Hello" in the current working folder (specified by the "." after the -cp option)

So if you have your Hello.class in some other folder say C:/Classes then you have to give the command like java -cp C:/Classes Hello
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic