The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.

Slides:



Advertisements
Similar presentations
Chapter 1 Chapter 2 Chapter 3 Code Gone Wrong Random 5 pt 5 pt 5 pt
Advertisements

Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Introduction to Computers and Programming Lecture 7:
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 9: Characters * Character primitives * Character Wrapper class.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
Data Representation (in computer system) Computer Fundamental CIM2460 Bavy LI.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
String Escape Sequences
CHARACTERS Data Representation. Using binary to represent characters Computers can only process binary numbers (1’s and 0’s) so a system was developed.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
The character data type char
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Binary Arithmetic & Data representation
Computer Structure & Architecture 7c - Data Representation.
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for.
Fill in the blanks: (1) _________ has only two possible values 0 and 1. (2) There are __________bits in a byte. (3) 1 kilobyte of memory space can store.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Floating point numerical information. Previously discussed Recall that: A byte is a memory cell consisting of 8 switches and can store a binary number.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
PHY 107 – Programming For Science. Announcements  Slides, activities, & solutions always posted to D2L  Note-taking versions before class, for those.
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
Primitive Variables.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Unit 2 Test: Tues 11/3. ASCII / Unicode –Each letter, symbol, etc has a # value –See ascii table (in folder) –To convert a char into its ascii value,
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
Agenda Character representation Numerical Conversions ASCII EBCDIC
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
Information Coding Schemes Group Member : Yvonne Tiffany Jurifah bt Junaidi Clara Jane George.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
7. BASIC TYPES. Systems of numeration Numeric Types C’s basic types include integer types and floating types. Integer types can be either signed or unsigned.
Lecture 4 Monday Sept 9, Variables and Data Types ►A►A►A►A variable is simply a name given by the programmer that is used to refer to computer storage.
1.4 Representation of data in computer systems Character.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Nat 4/5 Computing Science Data Representation Lesson 3: Storing Text
Primitive Types Four integer types: Two floating-point types:
Chapter 2 Basic Computation
Binary 1 Basic conversions.
ITEC113 Algorithms and Programming Techniques
FATİH SULTAN MEHMET VAKIF UNIVERSITY Faculty of Engineering & Architecture Computer Engineering Department MAT217E - DİSCRETE STRUCTURES Slides for a.
Data Encoding Characters.
Chapter 2 Basic Computation
Primitive and Reference Data Values
Chapter 8 Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single.
The Boolean (logical) data type boolean
Presenting information as bit patterns
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
Learning Intention I will learn how computers store text.
Primitive Types and Expressions
ASCII LP1.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Presentation transcript:

The character data type char

Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory to store the Unicode value

Unicode Unicode provides a unique number for every character

ASCII code (1) The value of the Unicode is called the ASCII code The American Standard Code for Information Interchange (ASCII) code was designed to represent characters in the English alphabet

ASCII code (2)

Defining character typed variables (1) Syntax to define an character typed variable: The keyword char announces the variable definition clause The NameOfVariable is an identifier which is the name of the variable. The variable definition clause is must be ended with a semi-colon ";" A char typed variable can store the Unicode of one character

Character literals A character literal is written between quotes '...‘

Defining character typed variables (2)

char and int (1) A char typed variable contains a character code A character code is a (positive) number So: a char data type is an integer data type !!! The size of the char data type is 2 bytes The range of values of the char data type is: [ ]

char and int (2) A char variable is an integer typed variable. The expression 'A' is an integer (= 65) in a Java program !!!!

char and int (3) Although char type is a kind of integer type, it is treated differently when we want to "see" the value (e.g., printing) Different encoding methods used in printing: When printing a char typed integer, the print and println methods will use the Unicode table to print the corresponding character. When printing other kinds of integer types, the print and println methods will use the binary number encoding.

Converting char to int: Operations on the char data type (1) All operations on integer typed values in Java are converted to int type the conversion from char to int is safe:

Converting char to int: Operations on the char data type (2)

Converting char to int: Operations on the char data type (3)

Converting other integer type into char (1) It is always unsafe to convert any integer type (byte, short, int, and long) to char: The range of byte, short, int, and long include some negative values The range of values of char only contain positive values (including 0). We must use casting (char) to assign any kind of integer value to a char typed variable.

Converting other integer type into char (2)

Converting other integer type into char (3) The (same) value will now be interpreted using the Unicode code System.out.println(a); will print the letter 'b'.

Testing for lower case and upper case characters How to detect a lower case letter: How to detect an upper case letter:

Converting a lower case character into the same upper case character (1) We can convert an Unicode code for a lower case letter into the same upper case letter by subtracting 32 from the code value.

Converting a lower case character into the same upper case character (2)