Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35110

Is it necessary the source file should be at the same location with the class file?

From parmenides <xparmenides@yahoo.com>
Newsgroups comp.lang.java.programmer
Subject Is it necessary the source file should be at the same location with the class file?
Date 2016-07-24 00:55 +0800
Organization Aioe.org NNTP Server
Message-ID <nn07hl$8ti$1@gioia.aioe.org> (permalink)

Show all headers | View raw


Hi,

I try to understand the relationship of the souce file and the class 
file. I have the following file cascade:
work/Test.java
work/Circle.java
work/compute/shape/

The Test.java is written:

import compte.shape.*;
public class Test {
         public static void main(String[] args) {
                 Circle c = new Circle(3);
                 System.out.println(c.circleArea());
         }
}

The Circle.java is written:

package compute.shape;
public class Circle{
    double radius;
    public Circle(double radius){
      this.radius = radius;
    }
    public double circleArea() {
      return Math.PI*radius*radius;
    }
}

I compiled the Circle.java and copied the Circle.class to the 
compute/shape directory:

javac Circle.java
cp Circle.class compute/shape

Then, I compiled the Test.java:

javac Test.java

I got a message like this:

Test.java:5: error: cannot access Circle
                 Circle c = new Circle();

I modified the first line of Test.java as follows:

import compte.shape.*;
===>
import compte.shape.Circle;

I compiled the Test.java again:

javac Test.java

and it is all right.

Then, I moved the Circle.java to compute/shape directory

mv Circle.java compute/shape

and changed the Test.java back:

import compte.shape.Circle;
===>
import compte.shape.*;

At last, the compiling of the Test.java is correct.

It seems that the source file should be at the same location as the 
class file.Is this right? Why the compiling is wrong? Thanks.

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Is it necessary the source file should be at the same location with the class file? parmenides <xparmenides@yahoo.com> - 2016-07-24 00:55 +0800
  Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-23 20:10 +0100
  Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-23 19:05 -0400
    Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-24 08:42 +0100
      Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-24 07:47 -0400
        Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-24 22:08 +0100
          Re: Is it necessary the source file should be at the same location with the class file? Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-24 21:28 +0000
          Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-24 18:06 -0400
            Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-25 21:21 +0100
              Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-25 21:03 -0400
    Re: Is it necessary the source file should be at the same location with the class file? Roedy Green <inquiry@mindprod.com> - 2016-07-26 15:24 -0700
  Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-23 19:06 -0400

csiph-web