Forums.Sureshkumar.net : A Perfect Place to Share Knowledge         Blogs     Games    Magazines    

"Sharing knowledge does not lessen your store, often it gets you more. Sharing plays a key role in relationships and bonding, happens in small steps and is assisted through community membership."

Go Back   SURESHKUMAR.NET FORUMS > TECHNICAL DISCUSSIONS > JAVA Technologies
Register FAQ Members List Calendar Games Blogs Search Today's Posts Mark Forums Read

   

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 06-12-06, 06:43 PM   #1 (permalink)
Junior Member
 
Join Date: Oct 2006
Age: 26
Posts: 23
Thanks: 7
Thanked 0 Times in 0 Posts
Thanks: 7
Thanked 0 Times in 0 Posts
Rep Power: 3 kiranmayi_p1 is on a distinguished road
classpath: why and how to set?

hi friends

kindly explain me the following

environment variables
need to set classpath
how to set
what value to be given to classpath variable and why

Thanks
kiranmayi
kiranmayi_p1 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-12-06, 09:02 PM   #2 (permalink)
Super Moderator
 
sk_kireeti's Avatar
 
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117
Thanked 241 Times in 198 Posts
Thanks: 117
Thanked 241 Times in 198 Posts
Blog Entries: 4
Rep Power: 51 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
Re: classpath

Kiranmayi,

Environment variables are global variables in the session. They can be accessed by any application. For example, name of the OS, name of the user who logged in, what is OS files location and so on.

Classpath will tell jvm in which folders it has to search for class/jar/war files. Otherwise every time you call a class file, it has to search entire system to load it.

You can set classpath as below from dos prompt -
set classpath = %classpath%;c:\jdk1.5\bin;c:\jdk1.5\lib;

Here I assume that jdk1.5 version is installed in c:

Thanks,
Krishna
sk_kireeti is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to sk_kireeti For This Useful Post:
kiranmayi_p1 (07-12-06)
Old 07-12-06, 05:08 PM   #3 (permalink)
Junior Member
 
Join Date: Oct 2006
Age: 26
Posts: 23
Thanks: 7
Thanked 0 Times in 0 Posts
Thanks: 7
Thanked 0 Times in 0 Posts
Rep Power: 3 kiranmayi_p1 is on a distinguished road
Re: classpath: why and how to set?

Hi,

Thanks Krishna for the information. Now I understand what is environment variable, Here, I have one doubt.

You said:
Classpath will tell jvm in which folders it has to search for class/jar/war files. Otherwise every time you call a class file, it has to search entire system to load it.

If we wont set classpath, the .java file gets compiled. But it wont execute. Then we get error saying that "Class not found ". That means, the .class file is not found. But after compiling .java file, the .class file is saved in the same directory , right? Then why is it saying class not found? and why are we giving bin and lib directories as classpath to jvm when the .class file is saved in the same directory?


One more doubt is, you said that if we wont set classpath, then the jvm has to search the entire system for loading the class files, does it mean that if we wont set classpath, the jvm searches the entire system and then finds the class files wherever they are located(incase, claspath not set). Then in that case, it should take some extra time to search the classfile, but why is it not executing at all.

My doubts are at very basic level. Kindly clarify.
Kiranmayi.
kiranmayi_p1 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 07-12-06, 08:48 PM   #4 (permalink)
Super Moderator
 
sk_kireeti's Avatar
 
Join Date: Feb 2006
Location: Hyderabad
Posts: 2,355
Thanks: 117
Thanked 241 Times in 198 Posts
Thanks: 117
Thanked 241 Times in 198 Posts
Blog Entries: 4
Rep Power: 51 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
Re: classpath: why and how to set?

Kiranmayi,

It is not necessary that .java file and .class file are in the same folder. Generally when project is packaged, only class files will go into packing and not .java files. In that case both .class file and .java files are in different places/locations.

I am sorry if I confused you with my statement. But I gave that statement to explain you what will happen if we don't have classpath.

Why javac will accept files from local folder (files in bin dir)?
This is because, for javac command uses environment variable called PATH where as java command will use CLASSPATH. Enter the following command in DOS and you will see your java bin dir in the output.

C:\PATH

Why not javac will accept files from local folder?
Type the following command in dos and see the output. May be it will help you. But I am not sure.

SET CLASSPATH = %CLASSPATH%;.;

The . at the end will specify the current directory (the directory from which you are issuing the javac command.

NOTE: If you are storing your .java (PATH env variable) and .class (CLASSPATH environment variable), then the corresponding variables should have those folder details/path. Otherwise you can't see any output and it will error out.

Thanks,
Krishna
sk_kireeti is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to sk_kireeti For This Useful Post:
kiranmayi_p1 (08-12-06)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +6.5. The time now is 02:23 PM.





Search Engine Optimization by vBSEO 3.1.0