Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

How to compile a java program w/ another java programs which are w/o a main method

Thread view: 
cjeffwang@yahoo.com - 31 Oct 2005 17:48 GMT
I have been reviewing my "Java Tutorial" lately.  For the
CounterDemo.java in IO\example-1dot1, javac CounterDemo.java showed an
error message that can not find the CountWriter/CountReader classes. I
have compiled these two java files at the same driectory.

How do I compile counterDemo.java?

TIA,
Jeffrey

G:\JavaTutExamples\essential\io\example-1dot1>javac CounterDemo.java
CounterDemo.java:5: cannot find symbol
symbol  : class CountReader
location: class CounterDemo
       CountReader cr = new CountReader(new FileReader("farrago.txt"),
'e');
       ^
CounterDemo.java:5: cannot find symbol
symbol  : class CountReader
location: class CounterDemo
       CountReader cr = new CountReader(new FileReader("farrago.txt"),
'e');
                            ^
CounterDemo.java:6: cannot find symbol
symbol  : class CountWriter
location: class CounterDemo
       CountWriter cw = new CountWriter(new
FileWriter("outagain.txt"), 'e');
       ^
CounterDemo.java:6: cannot find symbol
symbol  : class CountWriter
location: class CounterDemo
       CountWriter cw = new CountWriter(new
FileWriter("outagain.txt"), 'e');
                            ^
4 errors
Andrew Thompson - 31 Oct 2005 18:33 GMT
> I have been reviewing my "Java Tutorial" lately.  For the
> CounterDemo.java in IO\example-1dot1, javac CounterDemo.java showed an
> error message that can not find the CountWriter/CountReader classes. I
> have compiled these two java files at the same driectory.

That sounds odd.  Are you saying that CountWriter.class and
CountReader.class are both in the same directory as CounterDemo.java?

> How do I compile counterDemo.java?

It should compile OK if the class files for CountWriter/Reader are
present, as I was asking above, but your compilation errors below
(now snipped) are suggesting they are *not* found.

Did you put any package statements in the other classes?
(Did you change them at all?)

Try this.

G:\J...\example-1dot1>javac -classpath . CounterDemo.java
cjeffwang@yahoo.com - 31 Oct 2005 19:14 GMT
The FilterReader and FilterWriter are also shown in CounterDemo.java:

CountReader cr = new CountReader(new FileReader("farrago.txt"), 'e');
CountWriter cw = new CountWriter(new FileWriter("outagain.txt"), 'e');

-- Jeffrey
cjeffwang@yahoo.com - 31 Oct 2005 20:02 GMT
Thanks. Tried " javac -classpath . CounterDemo.java "     It worked.

Reviewing the CounterReader and CounterWriter java files, found:
public class CountReader extends FilterReader {
public class CountWriter extends FilterWriter {

I can not find FilterReader or FilterWriter in my G:\JavaTutExamples.
Is this an error?

Jeffrey
Mark Haase - 01 Nov 2005 01:29 GMT
> I can not find FilterReader or FilterWriter in my G:\JavaTutExamples.
> Is this an error?

Those classes are part of the standard class library that comes with
Java. The compiler finds those on its own even though they're not in the
same directory as your classes.

|\/|  /|  |2  |<
mehaase(at)gmail(dot)com
cjeffwang@yahoo.com - 01 Nov 2005 04:02 GMT
Have run the CounterDemo.class again.  It worked well now.

I have had another question on how to run the Subclass program.  "java
Subclass" showed a "NoSuchMethodError" in thread "main"     Of course I
have a "public class Subclass extends Class {" statement in my
Subclass.java file.  I can compile Subclass and SubSubclass java files.
Just don't know how to run these class files.

TIA,
Jeffrey
Andrew Thompson - 01 Nov 2005 05:38 GMT
> Have run the CounterDemo.class again.  It worked well now.
>
> I have had another question on how to run the Subclass program.

Huh?  What 'Sublcass' program?  Is this something you are
writing yourself?

Note that 'Subclass' is not written according to the correct
nomenclature for a class name, which is EachWordUpperCase.
If you want to name it as an extension of another class, it
might make sense to add the name of the super class.  E.G.

'CounterDemoSubClass'

>.. "java
> Subclass" showed a "NoSuchMethodError" in thread "main"

Please copy/paste output rather than 'describing' it to us..
<http://www.physci.org/codes/javafaq.jsp#exact>

>...    Of course I
> have a "public class Subclass extends Class {" statement in my
> Subclass.java file.  

You are telling the compiler that 'Class' class has a
  main(String[] args)
..method.  Is that correct?   Doi you see a 'main' here?
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#method_summary>

OTOH, why the heck are you extending 'Class' rather than a
class related to the Counter classes?

Are you still working on the counter example, is this code
supposed to be related to that code in some way?
cjeffwang@yahoo.com - 01 Nov 2005 08:29 GMT
Andrew,

My Subclass question has nothing to do with the CounterDemo.

In fact, my question is, for a Super class and a Sub class, how do I
start to run the Sub class file?
Because both have no Main Method, I had the 'NoSuchMethodError".  Later
on I added a "public static void main(String[] args) {" to my Sub java
file.

Compiling the Sub java file showed an 'illegal start of expressioin"
error message at the next statement immediately after the main method.

How can I start a Sub java file?

Jeffrey
Andrew Thompson - 01 Nov 2005 05:29 GMT
> Thanks. Tried " javac -classpath . CounterDemo.java "     It worked.

It would help if you could look into the JavaDocs to try and
understand *why* it worked.  Why not have a look over this and
give us your best idea why that is..
<http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html#options>
cjeffwang@yahoo.com - 01 Nov 2005 08:02 GMT
Not quite understand what's going on here.

After typing "javac -classpath . CounterDemo.java" to run it
successfully, just typing "javac CounterDemo" also worked well.  I have
a Classpath environment variable set to G:\jenut2;  .  for those java
files w/ a pakage statement.  CounterDemo.java has no package statement
and is not in jenut2 directory, it should work fine w/o -classpath .
option.

That's all I know.  

-- Jeffrey


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.