Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

K&b selftest 10.6 packages

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package client;
public class Stuff{
public static int doStuffi(int x){return (x++)*x; }
public static final int MY_CONSTANT=5;
}

import client.Stuff;
import static java.lang.System.out;

class User {

public static void main(String [] args){

new User().go();
}

void go(){out.println( doStuffi(MY_CONSTANT ) );}




}
bin
|
|---client

set in bin:
javac -cp . client\User.java
Do not compile(Don't find Stuff.java)
I'd appreciate your help.

 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you have some compile time problems in the declaration of your file User.java

You're a missing a bracket and you are trying to access a static members in another class without using the name of the class that holds the members.

You must declare your code like this:



Now, let's see about the javac command line.

If you have your source files in the current directory where you are running the javac command.

You must first compile the Suff.java file, like this

javac -d ./bin Stuff.java

The -d flag indicates where you want to put the compile class files.

Now, we can compile the User.java file. Like this

javac -cp ./bin -d ./bin User.java

In this case -cp flag is to indicate to the compile where it can find the Suff.class and the -d flag to indicate to the compile where to locate the locate class.

I hope this helps!
[ May 22, 2006: Message edited by: Edwin Dalorzo ]
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This compiles and runs fine:

import client.Stuff;
import static client.Stuff.*;
import static java.lang.System.out;

class User {

public static void main(String [] args){

new User().go();
}

void go(){out.println( doStuffi(MY_CONSTANT) );}


In another file:
package client;
public class Stuff{
public static int doStuffi(int x){return (x++)*x; }
public static final int MY_CONSTANT=5;
}

From the parent directory of client (where I have User.class), I simply ran this as follows:

java User //no need to use -cp because I am in a folder that contains client folder
 
Juan Handal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Edwin great explanation!
 
You have to be odd to be #1 - Seuss. An odd little ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic