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

Compiling problem for Scjp

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My directory structure is like that-


In the x directory:


In the test directory:


In the myApp directory:

The question is :
If the current directory is x, which invocations will produce the output "test/Baz"? (Choose
all that apply.)

I know how to compile and run
let's say:
here is my answer :
c:\Users\Ian Su\Desktop\x>javac -cp test FindBaz.java //to compile
c:\Users\Ian Su\Desktop\x>javac -cp test;. FindBaz //to run to have the correct output

The answer is ok.

It is still ok!Then I tried to change the FindBaz.java.That is I inserted one line.
FindBaz.java after changing it.

In the x directory:

Other files are the same as before.
After changing it,I tried several ways to compile FindBaz.java.But I still can't compile.
Is there anybody able to help me with it!Thank you for your reading my post!
I know what the problem is.But what i want to know is ,can I compile in this latest situation.
help me out please.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Why did you post this in the "Meaningless Drivel" forum? I'll move it to a more appropriate forum for you.
 
Ian Su
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jesper Young.Actually I am a starter in this forum.So I don't know where to put.I just want to post it.
Can I get a forum name like "Programmer Certification(SCJP)"?I mean can i edit that name or can I have a new name?
Thank you.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ian Su wrote:
Then I tried to change the FindBaz.java.That is I inserted one line.
FindBaz.java after changing it.

In the x directory:
1. package x; //I inserted this line
2. public class FindBaz {
3. public static void main(String[] args) { new Baz(); }
4. }
Other files are the same as before.
After changing it,I tried several ways to compile FindBaz.java.But I still can't compile.



c:\Users\Ian Su\Desktop\x> cd ..
c:\Users\Ian Su\Desktop>javac -cp x\test;. FindBaz.java
c:\Users\Ian Su\Desktop>java -cp x\test;. FindBaz

 
Ian Su
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Ian Su wrote:
Then I tried to change the FindBaz.java.That is I inserted one line.
FindBaz.java after changing it.

In the x directory:
1. package x; //I inserted this line
2. public class FindBaz {
3. public static void main(String[] args) { new Baz(); }
4. }
Other files are the same as before.
After changing it,I tried several ways to compile FindBaz.java.But I still can't compile.



c:\Users\Ian Su\Desktop\x> cd ..
c:\Users\Ian Su\Desktop>javac -cp x\test;. FindBaz.java
c:\Users\Ian Su\Desktop>java -cp x\test;. FindBaz



Thank you Henry Wong for your advice!really!
I still can't compile FindBaz.java.I've already tried it but can't.Three files are in the same directory tree and one file is included with the package import(in this case,package x; in the FindBaz.java) and the other two don't have the package import.I don't think the problem starting from there!
help me out please.
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ian Su wrote:
I still can't compile FindBaz.java.I've already tried it but can't.



Without anymore information, we can't give you any help -- if would help if you cut-n-paste the exact error messages, when you ran the commands that you "already tried".

Henry
 
Ian Su
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Ian Su wrote:
I still can't compile FindBaz.java.I've already tried it but can't.



Without anymore information, we can't give you any help -- if would help if you cut-n-paste the exact error messages, when you ran the commands that you "already tried".

Henry





The area marked by white rectangle is where I generated the two Baz classes in different locations and what I tried to compile FindBaz.java the way what you said to me.

I still can't compile Henry Wong.help me out!Thanks!
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ian Su wrote:
I still can't compile Henry Wong.help me out!Thanks!



Oops... I can't believe that I forgot about this.

Short answer. You can't do it. You are not allowed to use a class that is in the default package from any named package.

Long answer. If you are trying to use a class that is in a different package, and not in the java.lang package, then you must import the class. In this example, the FindBaz class must import the Baz class because the Baz class is in a different package, and not the java.lang package. In older versions of Java, I believe you can just do an import with the name of the class. This is no longer allowed. If you want the FindBaz class to use the Baz class, then the Baz class needs to also be in a package.

Henry
 
Ian Su
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Ian Su wrote:
I still can't compile Henry Wong.help me out!Thanks!



Oops... I can't believe that I forgot about this.

Short answer. You can't do it. You are not allowed to use a class that is in the default package from any named package.

Long answer. If you are trying to use a class that is in a different package, and not in the java.lang package, then you must import the class. In this example, the FindBaz class must import the Baz class because the Baz class is in a different package, and not the java.lang package. In older versions of Java, I believe you can just do an import with the name of the class. This is no longer allowed. If you want the FindBaz class to use the Baz class, then the Baz class needs to also be in a package.

Henry



Thank you,Henry!I really appreciate your help.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic