The document discusses data types in programming. It defines data types as specifying the different sizes and values that can be stored in variables. It then provides examples of declaring integer variables and assigning values in different programming languages. It also describes how memory can be visualized as an array of bytes, with each variable's address being the index of the first byte of that variable. Finally, it distinguishes between primitive data types that store single values and non-primitive types that can store multiple values.
The document discusses data types in programming. It defines data types as specifying the different sizes and values that can be stored in variables. It then provides examples of declaring integer variables and assigning values in different programming languages. It also describes how memory can be visualized as an array of bytes, with each variable's address being the index of the first byte of that variable. Finally, it distinguishes between primitive data types that store single values and non-primitive types that can store multiple values.
The document discusses data types in programming. It defines data types as specifying the different sizes and values that can be stored in variables. It then provides examples of declaring integer variables and assigning values in different programming languages. It also describes how memory can be visualized as an array of bytes, with each variable's address being the index of the first byte of that variable. Finally, it distinguishes between primitive data types that store single values and non-primitive types that can store multiple values.
The document discusses data types in programming. It defines data types as specifying the different sizes and values that can be stored in variables. It then provides examples of declaring integer variables and assigning values in different programming languages. It also describes how memory can be visualized as an array of bytes, with each variable's address being the index of the first byte of that variable. Finally, it distinguishes between primitive data types that store single values and non-primitive types that can store multiple values.
Data Types Data types specify the different sizes and values that can be stored in the variable.
int num=5: This statement is used to declare and initialize variable.
Assign 5 to num. Data type: int Variable name: num Value : 5 Assignment : =
Dr. Ibrahim Atoum 1-2
Data Types
Computer systems typically have many gigabytes of memory,
and each byte of memory has a unique address.
We can think of main memory or RAM as a large array of
bytes and the addresses as the indexes of each array element or byte within the array.
Most variables stored in the array (i.e., in main memory) are
larger than one byte, so the address of each variable is the index of the first byte of that variable.
Dr. Ibrahim Atoum 1-3
Data Types Main memory, often called RAM, can be visualized as a contiguous array of bytes. An address is equivalent to an index into the memory array.
Dr. Ibrahim Atoum 1-4
Data Types Most data types span multiple bytes of memory. Illustrated here are a sequence of 4-byte variables; depending on the compiler and the underlying hardware, these might be ints, longs, or floats. The address of multi-byte variables is the address or array index of the first byte.
Dr. Ibrahim Atoum 1-5
Data Types As an analogy for variables in memory, home addressing can be used. Every house has a unique street address that people can use to find and to distinguish it from the others on the same street. In much the same way, variables have addresses in main memory. Memory addresses are a property of the hardware and cannot change, but the data stored in memory - stored in a variable - can change or vary over time. Each variable has a unique address that gets larger as you move along the street or through memory.
Dr. Ibrahim Atoum 1-6
Data Types • There are two types of data types in Java: Primitive data types: a data structure that allows you to store only single data type values. Non-primitive data types: a data structure that allows you to store multiple data type values.
Dr. Ibrahim Atoum 1-7
Primitive Data Types A primitive data type is either a data type that is built into a programming language, or one that could be characterized as a basic structure for building more sophisticated data types. There are 8 primitive data types in Java. There are 4 primitive data types in Python.
Dr. Ibrahim Atoum 1-8
Non-Primitive Data Types There are five types of non-primitive data types in Java: Class, Object, String, Array and Interface.
There are 4 non-primitive data types in Python: lists, tuples,
dictionaries, and sets
Dr. Ibrahim Atoum 1-9
Boolean vs Numeric
Dr. Ibrahim Atoum 1-10
Data Type Default Size (in bits and bytes
Dr. Ibrahim Atoum 1-11
Data Type (Range Values)
Dr. Ibrahim Atoum 1-12
Default Value and Size
Dr. Ibrahim Atoum 1-13
Default Value and Size
Dr. Ibrahim Atoum 1-14
Char Data Type
• Default value: '\u0000‘.
• Size : 2 Bytes.
• Why is the size of char is 2 byte in java..?
In other languages like C/C++ uses only ASCII characters and to represent all ASCII characters 8-bits is enough. • Java uses the Unicode system not the ASCII code system and to represent Unicode system 8 bit is not enough to represent all characters so java uses 2 bytes for characters. • Unicode defines a fully international character set that can represent most of the world’s written languages. It is a unification of dozens of character sets, such as Latin, Greeks, Cyrillic, Katakana, Arabic, and many more. Dr. Ibrahim Atoum 1-15 ASCII
• ASCII, abbreviation of American Standard Code For
Information Interchange.
• It is a standard data-transmission code that is used by smaller
and less-powerful computers to represent both textual data (letters, numbers, and punctuation marks) and noninput-device commands (control characters).
• Coding systems converts information into standardized digital
formats that allow computers to communicate with each other and to efficiently process and store data.
Dr. Ibrahim Atoum 1-16
ASCII
Dr. Ibrahim Atoum 1-17
ASCII
• ASCII was originally developed for basic computers
and printers. It uses a 7-bit code to represent characters. • As more computers began to work with 8-bit groups of data, ASCII was written as 8 bits. • The most significant bit was sometimes used as a parity bit to perform a parity check (a form of error checking). Other computers set the most significant bit to 0.
Dr. Ibrahim Atoum 1-18
ASCII
• It was introduced in 1981 by the International Business
Machines Corporation (IBM) for use with its first model of personal computer. • This extended ASCII code soon became the industry-wide standard for personal computers. • In it, 32 code combinations are used for machine and control commands, such as carriage return. The next group of 32 combinations is used for numbers and various punctuation symbols. • Another group of 32 combinations is used for uppercase letters and a few other punctuation marks, and the last 32 are used for lowercase letters.
Dr. Ibrahim Atoum 1-19
ASCII
Dr. Ibrahim Atoum 1-20
Parity bit The sender's role is to add the parity bit. ASCII characters are represented using a 7-bit binary string. A parity bit is added to the beginning of the binary string (i.e. at the most significant bit, or MSB). Since it's even parity, the number of 1's in the 8-bit binary string must be even. For example, if the sender wanted to transmit the ASCII code for the letter 'A' (ASCII code 65), which is represented in binary as 1000001, a 0 would be added as the parity bit at the MSB. Therefore, 01000001 would be transmitted. Similarly, for ASCII code 'C', which is represented in binary by 1000011, a 1 would need to be added to make the number of 1's even. In this case, 11000011 would be transmitted. Dr. Ibrahim Atoum 1-21 Parity bit
Dr. Ibrahim Atoum 1-22
Unicode System
• Unicode uses 16 bits to represent the most commonly used
characters in a number of languages. This Basic Multilingual Plane allows for 65,536 characters.