Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

packages

 
Asanka Vithanage
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai ranchers

i want compile and run follwing codes
please give me the step by step procedure

//this code in the folder desktop/B file name X.java
package SD;
public class X{
public static void main(String as[]){
System.out.println("B");
}
}

//this code in the folder desktop/A file name Y.java
import SD.x;
class Y{
public static void main(String as[]){

System.out.println("A");
}
}
i use followig code but it's not working(i am in the desktop prompt)
javac -classpath B/X.java A/Y.java
tells package SD does not exit
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi asanka....

In the first code your class name is X.

but in second code
you have used import SD.x; instead of import SD.X;

now it compiles fine....
 
Asanka Vithanage
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai

I corrected the code still it is gives above error
if You can put the correct commands to compile and run the above code
it would be help full to me.
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you tell me the command you have used to compile your class X?
 
M Srilatha
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi asanka...

As you are declaring a package name SD for class X, you have to place the X.java file under SD folder.
Create a folder "SD" inside "B" and then compile class X using the following command:
javac B\SD\X.java
and compile Y.java using
javac -classpath B A\Y.java

It should work!
Hope this helps!
 
Asanka Vithanage
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
it is working


now i want to run this x and y files
how can i do this
please send me the command
i want to run from C:\Users\User\Desktop

i have set classpatn to difeerent folder using Environment variable
so it is possible run x and y without changinhg it in current prompt(C:\Users\User\Desktop)
 
M Srilatha
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the following commands:

java -classpath B SD/X
java -classpath B;A Y
 
Asanka Vithanage
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i caught it finally
after hard practicing

thank you for you,r support
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic