Chapter 2: Concepts Review

Concepts Review

  1. The information we manage in a Java program is either primitive data or ADT.
  2. An abstraction hides details. A good abstraction hides the right details at the right time.
  3. A variable is a name for a memory location used to hold a value of a particular data type.
  4. A variable can store only one value of its declared type.
  5. Java is a strongly typed language. Each variable has a specific type, and we cannot assign a value of one type to a variable of another type.
  6. Constants are like variables, but they hold one particular value.
  7. Java has two kinds of numeric values: integers and floating point. The primitive type int is an integer data type and double is a floating point data type.
  8. Many programming statements involve expressions. Expressions are combinations of one or more operands and the operators used to per­ form a calculation.
  9. Java has rules that govern the order in which operators will be evalu- ated in an expression.
  10. Avoid narrowing conversions because they can lose information.
  11. The new operator returns a reference to a newly created object.
  12. The Java standard class library is a useful set of classes that anyone can use when writing Java programs.

Submit answers to the following questions:
1. What is the content of an object variable?
2. Write a code snipped to compare two strings, s1 and s2. If s1 comes first in the lexicographic order, then it will print “move two steps forward” else “move two steps backwards.
3. Why the “= =” cannot be used to compare objects?
4. Give an example of widening and narrowing type conversion for each.
5. What is the purpose of casting when using a casting operator in the case of narrowing type conversion.
6. What is the result of 21 % 6 when evaluated in a java expression?
7. What is the result of (double) (15/2) in a java expression?
8. What does the operator new do?
9. Write the statement to print “Hello World” including the quotes.
10. What does “123456789”.substring(3,6) return?
11. Write a main method that prompts the use for two numbers, x and y, and it displays it back the following format: (x,y).

Chapter 2: Do programming assignments 2.13, 2.14 and 2.15 but instead of an applet write an application. You can use the university libraries or the java graphics libraries. The assignments are at the end of the chapter.
Screen Shot 2014-09-09 at 10.13.27 PM

screen-shot-2016-09-19-at-5-25-49-pm

Homework:
Read/browse pages 58 through 79