• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Packages

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to create packages in java? I have a problem in setting CLASSPATH variable and I also have problem in compiling programs in a package.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
packages are created (logically)as they are declared, using the "package" keyword. the JLS governs that. the compiler will create a directory structure that "reflects" your package names. maybe you could post the errors you are getting with yr code, so we could help out?
regs
peter
 
Amna Arif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello
whenever i try to compile a class file in a package after setting CLASSPATH i get the following error message
E:\jdk1.4\bin\lab>javac toy.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
E:\jdk1.4\bin>javac toy.java
error: cannot read: toy.java
1 error
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'javac' is not recognized as an internal or external command,
operable program or batch file.

This is a PATH issue, not a CLASSPATH issue. The CLASSPATH is concerned with locating Java class files. The PATH is concerned with locating executables, like .exe files.
You probably want to adjust your PATH setting to include the location of javac.exe (which is included with your Java 2 SDK installation).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
E:\jdk1.4\bin>javac toy.java
error: cannot read: toy.java

Where is toy.java located? It must not be in the E:\jdk1.4\bin directory. Is it in the E:\jdk1.4\bin\lab directory? If it is, then try E:\jdk1.4\bin>javac lab\toy.java
Note that the CLASSPATH setting isn't concerned with locating Java source files, it specifies the location of compiled classes.
 
Amna Arif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually if there is a class file in a package. To execute it from the package iam setting CLASSPATH but it is not working. The lab package is in JDK1.4\bin\lab. Please help.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
After u set the path for javac compiler and the following is the procedure I used for compiling and accessing my java files in the package.
I have a folder in the F:\Programs\Java\mypack
The CLASSPATH is set to F:\Java\Programs (i.e the classpath has to be set to the parent folder in which the package resides i.e to the F:\Java\Programs because the mypack folder resides in F:\Java\Programs\mypack )
To compile them u need to compile them in the following way.
F:\Programs\Java>javac mypack\*.java
Cheers,
Gaya3
-------------------------------------------------
Beginning is half done
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic