Hey guys, I've just started learning Java and I have some questions which I would like to ask. Unless otherwise stated, all of the below are text from a book which I am reading from:
1) When using notepad, why is there a need to use spaces instead of tabs for indentations? I personally use the Eclipse IDE and I have tabbed my way through without any errors so far. Is there a reason for this in notepad?
2) When saving a .java file using notepad, I was told to save it with quotes (i.e. "Hello.java"). I re-read the paragraph multiple times and yes, the authors want the quotes in. Why is that so?
3) It was recommended that doubles be used in place of floats since doubles could hold a wider range of numbers. However, ints were recommended where possible over longs as "using less storage means your computer will run faster because there's more free space." In view of the fast computers we have today, is this actually relevant?
4) "Usually, you'll want to initialize each named constant to a single hard-coded constant....But be aware that it's legal to use a constant expression for a name constant initialization value." - I understand the first sentence, but not the second.
5) The following is with regards to writing a program such that it terminates when the user keys in "q" or "Q".
The provided code was:
The book then goes on to explain that this will not work because The response string variable and the "q" string literal both hold memory addresses that point to string objects; they don't hold string objects themselves. I do not quite get the bolded text.Quote:
Scanner stdIn = new Scanner(System.in);
System.out.print("Enter q or Q :");
response = stdIn.nextline();
if (response == "q" || response == "Q")