Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎

2018-09-13 Types

posted Sep 13, 2018, 6:04 AM by Konstantinovich Samuel   [ updated Sep 13, 2018, 10:30 AM ]
Stuyvesant has competed in an international  team programming competition that programs robots in outer space (Yes, real robots in the International Space Station).  Last year, our team came in first.  We have an interest meeting today, Thursday, after 10th period, at 3:45 in room 325.  Come on down and found out what it's like to program robots out there.  If you have questions, see (and try to find) Mr. Brooks.

Homework:
Install the java development kit:  (version 8 or 9 are both fine)


0. Terminal Stuff

Commands you should know and love:
cp     mv     
mkdir    rmdir
ls      
cd      pwd     
rm
cat    man

Commands you should learn to love:
nano   
ssh   
less    more 

Cool Commands that won't be required:

grep
|        (pipe)  lets you run the output of one program into another program
wc 




More detailed Linux/Unix tutorial:


Java Types

-Java is statically-typed (variables must be declared before they can be used)

The primitive data types: (you need the ones underlined)
byte/short/int/long
float/double
boolean
char

1. Integer

Integer types can hold whole numbers such as 123 and −96. The size of the values that can be stored depends on the integer type that we choose.

The range of values is calculated as −(2n−1) to (2n−1)−1; where n is the number of bits required. For example, the byte data type requires 1 byte = 8 bits. Therefore, the range of values that can be stored in the byte data type is:

−(28−1) to (28−1)−1
= −27 to (27) -1

= −128 to 127

Type Size Range of values that can be stored
byte 1 byte −128 to 127   OR  −27 to (27) -1
short 2 bytes −32768 to 32767   OR  −215 to (215) -1
int 4 bytes −2,147,483,648 to 2,147,483,647   OR −231 to (231) -1 
long 8 bytes −9,223,372,036,854,775,808 to
9,223,372,036,854,755,807  OR −263 to (263) -1


2. Floating Point

Floating point data types are used to represent numbers with a fractional part. Single precision floating point numbers occupy 4 bytes and Double precision floating point numbers occupy 8 bytes.  There are two subtypes, double can have both more significant digits, and a larger exponent. (Think scientific notation)

Type Size Digits that can be stored
float 4 bytes approximately 7 significant digits
double 8 bytes approximately 16 significant digits

3. Character

Character data type char hold single symbols such as

't', 'T' , '%' , '5' etc.

Special characters can be created using the \ (backslash) to escape the special character.

'\n',    '\t' , '\'' ,       '\\'

newline, tab,   single quote, bacsklash

The char data type is 2 bytes (ascii only requires 1), but it can hold only a single character because char stores unicode character sets. It has a minimum value of ‘u0000’ (or 0) and a maximum value of ‘uffff’ (or 65,535, inclusive).

4. Boolean

Boolean data types are used to store values with two states: true or false.

boolean (size not defined, because different JVM's can implement it differently)

5. Other Data Types

A String is not a primitive type. Strings are special because they are objects, and we will learn about them more later.

6. Literals and Identifier

Literal - a fixed value written in the source code. Not a variable or expression.
e.g.
54
"hello"
1.3
true
-341.823
1.23e2 (doubles can be written in engineering notation!)

Identifier - the name given to a variable/function.
Can contain:
     letters,
    digits,
     _ ,
    $  (Don't use dollar signs, and don't use underscores except when discussed in class)
May not start with a digit

e.g.
abbyNormalBrain
fish
bitter_sweet_chocolate_pie
x1y1z2_123
num$dollarsx123

Comments