• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New to Java

 
Andrew Casselton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi all,

I'm ploughing through Head First Java, and agree, it is very easy to read and understand (particularly as I'm a grizzled old man from a procedural programming background).

I have JDK 1.6 installed (also NetBeans IDE).

One thing though - the book asks you to solve some code puzzles quite early on - the first PoolPuzzleone for example. I really want to run the code, but the book gives you no indication of how to do this - very frustrating. It shows a kind of console window but doesn't show how to compile a class or run it.
I realise this may be later in the book but I want to do it now - is there a short tutorial on here on achieving that ?

Thanks , Andrew
 
fred rosenberger
lowercase baba
Bartender
Posts: 12085
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will assume windows.

Don't use netbeans.

use notepad to write your java file. save it, making sure you don't get the ".txt" extension on the file name.

open a command window, and navigate to where the .java file is.

type "javac ClassName.java"

if that works, type "java ClassName"
 
Campbell Ritchie
Sheriff
Posts: 48385
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Agree with Fred about avoiding NetBeans at this stage, but I would suggest you get something like Notepad++ or Notepad2 or jEdit, which are all much better than MS Notepad for programming. Also have a look at the first few pages of the Java™ Tutorials.
 
Andrew Casselton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys (already had jEdit)
 
Campbell Ritchie
Sheriff
Posts: 48385
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome Use jEdit and then compile and run things from the command line. Note some things have .java in the instruction and some things miss out the extension.
javac MyFile.java
. . .
java MyFile
And please note your thread subject doesn't tell us what the question is about.
 
Andrew Casselton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so I set the 'Path' as per tutorial on here and ran

javac PoolPuzzleone.java

No errors...so far so good. Then I ran

java PoolPuzzleone

and I got the following message

Exception in thread "main" java.lang.NoClassDefFoundError: PoolPuzzleo
name: PoolPuzzleOne)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: PoolPuzzleone. Program will exit.


I then searched a few other threads here and ran following :

java -classpath . PoolPuzzleone

I still get exactly the same error. Appreciate your help (and sorry about the title of the thread - will bear in mind in future).

Thanks in advance

Andrew


 
Andrew Casselton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its ok I was being dumb I didn't realise that the class name was case sensitive - I had one character lower instead of upper case ! Doh !
 
Campbell Ritchie
Sheriff
Posts: 48385
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And does it work any better with PoolPuzzleOne than PoolPuzzleone?
 
Andrew Casselton
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep it works fine. I came up with a slightly different solution to the one it the book, wanted to test it, and it worked !
 
Campbell Ritchie
Sheriff
Posts: 48385
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic