Key Points from WEEK 7 10/11/2024 Lecture 1. We will be following the Oracle Java tutorial: You can find the link to it on the course web site https://radourmeire.com/it/ We will begin with New to Java > Learning the Java Language > Language Basics 2. Because Java is object oriented, there are different types of variables (instance, class, local, parameter), however we will focus on local variables and parameters first. When we study objects and classes we will learn about instance and class variables. 3. As we discussed last time, variables correspond to blocks of main memory (RAM) that the program has acces to when it is running. There are different types of data that can be represented in a program, for example numerical data and textual data. When a variable is declared, its data type must be specified. 4. There are two broad categories of data types in Java: primitive types and reference types. For now we will concentrate on primitive types, and we will return to reference types when we study objects and classes in detail. 5. Among the primitive types there are again two main categories: numeric and non-numeric. 6. The numeric types are byte, short, int, long, float, double 7. Among the numeric types there are the integer types (byte, short, int, long) and the non-integer types (float, double) 8. A byte is 8 bits and the value stored in a byte variable is represented in two's complement notation, which we will discuss in detail later. 9. There are 2^8 possible configurations of 8 bits. Half of these are used for negative integers, and half of them are used for non-negative integers. As a result of the two's complement representation, a bit sequence with the most significant bit set to 1 represents a negative integer. A bit sequence of all zeros represents 0. All other bit sequences beginning with 0 are positive integers. Hence, there are 2^7 configurations available for negative numbers and (2^7) - 1 configurations available for positive integers. Therefore, the range of integers that can be represented in a byte is [-128,127]. 10. A short is 16 bits (2 bytes). So it takes up twice as much space as a byte. However, it provides 2^16 possible configurations, 2^8 times as many as a single byte. The internal representation is the same, so the possible range is [-32768,32767]. 11. An int is 32 bits (4 bytes), double the size of a short, with 2^16 times as many values as a short, and also in two's complement form, so the the range is [-2^31,(2^31)-1]. 12. Likewise, a long is 64 bits (8 bytes), with a range of [-2^63,(2^63)-1] 13. The non-numeric types are boolean and char 14. The possible values represented by a boolean can be indicated using the literals true and false. 15. A char is a 16-bit unicode unit which can be represented using the \u escape sequence as in the character literal '\u263A\', which is a ☺ (smiley face). The characters following the \u are hexadecimal (base-16) digits, which range from 0-F. 16. Other types of literals are numeric literals as in : int a = 100; // 100 is a literal that indicates a value of 100, which should be stored in the variable identified as a int b = 0b01100100; // The 0b prefix means that the characters that follow it are binary digits. This has the same effect as // int b = 100; int c = 0x2B; // The 0x prefix means that the characters that follow it are hexadecimal (base-16) digits. Therefore, this // has the same effect as int c = 43 float d = 1.234f; double e = 2.718281828459045d; For more examples with literals, see New to Java > Learning the Java Language > Language Basics > Variables > Primitive Data Types