Below are important Question & Answers taken from the Q&A discussions in this section.

Q1. What is  Algorithm complexity?

It is related to algorithm complexity and it comes from the field of Algorithms and is one of the first things taught in an algorithm course. It is often referred to as "asymptotic analysis". It is difficult to explain the concepts here, but I will give a very high-level idea. "O" is referred to as Big-Oh notation and it tells how an algorithm performs in the worst-case. Generally, if you design an algorithm, then one might ask you what the complexity of the algorithm is to get an idea of how it works. N in the parenthesis is the input size. O(N) means linear complexity. For instance to search an element in a list of 1000 elements (N is 1000), one way is to scan the elements from the beginning until the element is found or you don't find the element. In the worst-case, the element you are searching may not be there or it may be the 1000th element. This search might take some time. Now, if N is 10000 or 1 million, then your worst-case search time also grows linearly with the input size. In this case, your algorithm is doing a naive lookup of one item at a time. But, some other algorithm might do it in a better way. One example is hash algorithm, which we will see in Collections Framework chapter. Here the elements are stored in some special way (via a technique called hashing) and when you search for an element, it would return the element almost instantly. Here it doesn't matter whether your N is 1000 or 10k or 1 million, it will almost always take the same amount of time to find whether your element is there in the list or not. In this case, the complexity is said to be O(1) ~ it is referred to as constant time, i.e., performance is constant regardless of the size of the data. Now, if your data is sorted and if an algorithm like binary search is applied, then the complexity would be logarithmic, i.e., O(log(n)), which is better than O(N), but worse than O(1), i.e., when you move from 1000 elements to 10k, the time would not grow as significantly as an O(N) algorithm. There are also other complexities like quadratic ~ O(N2), cubic ~ O(N3), which are even worse. Here N2 is N raised to the power of 2 and same applies to N3.

At some point, I will definitely try to add a bonus lecture on this topic. You may want to get a high-level understanding of algorithm complexity when you get to Section 15 (Collections Framework), which deals with data structures and we will be seeing how different data structures perform. Generally, if you are into Web development and stuff like that you may never have to worry that much about them. But, if you are into algorithm development, then understanding of algorithm complexity is a MUST and you will definitely encounter some questions on it in the interview. But, even for Web development, I would recommend to have a basic understanding of it.

You can also read about it from the following link, which describes these concepts in a pretty simple way. I read it long time back and I felt it was explained in a very simple way ~ generally in many cases it is explained in not so easy way as authors get into some math behind these concepts. But, below article should give you a better idea. It is also a good online Java book and so you can bookmark it.

http://math.hws.edu/javanotes/c8/s5.html

Q2. How can I draw a java smiley using utf 16 code in eclipse as all I am getting is a square in the eclipse editor.

char CharacterUnicodeDemo='\uE056';

I am not sure about that character. But, try '\u263A'. Ensure the following too:

1. In Eclipse, go to Window -> Preferences -> General -> Workspace -> Text File Encoding -> Other (UTF-8)

2. Font selection: In Eclipse, go to Window -> Preferences -> General -> Appearance -> Colors and Fonts -> Console Font -> Click Edit button and select "Segoe UI Symbol" in Font and hit ok -> hit apply and try running the program. If you don't see "Segoe UI Symbol", click on See more fonts and see if you can find it. If you still cannot find it try 3rd step

3. Control Panel --> Fonts --> Font settings -> Ensure 'Hide fonts based on language settings' is disabled and hit ok. Now, restart Eclipse and do step 2 above to see if "Segoe UI Symbol" can be seen


For me it did print a smiley after following the above steps. Hope that helps. Essentially, you need to have the font selected for your eclipse that supports those smileys.

References:

http://paranoid-engineering.blogspot.com/2008/05/getting-unicode-output-in-eclipse.html

https://stackoverflow.com/questions/1799458/display-the-unicode-value-in-the-java-screen

https://superuser.com/questions/336197/unicode-characters-suddenly-start-displaying-as-boxes-in-some-applications

https://stackoverflow.com/questions/44337894/what-is-the-microsoft-office-smiley-face-character-really

Some definitions:

Font: A font is a digital file which is used to display a typeface, which contains the entire upper- and lowercase alphabet as well as punctuation, numbers, and other special characters. 

Glyph: A glyph is an image, usually stored in a font (which is a collection of glyphs).

Excellent Reference on these definitions: https://stackoverflow.com/questions/27331819/whats-the-difference-between-a-character-a-code-point-a-glyph-and-a-grapheme

Q3. If every statement in Java ends with a semicolon then how can a if  condition called a control flow "statement" since it does not ends with a  semicolon?

The most likely reason is the ending brace } implicitly signals the end of the statement. Below is a good post discussing this.

https://stackoverflow.com/questions/5561869/why-semicolon-is-not-required-after-a-curled-bracket

Q4. You mentioned that the integer range is related to the bit depth. Please explain how we get range from the bit depth.

Let's consider byte whose bit-depth is 8. With 8 bits you can represent 256 numbers (2 raised to 8). And these 256 numbers fall in the range -128 to +127 including 0. In binary, whether a number is +ve or –ve is represented by 1 bit (called sign bit), which would be the most significant bit and it appears on the left most end; the remaining 7 bits indicate the magnitude of the number. That’s the reason the range says -2 raised to 7 to 2 raised to 7 – 1 (i.e., -128 to +127).

Q5. why byte is first converted to int and then to char? why is this intermediate conversion to int is required?

byte is signed integer where as char is unsigned integer and byte's range ([-128, 127]) is not a subset of char's range ([0, 65535]). So, byte is first converted to a type (int) whose range covers the range of char. So, byte is converted to int via sign-extension (i.e., widening) and then int is then narrowed down to char. Below is what Java language specification has to say and below is the link too. Thanks.

First, the byte is converted to an int via widening primitive conversion (§5.1.2), and then the resulting int is converted to a char by narrowing primitive conversion

https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.4

Q6. (This is a re-phrased question to give more clarity on Arrays). In a single application, can we have 1D, 2D and 3D arrays representing same data?

Answer: Yes. With each added dimension, the corresponding array would provide more details. Let's pick the same use-case we saw in 3D arrays lecture where we were capturing # units sold for 4 products (TV, Laptop, iPad, iPhone) across different months and cities. Let's assume we have these 4 products that are sold by a  particular retail store and lets say the # units sold in first Quarter is represented in the following 1D array.

int[] itemsSoldByQuarter = {1000, 2000, 3000, 4000}; // i.e., 1000 TVs were sold in the quarter 

Now, let's say we want to view the above data on a month-by-month  basis that make up the first quarter, which includes January, February,  and March. So, month is a new dimension and so the above data when  represented in 2D array would be as follows. Note the variable names I  am using too.

int[][] itemsSoldByMonth = { {350, 700, 1000, 1000}, <--- Jan sales

                                                    {350, 700, 1000, 2500}, <--- Feb sales

                                                    {300, 600, 1000, 500}}

If  you sum up the first column 350 (# TVs sold in Jan) + 350 (# TVs sold  in Feb) + 300 (# TVs sold in Mar), you get 1000, which is what the total  sales of TVs was for first quarter in the 1D array.

Now, let's add one more dimension. Let us say this store operates in two cities: San Francisco & New York and the above two array represent  the sales across both cities combined. Now, by adding one more  dimension, we can represent the sales of each product, for each month by city.  So, the 3D array looks as follows:

int[][][] itemsSoldByMonthAndCity = { { <-- this new dimension is say for San francisco

                                                                       {150, 300, 500, 800}, <--- Jan sales in San Francisco

                                                                       {100, 300, 200, 1000}, <--- Feb sales in San Francisco

                                                                       {100, 400, 300, 200} <--- Mar sales in San Francisco

                                                                     },

                                                                     { <-- this one is for New York

                                                                       {200, 400, 500, 200}, <--- Jan sales in New York

                                                                       {250, 400, 800, 1500}, <--- Feb sales in New York

                                                                       {200, 200, 700, 300} <--- Mar sales in New York

                                                                     }

                                                                   }

Now,  in this 3D array, if you add up the the values in first column, it  amounts to 1000, which is the #TVs sold in total (first element in 1D  array above). If you add just the 0th element in inner arrays  representing Jan sales in both the cities, you have 150 & 200  (emphasized in bold) and you get 350, which is the #TVs sold in Jan  across both cities, which is  itemsSoldByMonth[0][0] in the 2D array.

Hope it is clear now. If required, just brainstorm a bit more on this and it should get clear. Can be confusing at times.   

Q7. Is there any specific reason for this() statement to be first? 

Answer: The main reason is to do with inheritance, which is  discussed in OOPS-related sections few sections from here. There you  come across the concept of super class & subclass where subclass  extends super class and inherits properties (e.g., certain variables  & methods) of super class. So, a super class object should  first be constructed before a subclass object is constructed.  Otherwise, subclass object can inherit variables that are not  initialized in super class, which is meaningless. To make this work  properly, super class constructors are invoked from the sub-class  constructors by using a super() call (can be done by compiler too, but  let's not worry about this as this will be clear when we get to  inheritance)

So, coming to your question, if you have a this()  statement as first one, then it would invoke another constructor, which  in turn invokes the super class constructor via super() thus ALWAYS  ensuring that super class object is fully constructed before subclass  object.

Below post is relevant and I found the user Randa Sbeity's  answer useful. However, this restriction is not that popular as  discussed in few answers in the below post (including language  designers) and why that is the case is not entirely clearly to me at  this point -- probably requires to do much more in-depth reading.

https://stackoverflow.com/questions/1168345/why-do-this-and-super-have-to-be-the-first-statement-in-a-constructor