Help running a very very very simple code

O

olivier.melcher

Hi,

i'm started with Java Programming, i'm trying to run a very simple
sample code.

Can anyone tell me why it's not compiling right?

I'm running Netbeans IDE 6.1 with Java JDK 6 on Linux OS (Ubuntu).

I've got the Java API Documentation placed in my Java Home Directory (/
home/olivier/jdk1.6.0_06/docs)

Here is the code:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package myfirstproject;

/**
*
* @author olivier
*/
class MyFirstJavaClass {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
System.out.println(“chocolate, royalties, sleep”);
}
}


Here is the error message i get when trying to compile the code:

init:
deps-jar:
Compiling 1 source file to /home/olivier/NetBeansProjects/
MyFirstProject/build/classes
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: illegal character: \8220
System.out.println(“chocolate, royalties, sleep”);
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: ';' expected
System.out.println(“chocolate, royalties, sleep”);
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: illegal start of expression
System.out.println(“chocolate, royalties, sleep”);
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: illegal character: \8221
System.out.println(“chocolate, royalties, sleep”);
4 errors
BUILD FAILED (total time: 0 seconds)


Thanks for the help!
 
A

Aryeh M. Friedman

olivier.melcher said:
Hi,

i'm started with Java Programming, i'm trying to run a very simple
sample code.

Can anyone tell me why it's not compiling right?

I'm running Netbeans IDE 6.1 with Java JDK 6 on Linux OS (Ubuntu).

I've got the Java API Documentation placed in my Java Home Directory (/
home/olivier/jdk1.6.0_06/docs)

Here is the code:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package myfirstproject;

/**
*
* @author olivier
*/
class MyFirstJavaClass {
/**
* Method main
*
*
* @param args
*
*/
public static void main(String[] args) {
System.out.println(“chocolate, royalties, sleep”);
}
}


Here is the error message i get when trying to compile the code:

init:
deps-jar:
Compiling 1 source file to /home/olivier/NetBeansProjects/
MyFirstProject/build/classes
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: illegal character: \8220
System.out.println(“chocolate, royalties, sleep”);
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: ';' expected
System.out.println(“chocolate, royalties, sleep”);
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: illegal start of expression
System.out.println(“chocolate, royalties, sleep”);
/home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
MyFirstJavaClass.java:21: illegal character: \8221
System.out.println(“chocolate, royalties, sleep”);
4 errors
BUILD FAILED (total time: 0 seconds)


Thanks for the help!

What happens if you compile from the command line:

cd /home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
javac MyFirstJavaClass.java
java MyFirstJavaClass
 
S

Stefan Ram

olivier.melcher said:
package myfirstproject;

Simple »Hello, world« programs do not need to have
a package, while this is good for most real work.
System.out.println(chocolate, royalties, sleep);

You should use character 43 (»"«) instead of character 147
and 148 (both omitted in the quotation above) around the text.
 
F

fchang

olivier.melcher said:
package myfirstproject;

class MyFirstJavaClass {
public static void main(String[] args) {
System.out.println(“chocolate, royalties, sleep”);
}
}

What happens if you compile from the command line:

cd /home/olivier/NetBeansProjects/MyFirstProject/src/myfirstproject/
javac MyFirstJavaClass.java
java MyFirstJavaClass

Actually, since the class is under the "myfirstproject" package,
the legal way to compile it from the command line must be done
from the directory ABOVE it:

cd /home/olivier/NetBeansProjects/MyFirstProject/src/
javac myfirstproject/MyFirstJavaClass.java
java -cp . myfirstproject.MyFirstJavaClass
 
T

Tom McGlynn

On May 12, 9:14 am, "olivier.melcher" <[email protected]>
wrote:
...
System.out.println(“chocolate, royalties, sleep”);
...

The error messages and the way the line above renders for me, suggests
that you might want to check if you have a pair of forward and
backward quotes here rather than just two simple double quotes.
Perhaps the editor your installation of NetBeans uses converts pairs
of quotes this way (a la Word).

Regards,
Tom McGlynn
 
S

Stefan Ram

You should use character 43 (»"«) instead of character 147
and 148 (both omitted in the quotation above) around the text.

1s/character 43/character 34/
 
S

Stefan Ram

O

Oliv

  Simple »Hello, world« programs do not need to have
  a package, while this is good for most real work.


  You should use character 43 (»"«) instead of character 147
  and 148 (both omitted in the quotation above) around the text.

Stefan,

That did the trick, i changed the characters and the program compiled
and ran perfectly!

Thanks for your help :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top