• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Unable to compile these java files

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am new to java and i developed following code. i am not able to compile these files. i am getting error while compiling second file

C:/Code/foo >javac Person.java
C:/Code/foo >javac Employee.java
Employee.java:2: cannot resolve symbol
symbol : class Person
location: class foo.Employee
public class Employee extends Person
^
1 error

following are code
Person.java
package foo;
public abstract class Person
{
private String name;

public String getName() { return this.name;}

public void setName(String name){ this.name=name; }
}

Employee.java
package foo;
public class Employee extends Person
{
private int empID;

public int getEmpID() { return empID; }

public void setEmpID(int empID) {this.empID=empID;}
}



settings
set JAVA_HOME="C:\JDK1.4";
set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you have to include the import statement
import foo.Person;
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
compile the files from C:\code like this.

C:\Code>javac foo\Person.java
C:\Code>javac foo\Employee.java

Prabhakar
 
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

Originally posted by Sujatha Rangarajan:
i think you have to include the import statement
import foo.Person;


No, that is not necessary, because both class Person and class Employee are in the same package foo. You don't need to import classes that are in the same package.

Prabhakar's answer is right - you have to compile it from the directory C:\Code, not from C:\Code\foo.
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

you have set your classpath as,

set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"

so do following ,

compile as

javac -d . <classfile1>
java -d . <classfile2>

Make sure that classfile2 depending on classfile1.

Happy compiling...
 
KRK Gowda
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys,
it compiled Successfully
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by KRK Gowda:
i am new to java and i developed following code. i am not able to compile these files. i am getting error while compiling second file

C:/Code/foo >javac Person.java
C:/Code/foo >javac Employee.java
Employee.java:2: cannot resolve symbol
symbol : class Person
location: class foo.Employee
public class Employee extends Person
^
1 error

following are code
Person.java
package foo;
public abstract class Person
{
private String name;

public String getName() { return this.name;}

public void setName(String name){ this.name=name; }
}

Employee.java
package foo;
public class Employee extends Person
{
private int empID;

public int getEmpID() { return empID; }

public void setEmpID(int empID) {this.empID=empID;}
}



settings
set JAVA_HOME="C:\JDK1.4";
set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"

 
DeepakKumar Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by KRK Gowda:
i am new to java and i developed following code. i am not able to compile these files. i am getting error while compiling second file

C:/Code/foo >javac Person.java
C:/Code/foo >javac Employee.java
Employee.java:2: cannot resolve symbol
symbol : class Person
location: class foo.Employee
public class Employee extends Person
^
1 error

following are code
Person.java
package foo;
public abstract class Person
{
private String name;

public String getName() { return this.name;}

public void setName(String name){ this.name=name; }
}

Employee.java
package foo;
public class Employee extends Person
{
private int empID;

public int getEmpID() { return empID; }

public void setEmpID(int empID) {this.empID=empID;}
}



settings
set JAVA_HOME="C:\JDK1.4";
set CLASSPATH=".;C:\JDK1.4\LIB;C:\JDK1.4\LIB\TOOLS.JAR;C:\JDK1.4\BIN;"

 
DeepakKumar Srivastava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all you should comple the files like this

javac -d . Person.java
javac -d . Employee.java

-d stands for directory and the'.' followed by it represents the path where the files are located to be compiled.So just go through the options and i m sure that it will work.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic