Results 1 to 15 of 15
Thread: Class paths and Packages issue
- 07-11-2012, 02:03 AM #1
Class paths and Packages issue
I have a few packages and files that I am using.
To quickly explain my issue, I have 3 class files.
- First class file is in <parent directory>/
- Second class file is in <parent directory>/com
- Third class file is in <parent directory>/com/fo
I want the first and second file to be able to access the information and functions of the third file. How can I get this to work?
At the moment, the package names for the second class file isJava Code:package com;
Java Code:package foo;
How can I format the java 'package' line to give all of my files access to the third file. If this is not possible, please tell me.
A visual example of what I am currently doing is here:
File 1: /
Java Code:import com.*; public class my_first_class { public static void main(String args[]) { my_second_class c2 = new my_second_class(); //this works at the moment } }
Java Code:package com; public class my_second_class { my_third_class c3 = new my_third_class(); //this works at the moment }
Java Code:package foo; public class my_third_class { //Some code that is needed in both the first and second class. }
Last edited by pbrockway2; 07-12-2012 at 04:37 AM. Reason: marked as solved
My API:Java Code:cat > a.out || cat > main.class
-
Re: Class paths and Packages issue
First off, *every* class should be in a package. You should not be using the default package anywhere. Next of all, if you need access to a class then you'll want to import that class using its full name, package included.
- 07-11-2012, 02:42 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Class paths and Packages issue
To keep things straight (and simple) make your package structure analogous to the file structure on disk.
So... Put the first class into a package (creating a directory for it - a sibling of com - if necessary).
Make the third class com.foo.ThirdClass not foo.ThirdClass. Ie change the package line in the thrid class to "package com.foo".
With these changes all three classes will be found providing the directory (folder) containing com is part of the classpath.
-----
Classes should begin with a CapitalLetter. Although often abbreviated in code, a class includes the package part of its name. Think of them that way and recognise that foo.bar.Baz - to give it its full name - will correspond to the .class file <somewhereOnClasspath>\foo\bar\Baz.class.
- 07-11-2012, 03:28 AM #4
Re: Class paths and Packages issue
Thank you pbrockway2
With your advise, I was able to work everything out. Consider this thread solved!My API:Java Code:cat > a.out || cat > main.class
- 07-11-2012, 03:47 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Class paths and Packages issue
Great. I'm glad you've got it sorted out. There should be a link on this page (somewhere!) letting you mark the thread as closed.
- 07-11-2012, 11:28 PM #6
Re: Class paths and Packages issue
Where is the solve button!!!!!!!!!!!!!!!!!!!!!!
My API:Java Code:cat > a.out || cat > main.class
- 07-11-2012, 11:59 PM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Class paths and Packages issue
- 07-12-2012, 02:34 AM #8
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Re: Class paths and Packages issue
Hey pbrockway2!
I was actually discussing this issue with another moderator earlier today. When I go to my thread and click on 'thread tools', the first 4 options show up but not the 5th 'Mark this thread as solved' option. I have a standard account with standard privileges as far as I know. It seems that there is not a way for a non-moderator to close a thread.
- 07-12-2012, 02:55 AM #9
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Class paths and Packages issue
Umm... It could be that the "mark as solved" functionality is broken.
Jos' advice in that thread was "edit your original post; go to the 'advanced mode' and set the prefix of the title to '[solved]'" which might work in this case as well.
[Edit] Yes, that seems to be the way to do it. (Eg http://www.java-forums.org/forum-lob...t-testing.html) Ignore the faq and edit the original post (in advanced mode) to add the [Solved] prefix.Last edited by pbrockway2; 07-12-2012 at 03:01 AM.
- 07-12-2012, 03:02 AM #10
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Re: Class paths and Packages issue
Yes, I actually had an in-depth conversation with Jos about this
What I've found out is that the option to edit a post expires for us members after a certain amount of time (I think it might be 24 hours.) Here is a thread that I created yesterday morning: http://www.java-forums.org/new-java/...mpliation.html
My first two posts have the 'reply', 'reply with quote', and 'multi-quote this message' buttons, but there is no 'edit post' button. However, my subsequent 4 posts that I made today do have the 'edit post' button.
So it seems that if a post takes longer than a day to be answered, it can't be solved by a non-moderator.
Edit:I realize that the thread I linked to is already solved, that's because a mod did it for me.Last edited by awinston; 07-12-2012 at 03:11 AM. Reason: format
- 07-12-2012, 04:36 AM #11
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Class paths and Packages issue
I'll bring it to the attention of the other moderators and link to here. The functionality used to be accessible via the "thread tools" (as described in the faq) rather than editing a post and that's a better place for it: edits of posts long after the fact is^H^H are annoying.
[edit]... but so are grammar mistakesLast edited by pbrockway2; 07-12-2012 at 04:45 AM.
- 07-12-2012, 05:01 AM #12
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Re: Class paths and Packages issue
Just curious...do moderators have the power to play with the code of this website? Or do you guys have to contact somebody else?
- 07-12-2012, 05:44 AM #13
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Class paths and Packages issue
No. We have the power to take out the spam trash, the glory of tidying up posts put in the wrong forum and now, it seems, the glamour of marking solved threads as solved. Things of that sort. I guess we can also ban users, but that's seldom done here (I never have for instance).
Any changes to the site are made by the "forum's owner". Who seems to be referred to always as the "forum's owner": an anonymity that strikes me as having a sort of James Bond feel to it.
There's a "Suggestions and Feedback" forum (near the bottom of the forum list) where you can ... make suggestions and give feedback.
- 07-12-2012, 06:02 AM #14
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 9
Re: Class paths and Packages issue
Are you...suggesting
...that I make a post about solving threads in that forum?
- 07-12-2012, 06:10 AM #15
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Similar Threads
-
How to find which packages are still needed to be imported in a class?
By h_robert64 in forum NetBeansReplies: 1Last Post: 04-03-2012, 10:29 AM -
Timer Class Issue
By CuppaCoffee in forum New To JavaReplies: 3Last Post: 01-05-2012, 11:31 PM -
Class cast issue
By AedonetLIRA in forum New To JavaReplies: 5Last Post: 11-19-2010, 05:34 PM -
Calendar class issue
By OlegKo in forum New To JavaReplies: 3Last Post: 10-24-2010, 07:36 PM -
Importing packages from the packages within same application.
By sta2003 in forum New To JavaReplies: 3Last Post: 02-12-2008, 12:03 PM
Bookmarks