• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Help setting up computer for Head First Java book?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to the java world and have just picked up the Head First Java book and need some help. I have Mac OSX operating system but I am having a lot of trouble getting everything set up using the command line to even get started with the book. I am not sure where to find the SDK, and if I do find it I do not really understand how to add an entry to my PATH environment? I am completely lost. Any help at all would be much appreciated. Thanks.

 
author & internet detective
Posts: 42055
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scotty,
Welcome to CodeRanch!

On a Mac, your JDK is under /Library/Java/JavaVirtualMachines. For example, mine is at /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

As far as how to edit it, see this post
 
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

It might sound funny but I can't figure out the same "path" thing for the "Head first java" exercise.
I mean I know what is path in pc but why you need it, where you need, do you have to do it once or several times?

I'm using mac el capitan - and I can't find my java folder in the library/java - there simply nothing there, but my pc preferences state that I have the latest java.?

Sorry for my confusion.
 
Marshal
Posts: 80083
412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80083
412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have an FAQ which may help explain the PATH.
 
Petras Janulevicius
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



Hey there!

I did workout how to open terminal, actually managed to workout a different program. I've compiled and run the simple program (MyFirstApp)
public class MyFirstApp {

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.print(“Doo”);
System.out.print(“Bee”);
x=x+1;
}

if=x+1;{
System.out.print(“Do”);
}
}
}


thanks in advance!
 
Petras Janulevicius
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:We have an FAQ which may help explain the PATH.



Hi,

You are correct I had a look at there, but I'm still not very used to this forum layout and structure so I'm slightly confused over using properly fAQ. Also i've found some old posts like ( 12 years old) talking about paths and thinking..they might be a little bit outdated -.-
 
Campbell Ritchie
Marshal
Posts: 80083
412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There will be little change in what it says about PATHs. The only change I can think of is that you used to use a .bat file on a Windows® machine to set the PATH and nowadays you use a properties dialogue.
The older posts may tell you how to set your CLASSPATH, which used to be required for Java® but no longer is, so setting a CLASSPATH usually does more harm than good.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
M Dias
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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




It's indeed weird and it's obviously something we are missing. The compiler is saying that “Bee”); the quotes are wrong in this line ....
also here DooBee.java:6: error: ';' expected ... so it's expecting a semicolon which you have.
uhmmm.
I'll have a deep look and i'll try to help meanwhile if you uncover a solution let me know as well
 
Petras Janulevicius
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Petras Janulevicius
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



Wooohooo I managed to get it done!!!

First I changed my texteditor to a plain text editor ( found one in Appstore named: TextEditor - Text editor & File manager).
This solved the symbol error issue. Apparently there are issues when you compile java from rich text text editors.

Second - Re-checked my exercise..apparently I made some mistakes in it too, which didn't appear until the symbol problem was solved. So this is the actual code I'm suppose to use in the "Head First Java":


By looking at it I've learned that the uppercase is important as I missed them as well..

To all who replied thanks for the support as its important to feel that there is support even for the newbies and seems like trial and error is still the best teacher;-)

Thanks!
 
Campbell Ritchie
Marshal
Posts: 80083
412
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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;. .

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.
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
 
Petras Janulevicius
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

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;. .

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.
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



Hi there,

thanks for clearing things completely

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?

And what does exactly "String literal" refers to?

I didn't notice the difference between neither of them in the book nor while executing the program as I've changed to @print@ before testing it with the print+In mistake. thank you for that, I'l remember it very well.

Regarding the challenge. the equation x> 3 changes the results we get. "DooBee" is a single result for satisfying the equation which in our case is x<3, but since the exercise required to repeat it twice and move on to next changing the number "3" to 4 or more would cause different result. In my humble understanding the loop "while" will be repeated until it cannot satisfy the equation anymore and will move on to the other equation which can be repeated only once I guess and we get the expected result ( Doobee+DooBee+Do).

- actually the code in the book came unfinished and it required creating the equation conditions (x < 3) and x==3.

Hehe, can I barbecue the beef?
 
Campbell Ritchie
Marshal
Posts: 80083
412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Petras Janulevicius wrote:. . . can I barbecue the beef?

No. You can however swap it for beer.

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 surprised that will constitute a String literal. And the compiler sees a String literal as an object in its own right.
 
Campbell Ritchie
Marshal
Posts: 80083
412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
…and I should learn to read. There I was saying x > 3 and it said x == 3.
 
Petras Janulevicius
Greenhorn
Posts: 9
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Petras Janulevicius wrote:. . . can I barbecue the beef?

No. You can however swap it for beer.

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 surprised that will constitute a String literal. And the compiler sees a String literal as an object in its own right.



Beer sounds fine!

The string literal - still trying to figure out, but probably it will take time..

thank you again!
 
Campbell Ritchie
Marshal
Posts: 80083
412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Literals are simpler than you think. If you write 123 or 123.45 or 123.45e67 those are number literals of different kinds.
If you write "Petras" that is a String literal. A literal is a piece of code representing a value, which is the value you want. Just as 123.45 is the same as the value 123.45, so "Petras" constitutes a String literal identical in value to the String containing P-e-t-r-a-s. It is all in the Java® Language Specification, only that can be difficult to understand.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?



They're used to give a typeset feel, where closing quotes and opening quotes are different glyphs. It's why you see them in rich text editors (like Word).

The normal ascii-style double (and single) quotes are only a single symbol, used for both opening and closing quotes.
 
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
reply
    Bookmark Topic Watch Topic
  • New Topic