Question about how javac finds referenced files.

Hi
I am just beginning to learn Java and have got some questions related to packages.
I have two classes:
MyClass.java
package pkg;
public class MyClass {
     public void prn(int x){
     System.out.println("Integer: "+x);
Test.java
import pkg.*;
public class Test{
     public static void main(String[] args){
          MyClass obj=new MyClass();
          obj.prn(2);
Directory structure
/root/ jprog/MyClass.java
/root/ jprog/Test.java
Executing the following sequence of commands gives me:
# ls
MyClass.java Test.java
# javac -d . MyClass.java
# ls
MyClass.java Test.java pkg/
# cd pkg
# ls
MyClass.class -----compiles.
# cd ..
# javac Test.java
Test.java:5: cannot access MyClass
bad class file: ./MyClass.java
file does not contain class MyClass
Please remove or make sure it appears in the correct subdirectory of the classpath.
MyClass obj=new MyClass();
^
1 error
Now after reading another thread on this forum I came to know that the compiler finds the
MyClass.java in the wrong package. Using verbose option with javac shows this.
So I move it to some other directory and everything works.
# mv MyClass.java /root
# ls
Test.java pkg/
# javac Test.java
# java Test
Integer: 2
Now the question begins:
Suppose we go back to how the files were arranged before I moved the MyClass.java file and
I change the Test.java file by adding
package pkg2;
statement to it.
Now everything compiles
# ls
MyClass.java Test.java ---I have deleted pkg and .class files
# cat Test.java
package pkg2;
import pkg.*;
public class Test{
public static void main(String[] args){
MyClass obj=new MyClass();
obj.prn(2);
# cat MyClass.java
package pkg;
public class MyClass {
public void prn(int x){
System.out.println("Integer: "+x);
# javac -d . MyClass.java
# javac -d . Test.java
# ls
MyClass.java Test.java pkg/ pkg2/
# java pkg2.Test
Integer: 2
Why isn't the MyClass.java file causing any problems now?
Using the verbose option with javac shows that the compiler goes straight for the pkg/MyClass.class.
My readings of Core Java Horstmann tell me that the compiler always looks in the current directory. javac documentation also doesn't help. I know that the documentation recommends that the source file locations should match the package statements.
I'm just trying to learn how javac finds referenced files.
Any help??
Thanks a load in advance.

I know that the
documentation recommends that the source file
locations should match the package statements.This is not merely a recommendation, it is a requirement.
Both javac and java find classes by traversing the classpath. The classpath should contain directories (or jar files) that correspond to the top of a (part of the) package hierarchy.
For example, if the Java code for your class is in a file C:\src\pkg\MyClass.java, and MyClass.java declares the class to be in package pkg, the classpath should contain C:\src. Classes are then found by transforming their package declaration into a directory structure.
Please note that javac works on files, not classes. Therefore it is necessary to specify the full filenames of the files you want to compile, even if you have specified the classpath. By default, javac will put compiled class files in the same location as their sources, so the classpath for the java command should also contain C:\src.
The exception to the rule is when all classes for the program are in the default package (i.e., they do NOT contain a package statement). In that case, it is possible for javac (and I believe java as well) to find all classes in the current directory, so it will "just work".
You can specify the classpath using the -cp parameter to both javac and java.
Hope this helps.

Similar Messages

  • How to find referenced photos within the Photos app

    Problem:
    Upon instructing Photos to use iCloud Photo Library, the app informed me:
    "104 referenced files in your library will not upload to iCloud Photo Library. Select referenced files in your library and choose 'Consolidate' from the File menu to copy the original files into the library."
    I do not know which 104 images in my library are referenced, and therefore cannot use "Consolidate" to import the masters into the library.
    Can anyone tell me how to find referenced files, within the active library in the Photos app?
    I am not asking how to use the "Show Referenced File in Finder" menu command. I need to identify a file as referenced first, hence this post!

    Gotcha - came up with a workaround... since the photos were living in the Photo Library packaged itself, and not simply in another regular folder, I right clicked on the library and said show packaged content, then search for what folders the files lived in, then copied the files out of the packaged library into a folder. Then I was able to give the Photos Library access to the new folder with the files.
    With all my files now references, I enabled iCloud Photo Library and am uploading now.
    Hopefully my new local Photo Library will be smart enough to optimize local images and shrink to give me more space.
    Thanks.

  • Hello! I have a huge question about how can I get connected my iphone 4 with my car Is there any opption on find my car application? I have a Volvo xc60 and I want to be connected all the time with my iphone. Can I do that?

    Hello! I have a huge question about how can I get connected my iphone 4 with my car Is there any opption on find my car application? I have a Volvo xc60 and I want to be connected all the time with my iphone. Can I do that?

    Hello. I can say that you have a quite strange „huge question”… It’s non-sense to stay connected with your car which is hundreds miles away. Unless…
    I have a theory. You don’t want to controll your car, you want to controll somebody who is driving the car. Volvo XC 60 is a nice family car, usually used by married men between age of 35-45, probably with small children, so it’s very unlikely that you want to controll your teanage kid, mainly because probably even if you would give him/her to drive the car in the neighborhoud, I don’t think that he/she would be „several hundred miles away”…  If your child is not young teneage anymore, and he/she has his/her own life, but you want to control him/her, that is sick… So I am convinced that you want to controll your husband who probably travelling often! Am I wright?
    Isnt’t nice at all! Would you like if you would be monitorized in such way? I bet you don’t!
    Anyway, iPhone is smart, you can use for many things, but come on, you really were thinking that there is such kind of application???
    What could you do it's to put in the car a GPS survelling system, however I don't think that you could do it without your husband knowledge, otherwise he won't be able to start the engine...

  • Round trip workflow with proxies between Premiere and AE / a more general question about how these programs work?

    Hi all,
    I'm new to editing with proxies in Premiere and have some questions about how to handle the relationship with After Effects. Say I have a rough cut (with proxies) and I want to send it to AE to do some effects. The simplest thing to do seems to be to replace the proxies with the originals in Premiere, send the project to AE and do my thing. But if I then want to send the project back to Premiere, it will involve the original files, which are too machine-intensive for me to edit. In theory, it seems like there should be a way to send the project with original footage to AE, do effects, send it back to Premiere, and then replace it with proxies to do further editing while retaining the effects.
    This leads to a confusion about how AE works. When I do an effect, am I correct in assuming that it does nothing to the original file? If that's the case, it seems like it shouldn't matter (in the editing stage) what file AE "applies" an effect to (proxy or original). But I feel like there's a hitch in this workflow. The same question could also be asked about going back and forth in Speed Grade.
    Perhaps there is no real answer to this and the best option is to save effects and grading for after I have picture lock, but sometimes that's not entirely possible or convenient, etc.
    Hopefully this makes some sense—It's a little hard to explain.
    Thanks.

    Hi Mark,
    Here are the specific sections of the manual that should give you the best explanation regarding the Check out/in workflow for FCP projects in Final Cut Server:
    Check out:
    http://documentation.apple.com/en/finalcutserver/usermanual/#chapter=7%26section =5
    Editing:
    http://documentation.apple.com/en/finalcutserver/usermanual/#chapter=7%26section =6
    Check in:
    http://documentation.apple.com/en/finalcutserver/usermanual/#chapter=7%26section =7
    -Daniel

  • How to find the file that delete from time capsule?

    How to find the file that delete from time capsule?

    I mean I saved JPEG file in Time capsule and unfortunately delete the file. Can I get it back
    IF.... .no other backups have occured since you deleted the file, you might be able to retrieve it using an application like Disk Warrior. It's about $100 as I recall, and there are no guarantees that it will work.
    DiskWarrior 4 - The Disk Utility for Mac  Disk Repair, Mac Directory ...
    Any of the free or low priced utilities that you might see or try will not be able to retrieve a deleted file from a Time Capsule.
    If any backups have occured since you deleted the file, the deleted file has almost certainly been overwritten. No way to retrieve it in that case.

  • How to find log files in Sun soalries....

    How to find log files in the SUN Solaries Os if there is any.....
    i am new to SUN Solaries Admin Can some one refer me a good book for me on sun solaries
    Thankq

    A reasonable method would be
    cat /etc/syslog.conf
    .. at least it would show you where syslog send its logs.
    .7/M.

  • How to find the File name using the FTP Adapter

    hi all,
    how to find the File name using the FTP Adapter with BPEL.
    Regards

    Found the solution for this.
    First In the mediator's routing rule use assign property $in.property.jca.file.FileName to $out.property.jca.file.FileName
    In the BPEL's receive activity go to the properties tab and get the property to a BPEL variable. That should do it.
    Thanks for the posts

  • How to find .pld files version in Oracle apps

    Hi,
    How to find .pld file version in Oracle apps using unix command or any other way.
    Regards

    Connect to the forms server.
    In the $AU_TOP/resource directory run the following...
    strings -a <NAMEOFFILE>.plx | grep '$Header'
    For example...
    To find the .pld version of INVAMCAP.plx I would run this on the forms server.
    cd $AU_TOP/resource
    strings -a INVAMCAP.plx | grep '$Header'
    This will return the .pld version.
    Hope this helps!
    Jen

  • How to find duplicate files in Finder with Automator or Apple ScriptEditor

    Can anyone tell me how to find duplicate files in Finder with Automator or Apple ScriptEditor.

    D'oh!  It's actually fairly easy - I just right clicked on the file, Get Info, Artwork tab, then dragged the picture to the desktop, from where I can do what I like with it.  Never mind, nothing to see here, carry on.

  • A few questions about how ZPM works.

    We have patch management (in ZCM 11.2.2), but honestly don't use it much. I have a few questions about how it works that might make me use it more, if I understand it more.
    If I deploy a patch (or a set of patches), it creates a bundle for that deployment. That bundle seems to include actions that deploy the actual patch bundles (correct?). Do I have to recreate a new deployment bundle every time I want to push a new patch? i.e. If I push a Java update, and a month later, a new one comes out, do I build out a new bundle with the new patch in it, or do I modify the old one?
    Once the patch is deployed, can I safely delete that deployment bundle, or should they just pile up?
    Is there a way to "auto-approve" patches? Lets say I always want a group of machines to have the latest Adobe Flash Player patches. Can I set up ZPM to automatically cache and push the latest patches for a specific product, or do I have to manually remediate each patch? (I'm thinking of how MS's WSUS does "auto-approval")
    I see most packages aren't cached in list, but occasionally, a patch is cached without me touching it. Why? Can I change what gets automatically cached?
    Thanks for any help/answers you can provide.
    -Adam

    Originally Posted by adrockk
    We have patch management (in ZCM 11.2.2), but honestly don't use it much. I have a few questions about how it works that might make me use it more, if I understand it more.
    If I deploy a patch (or a set of patches), it creates a bundle for that deployment. That bundle seems to include actions that deploy the actual patch bundles (correct?). Do I have to recreate a new deployment bundle every time I want to push a new patch? i.e. If I push a Java update, and a month later, a new one comes out, do I build out a new bundle with the new patch in it, or do I modify the old one?
    Once the patch is deployed, can I safely delete that deployment bundle, or should they just pile up?
    Is there a way to "auto-approve" patches? Lets say I always want a group of machines to have the latest Adobe Flash Player patches. Can I set up ZPM to automatically cache and push the latest patches for a specific product, or do I have to manually remediate each patch? (I'm thinking of how MS's WSUS does "auto-approval")
    I see most packages aren't cached in list, but occasionally, a patch is cached without me touching it. Why? Can I change what gets automatically cached?
    Thanks for any help/answers you can provide.
    -Adam
    For #1, (assuming you're not using baselines), you would check the new version of the patch (vulnerability) and do a new deployment.
    #2 - once you're satisified that the machines are deployed (or the best to your ability) you can delete the DEPLOYMENT package. It doesn't delete the actual vulnerability bundles to my knowledge. That's why it's a good idea to name your bundle deployments with something meaningful, IMO (and maybe include a nice desription).
    #3 - currently I don't believe this is possible. I know you can probably configure it to auto-download the patches, but not auto-deploy everything. Given the propensity for software to wreck other things (hello MS .NET patches), this is probably not a good idea. At least I'd never auto-download and auto-deploy any patches without testing them first, and certainly take my servers a little more cautiously than my workstations.
    #4 - I think you can configure what's cached, but I could be wrong.
    I know there's a lot of improvements coming in the pipeline, and it doesn't hurt to "vote" for your enhancements via the enhancement system (more work for Shaun--haha)
    --Kevin

  • How to find lost files from Iphone without back up

    How to find lost files from iPhone without back up?

    If you don't have a back up, there's no where to restore them from.

  • How can my own hard drive be considered off line to find referenced files?

    my iPhoto library for some reason could not be imported to Aperture when I converted to Aperture.
    However, I selected the option to create a referenced library and it worked fine.
    I upgraded my hard drive from 160 to 750 at a professional apple reseller and they copied all of my data, programs etc as well.
    While I never checked to see if this was the case before, becuase I had no reason to check for it, I notice now that all of the aperture thumbnails have the "reference offline" icon and when i try to "locate reference", I can do so, but Aperture still considers my own hard drive offline!!!   How's that for strange. 

    Every hard drive has a volume name (they also have a UUID but I don't think Aperture cares about that.)  If the new drive was not given the same name as your old drive then as far as Aperture is concerned, the drive it's looking for is not present (it's looking for a drive with a specific name and not finding it.)
    While YOU know that all the data on the old hard drive was copied to the new hard drive, Aperture doesn't know that (and makes no assumptions).  So if the volume name it's looking for isn't found, then the drive is "offline". Aperture is working as it should.
    You could rename the hard drive back to the original name, but then that would just cause it lose all any new 'referenced' masters you added since upgrading the drive.
    To fix:
    You'll need to reconnect the masters.  In the lower right corner of the thumbnail you should see a small icon which ordinarily has a tiny rectangle with an arrow pointing away (indicating this image is a "referenced" master).  If the master is missing you'll have a little orange triangle with the "!" inside it (indicating a problem).
    In the main menu, select "File" -> "Locate Referenced Files..."
    A box will appear and you can check the box which reads "Show Only Files Not Found" (this will hide all the files which are currently fine so that you only have to deal with the files that have a problem.)
    In the lower part of the panel is filesystem browser.  You can navigate to the directory drive & directory where these files are located and click "Reconnect" or, if they're all in the same place, "Reconnect All". 
    Pick "Done" when you've finished.
    If you don't like using "referenced" masters, you can tell Aperture to bring the masters into the Aperture Library so that it will manage the files for you (and avoid this problem in the future).  In the main menu pick "File" -> "Consolidate Masters".  You'll be given the choice to "copy" the files (it'll copy the masters but still leave the old files back in their original locations... but Aperture will no longer need those originals.)  or you can "move" the files (Aperture will copy them into the library then delete the original after the copy is completed... effectively "migrating" the masters into your library and cleaning up the originals when it's done.
    Regards,
    Tim

  • Question about how XI process files in FTP

    Hi experts,
    I have a file-FTP to JDBC scenario.
    XI scans a folder every minute to see if any file has appear.
    My question is, does XI process the files in their order of creation, or randomly ?
    If not, is there a way to make XI process them in order of creation ?
    Thanks a lot, any help would be appreciated.
    Kind regards,
    Jamal

    Hi,
    from SAP Help:
    If you select files from an FTP server and not from the file system, you need to make the following additional specifications:
    ○       ftp.host=<ftp-server>
    The host name or IP address of the FTP server. If this specification is made, it is assumed that you are accessing an FTP server. The specifications file.sourceDir and file.sourceFileName then refer to the FTP server. The following are then not possible specifications:
    ■       setAttribute for parameter file.processingMode.
    ■       byDate for parameter file.processingOrder.
    Regards
    Patrick

  • How to use "referenced files" in MY case?

    I have a MacBook pro, which I bring with me between home and studio.
    Until now, I've been storing my shots on an external HD. This means that I cannot see my photos when I'm home.
    I've been looking into the "referenced files"-thing.
    I would like to be able to see a preview of all my shots also when I only have my MacBook and not the external drive. When I shoot, I would like to store NEW shots on my MacBook at first (to edit, tag etc.) but then put them on my external drive for storage.
    I haven't been able to figure out how to do this. Can anyone please explain or link me to a place where I can read about it?
    Thanks in advance

    I haven't done this yet, but soon I'll need to coordinate a laptop and a desktop machine. So don't take my word for anything!
    It sounds as though you have Aperture set up so that the laptop machine's library is on the external drive -- not just the images that make up the heart of the library. Is that right? The alternative would be to tell Aperture its library is on the laptop, but have the library reference master images on the external drive. Previews -- if you have Aperture set to create and/or maintain previews in any or all projects -- are in the library, which is on the computer whether or not you have the drive containing the masters with you.
    (Am I going wrong yet??)
    But I'm still not clear, when master images are referenced, where Aperture stores versions, adjustments, metadata; in the library or with the referenced images?
    Anyway, it seems as though this arrangement should allow you to import new images into a project in the laptop's library while on the road. Then I don't think you even have to export and re-import the project -- when you're hooked back up to the external you just "relocate masters" for the new project onto the external drive.
    Somebody please straighten me out if I've got all this wrong.

  • Finding referenced files

    I am unable to get my referenced files to re-link to the original RAW file on my external hard drive. I have gone through many post and have experience relocating referenced files which works great when you can actually get to that screen. I have tried all the repairs in the repair menu with no luck. I click on the preview of the picture and select "locate referenced files" and I get "No referenced Files". If I go to File>Locate Referenced files I get "Unavailable original files cannot be relocated". I seem to be stuck in a error loop and I'm not sure why it won't me just redirect it to the correct file? I know I can reimport but I don't want to loose all the adjustments I've made to various pictures. I know the files are on my hard drive. It's also very strange because it magiaclly happened to library's that have worked fine in the past and that I haven't touched in some time. I keep my pictures on an external hard drive and have the latest updates of Aperture and OS.

    Are the files in question really referenced files and not managed?
    I click on the preview of the picture and select "locate referenced files" and I get "No referenced Files".
    That error message usually will appear, when you try to locate a referenced file for managed files.
    If I go to File>Locate Referenced files I get "Unavailable original files cannot be relocated".
    And that error message will occur, when you use the command "File > Relocate Original", not when you try to use the command "locate referenced Files".
    From the symptoms you describe, I suspect that the files in question might be managed files, but Aperture has lost the connection to these managed files. Unfortunately, Aperture has no tools to fix broken references to managed files, because that is not supposed to happen.
    Check,if you can find the originals in question inside the Aperture library. Ctrl-click the APerture library, select "Show Package Contents" from the pop-up menu, and then browse the "Masters" folder, if your missing originals are inside. The originals are filed by the dates of the import session.
    Regards
    Léonie

Maybe you are looking for

  • Number of rows in a clob

    I've a CSV file, stored in my database as a CLOB. I've a plsql cartridge that reads the clob and displays the data to the user as a html table. I'm using string functions, instr and substr to extract the data from the csv file. My CSV file is basical

  • Countif formula, how to make it not count a value if another cell is a certain value.

    I have this formula below: =IF(A21="","",IF(COUNTIF(G21:G50,">0"),"A","B")) I would like to tell it that if a corresponding row in column B has a value of: "Calibration" then to ignore that row and do not add the value to the countif. I thank you in

  • GRUB is messed up

    After a fresh install, I ran "pacman -Suy". It rattled off an error about Grub. After searching around, I found someone had done "pacman -Suyf" to fix the problem. I ran that and everything seemed to go properly. After rebooting, I now get an error:

  • Deleting preinstalled Apps

    How do I delete preinstalled apps? I dont want the preinstalled email App since it's designed for very low amounts of emails and not suited for 150-200 mails a day. Also I'd like to get rid of the gaming center and replace the buggy pre installed cam

  • Copy from planning to Budget in Cost Center Accounting (Controlling)

    Hi to All, Currently we are using the SAP 4.6C Version. Is there anyway to copy the planned version into Cost Center Budget when using the TCODE:KPZ2 (Cost Center Budget). SAP has provided the same option when dealing with Internal Orders. We can cop