• 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
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

public class access

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've been studying khalid for 1 month.
I thought practicals will be easy after theory.
but when i executed the first program.


1)i got "exception in thread "main" java.lang.NoClassDefFoundError:"
then set it right
by using
set CLASSPATH=c:j2sdk1.4.2_07\bin;%CLASSPATH%;

please help me in setting the classpath and path in environment variables
2) when i tried executing example 1.4 which is Client.java
This Client.java accesses CharStack.java which is having public access and is present in the same folder as Client.java however i get error
Client.java can't resolve symbol
Class CharStack .
i get the error
then i created CharStack.class but still same error.
then i copied CharStack class into Client.java
then i got error CharStack is public and must be declared in a CharStack.java file.

then i have to make
public class CharStack as
class CharStack and execute
or i have to make
public class Client as
class Client and execute.

but what i want to know is how to use the public access in both of them
do i need to set the classpath .
please help me in setting classpath
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Normally CLASSPATH is used to locate the specified jar/class file. not for the specified folder. for example [b] set CLASSPATH = c:\jdk\lib\tools.jar;
You give the path in PATH variable. ex [b] set PATH=c:\jdk\bin;%PATH$;.
Do the following steps. add ;.; in your classpath. It specifies the current working directory. So comiler first check the given class file is available in current folder. If it is not present then after search other jar files.
 
tim bond
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks but what about the public access case
in the client.java
and charstack.java
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear tim ,

you can not make two public class in same file.
so you can get error;

but if you make seperate file for each public class . you can not get error.

you can try.
 
The knights of nee want a shrubbery. And a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic