Chapter 2 - Data and Expressions Flashcards
What are the objectives of this chapter?
- Use of character strings, concatenation, and escape sequences.
- Explore the declaration and use of variables.
- Java primitive data types, expressions.
- Syntax and processing of expressions.
- Types of data conversions and mechanism for accomplishing them.
- Scanner class to create interactive programs.
What is a character string in Java and which class is it define by?
The character string is an object defined by the class string.
Whats the object and class here: System.out.println?
The system.out is the object representing an output device or file, which by default is the computer screen. The object’s name is OUT stored in System class using the print line method (println). Each piece of data we send is called a PARAMETER.
What’s the difference between print and println?
Print does not move to the next line. So if I System.out.print(“Three…”);
System.out.print(“Two…”); it will print Three…Two… on the same line.
System.out.println(“Liftoff!)
How do you add two numbers?
System.out.println( + (10 + 20) or + 10 + 20)
What are some escape sequences?
\b = backspace \t = tab \n = newline \r = carriage return \" = double quote \' = single quote \\ = backlash
What does this line produce? “Sugar is sweet. \n\tBut U have "commitment issues".\n\t”);
Sugar is sweet.
But I have “commitment issues”.
Is most of the information we manage in a program represented by variables?
Yes.
What is a VARIABLE? What does a variable DECLARATION instruct the compiler to do?
A variable is a NAME for a location in memory used to hold a data value of a particular DATA TYPE. A variable declaration INSTRUCTS the compiler to reserve a portion of main memory space large enough to hold a particular type of value and indicates the NAME by which we refer to that location.
Explain int keys = 88, count, minimum = 0, results;
integer type variable named keys that equals the value 88.
What does it mean when we say Java is a STRONGLY TYPED language?
We are not allowed to assign a value to a variable that is inconsistent with its declared type.
What are CONSTANTS?
Constants are identifiers and are similar to variables except that they hold a particular value for the duration of their existence. CONSTANTS are, to use the English meaning of the words, not variable. Their values doesn’t change.
How do you DECLARE a constant?
By putting a final in front of it. final int MAX_OCCUPANCY = 427;
How many Primitive Data types are there in Java and what are they?
There are 8 PRIMITIVE DATA TYPES in Java? Four types of integers, two types of floating point numbers, a character type, and a boolean data type. Everything else is represented using objects.
What are the two basic kinds of numeric values?
integers (no fractional part) & floating points (do have fractional parts). These two are divided by how much space (four integer data types, two floating).