• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question about how to import class.  RSS feed

 
Jack Robertson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given a directory structure,
com|
-----|headfirst|Souce|a.java
-----------------|Class|b.class

Suppose I want to import class b in the source code of a.java, how should I write that? Thanks.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Robertson wrote:Given a directory structure,
com|
-----|headfirst|Souce|a.java
-----------------|Class|b.class

Suppose I want to import class b in the source code of a.java, how should I write that? Thanks.




Except that package names (such as "Class") are, by convention, supposed to be all lower-case, and class names (such as "b") are, by convention, supposed to start with an uppercase letter.

rc
 
Jack Robertson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
Here's another one, do I need to set any classpath when invoking the javac command?
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No there is no need to set classpath while using javac command.......................classpath is set to tell java where you can find the class files and we use javac to make class files therefore there is no need to set classpath at the time of using javac command
 
Ogeh Ikem
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Robertson wrote:do I need to set any classpath when invoking the javac command?

You may need to set a classpath when invoking the javac command if the .java file you're trying to compile, uses a compiled class. One of the options to the javac command is -classpath. Read more here.
 
Jack Robertson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rameshwar Soni wrote:No there is no need to set classpath while using javac command.......................classpath is set to tell java where you can find the class files and we use javac to make class files therefore there is no need to set classpath at the time of using javac command


Thank you. But I just want to make sure that when use "import" in your source code, do I need to write the absolute path of the class I'd like to use or should I use the relative path that can be found by the current directory which is also the default one for the javac invocation?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!