[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Campbell Ritchie wrote:Welcome to the Ranch
Have you worked out how to open a terminal? Try the following instructions:-
java -version
javac -version
… and tell us what the responses are. Also which java and which javac would work on a Unix/Linux box, showing you where the installation of Java® you are using is.
Don't copy and paste the above instructions.
Campbell Ritchie wrote:We have an FAQ which may help explain the PATH.
M Dias wrote:public static void main (String[] args) {
System.out.println("I Rule!");
System.out.println("The World");
}
}
The Javac and java versions are 1.8.0_65 - I imagine they are updated.
However I just begun learning java with the book "Head First Java - 2005 edition". And the very reason I got stuck was that I've written a code exactly from the book and I could'nt get it to compile - received 16 errors!!! Now could someone have a quick look and state whether the I made a mistake in the code, or the book is outdated since its written for Java5.0 version and my pc has java 8!
Here's the code:
pubic class DooBee {
public static void main (String[] args){
int x=1;
while (x<3) {
System.out.println(“Doo”);
System.out.println(“Bee”);
x=x+1;
}
if=x+1;{
System.out.println(“Do”);
}
}
}
in your code you typed Public wrong.. could it be?
i reckon what i underline could cause the errors.
Petras Janulevicius wrote:
M Dias wrote:public static void main (String[] args) {
System.out.println("I Rule!");
System.out.println("The World");
}
}
The Javac and java versions are 1.8.0_65 - I imagine they are updated.
However I just begun learning java with the book "Head First Java - 2005 edition". And the very reason I got stuck was that I've written a code exactly from the book and I could'nt get it to compile - received 16 errors!!! Now could someone have a quick look and state whether the I made a mistake in the code, or the book is outdated since its written for Java5.0 version and my pc has java 8!
Here's the code:
pubic class DooBee {
public static void main (String[] args){
int x=1;
while (x<3) {
System.out.println(“Doo”);
System.out.println(“Bee”);
x=x+1;
}
if=x+1;{
System.out.println(“Do”);
}
}
}
in your code you typed Public wrong.. could it be?
i reckon what i underline could cause the errors.
Hi thanks for correcting the public word.
I've tried compiling it again but this is the result:
[/code]
Is there something wrong with my mac? As I believe the u201d refers to symbols but I'm using a normal text editor, and tried using sublime too. - same effect.
Regarding the Print or PrintIn- the exercise is about printing a long word made from repeated tasks using the "while" thing in java. But the exercise is 5.0 version, has the printIn or Print changed perhaps?
thanks
Petras Janulevicius wrote:M Dias,
Really thanks for posting back.
I've never encountered such a problem with java, but I did encounter similar problem while saving files for Html or css in the past and I think its got to do something with mac default text editor, the encoding preferences.
Google more on this symbol error and found out that it's not so rare :-)
http://stackoverflow.com/questions/1992933/illegal-character-when-trying-to-compile-java-code
Digging deeper to solve it...
M Dias wrote:
Petras Janulevicius wrote:M Dias,
Really thanks for posting back.
I've never encountered such a problem with java, but I did encounter similar problem while saving files for Html or css in the past and I think its got to do something with mac default text editor, the encoding preferences.
Google more on this symbol error and found out that it's not so rare :-)
http://stackoverflow.com/questions/1992933/illegal-character-when-trying-to-compile-java-code
Digging deeper to solve it...
To be totally fair.. i'm starting writing Java myself. And I encounter the same problems when compiling. I'm on a mac too and sometimes it drives me insane.
Yes, it was obvious when I saw your quotes looked like “ and ”, which are \u201c and \u201d. I use them all the time, so I am used to them. The compiler expects Strings to be delimited by "…", but you are allowed to put the posh quotes inside a String literal.Petras Janulevicius wrote:. . . Apparently there are issues when you compile java from rich text text editors. . . . By looking at it I've learned that the uppercase is important as I missed them as well.. . #x20d;. .
Campbell Ritchie wrote:
Yes, it was obvious when I saw your quotes looked like “ and ”, which are \u201c and \u201d. I use them all the time, so I am used to them. The compiler expects Strings to be delimited by "…", but you are allowed to put the posh quotes inside a String literal.Petras Janulevicius wrote:. . . Apparently there are issues when you compile java from rich text text editors. . . . By looking at it I've learned that the uppercase is important as I missed them as well.. . #x20d;. .
You have also seen the pitfall wereby you write printIn instead of println; if you look quickly at the two spellings it id very easy not to see the difference. If you pronouce it as print‑line you can see there isn't going to be an I in it.
Since you have gone to a lot of trouble getting dobeedobeedobeedo to print, I shall challenge you: does the bit about (x > 3) make the slightest difference to the execution of the program? I think I shall have to beef the thread up by sending some beef your way. Only it will be very fresh
No. You can however swap it for beer.Petras Janulevicius wrote:. . . can I barbecue the beef?
Campbell Ritchie wrote:
No. You can however swap it for beer.Petras Janulevicius wrote:. . . can I barbecue the beef?
A String literal is any String which you write in your code with non‑posh quotes. If you write "Campbell" anywhere,everybody will be very surprisedthat will constitute a String literal. And the compiler sees a String literal as an object in its own right.
Petras Janulevicius wrote:I would never have guessed that there are are posh quotes! If I may ask, in what circumstances you use symbol encoding such as /u201c or d?
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|