you can set path like(environmental variable in windows) below
right click on mycomputer->properties->advance->environmental variable->systemvariable->there you set path of your java installation path upto bin
for class path:
right click on mycomputer->properties->advance->environmental variable->uservariable->there you set path of your java class file to execute
Hope This Helps
Joined: Aug 20, 2008
Let's say I want to make a package named "SoundPackage" and put it in the "Packages" folder which has the path "D:\Packages\".And then let's say I want to make a project which uses that package and the project has the path "D:\My Documents\Java Projects\Project". Which path do I have to specify in the "User variable" section of "Environment variables" , the one to the project or the one to the "Packages" folder?
If you are executing from Project folder then add the D:\Packages\ and the current directory (denoted by . (dot)) to the classpath. You have to use the fully qualified class names since your classes are in the packages.
hi first of all the CLASSPATH shows the path where your .class file is present. so you need to update your environment variable naming classpath so that when you run any tool it will first check for that environment variable while executing any .class file. and package is basically nothing but a folder names. "please tell me if i am wrong" so what you have to do is that use the following command:
package <folder name>;
here package is a keyword and the folder name means you have to create a folder and give its name here in place of folder name. example:- for some file suppose puneet.java you want to create a package com.puneet so use this:-
so this will create your file puneet.java inside package com.puneet. and if you want some different file sebastian.java in upper package com but in different inner folder so then go for this:-
so now your file sebastian.java will be created in package com.sebastian
and one more thing while updating your classpath in environment variable, just give the value of variable name CLASSPATH and its value as the path where your .class file is present, but dont give the package name in the path. like
suppose your puneet.java file is present in C:\JDK5.0\src\com\puneet; so while you compile this file, compiler will automatically create your .class file by default in same folder in same package. so while updating your environment variable, just give classpath value as C:\JDK5.0\src; instead of C:\JDK5.0\src\com\puneet; becoz if you do so your runtime will consider will give error as com\puneet is your package name, not a classpath name. [ August 20, 2008: Message edited by: PUNEET MITTAL ]
Are you a real beginner? Just starting? Without complicated applications requiring access to third-party code? Are you using a recent version of Java?
If you can answer yes to those questions, there is a far easier way to handle the CLASSPATH:
Leave it alone and don't do anything with it.
Of course you still have to set up your PATH.
Joined: Oct 13, 2005
To create a package: two ways to do it.
All your classes must have the package declared as the very first statement, before "import" statements.
1: Create a folder with the same name (all lower-case) as the package, and put your java files in that. Navigate there. Compile them by writing javac MyClass.java MyClass2.java Remember that there are classes (client classes) which have dependencies on other classes (supplier classes). You have to compile the "supplier" classes before their clients.
2: Don't create a folder; navigate to the folder one level up from your package, which contains the classes, and compile the classes like this javac -d . MyClass.java MyClass2.java The same thing about supplier classes first applies.
To execute, navigate to the folder one level up (if you used method 2 you will already be there) and write java.mypackage.MyClassWithMainMethod command line arguments