• Post Reply Bookmark Topic Watch Topic
  • New Topic

Just started learning Java.. Question  RSS feed

 
Sam Lanzino
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so I just started to learn Java, and I picked up the book Head First. I wrote the intro source code which is called "Party.java" in a program called Jedit, which I downloaded. I then went to the javac terminal and went to the command tab and entered "javac Party.java". It is telling me that error: cannot read: Party.java 1 error. Do I have the java file in the wrong directory or something?
 
Sam Lanzino
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok figured out that i needed the directory /downloads/ in there. But its still giving me 1 error..
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error?
 
Sam Lanzino
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I just rewrote it and it was fixed... now I have hello.class file in my folder. I tryed running java hello and Exception in thread "main" java.lang.NoClassDefFoundError: hello
[Process exited - exit code 1] comes up... ??
 
Sam Lanzino
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone have any idea??
 
Job Anandam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sam,

Its a error caused when you do not set your CLASSPATH properly.while you use java command try directing your command to the correct location of your class

eg:

suppose your hello.class exists in X:\firstPrg\Hello.class and you are running your program from d:\ in the command prompt then

you should use
java -cp X:\firstPrg Hello
this would work.....

bye
 
Sam Lanzino
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im using Mac OS X so would it be the same?
 
Sam Lanzino
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I entered

java -cp\java\MyFirstApp

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-jvm is a synonym for the "client" VM [deprecated]
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
[Process exited - exit code 1]

thats what came up..
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using Terminal, are you in the directory that contains your file Hello.class?

I recently posted some beginning instructions for Mac in the Mac forum. See if these help.

(You should not have to worry about a classpath setting at this point.)
[ March 27, 2007: Message edited by: marc weber ]
 
Job Anandam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sam,

The mistake that you've made is there should be a space between -cp and \jav.. but you have type it continously... java -cp\java\MyFirstApp

Like marc said.. try out working within the very same same directory where your class files also exist ..
 
Bert Bates
author
Sheriff
Posts: 8945
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,

I think you're getting great help here, but I suspect that there's another problem too. Our bad! We didn't really want our readers to try to compile the class we show on page 3. We put a note at the bottom of the page indicating that, but you're not the first to miss that, so we're going to fix that page.

In the meantime, if you skip ahead to page 9, you can go ahead and type that class in, then let these guys help you out with whatever environment setup issues you have to work out. When you do type that class in, it'll also help to copy and paste that code into your question.

Any finally, hang in there! The setup issues you're dealing with are probably the hardest thing you'll have to do for the next couple hundred pages

hth,

Bert
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, a first for me. I'm in a forum where you can actually interact w/ an author of a book that you're reading. This is truly mind-blowing! I'm delving into Head First Design Patterns, one of the most amazing books on programming that I've studied yet, and one that is opening up my eyes to true code reuse. Thanks, Bert Bates.
 
Bert Bates
author
Sheriff
Posts: 8945
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pete,

I'll tell Eric and Beth that you're enjoying the book.

Bert
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!