 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.

Slides:



Advertisements
Similar presentations
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Advertisements

Constants and Data Types Constants Data Types Reading for this class: L&L,
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Types and Variables. Computer Programming 2 C++ in one page!
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
Structure of a C program
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
String Escape Sequences
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
Objectives You should be able to describe: Data Types
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
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.
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)
Input & Output: Console
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Variables.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
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.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Copyright Curt Hill Variables What are they? Why do we need them?
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Fundamentals 2.
Chapter 2 Variables.
Java Variables and Types
Lecture 2 Data Types Richard Gesick.
Documentation Need to have documentation in all programs
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Variables and Primative Types
Java Programming: From Problem Analysis to Program Design, 4e
IDENTIFIERS CSC 111.
Introduction to Java Programming
Chapter 2 Variables.
Chapter 2: Java Fundamentals
Chapter 2: Java Fundamentals
Primitive Types and Expressions
Chap 2. Identifiers, Keywords, and Types
Chapter 2 Variables.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Presentation transcript:

 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 Unicode character set.  Unicode is a two-byte character code set that has characters representing all characters in almost all languages and writing systems around the world.

 In Java program, all characters are grouped into symbols called tokens.  OR the smallest individual unit in a program is known as a token.  Tokens are- identifier, keyword, separator, operator, literal and comment.

 The first category of token is an Identifier.  Identifiers are used by programmers to name things in Java such as variables, methods, fields, classes, interfaces, exceptions, packages, etc.  All characters in an identifier are significant, including the case (upper/lower) of the alphabetic characters. Eg: The identifier Count and count denote different names in Java

 Identifiers are the names given to different part of the program viz. variables, objects etc.  Forming Rules  Identifiers can have alphabets, digits and underscore and doller sign characters.  They must not be a keyword or boolean literal or null literal.  They must not begin with digit.  They can be of any length.  Java is case sensitive i.e. Upper case and lower case letters are treated differently.

 Keywords are the second category of tokens in Java.  Keyword sometimes also called as reserved word.  Keywords have inbuilt meaning and the programmers cannot use for other things.  Below are the list of all keywords in Java.

 The third category of token is a Separator.  ;,. ( ) { } [ ]  Eg: Math.max(count,limit);  In the above segment the identifiers are Math, max, count, limit.  And the separators are. (, ) ;

 The fourth category of token is operator.  The keywords instanceof and new are the part of operators.  Below is the list of the operators in Java.

 The fifth category of tokens is literals.  The values written in Java are called literals.  Example: 1, 3.14, “Hello”, true, ‘a’, null.  int Literals: Literal of the primitive type int represent countable, discrete quantities.  0 is a non zero digit.  1,2,3,4……

 double Literals: Literal of the primitive type double represent measureable quantities.  Like real numbers in mathematics, they can represent fractions and numbers with decimal places.

 boolean literals: boolean literal gives one of the two results- true or false.  char literal: This is the first literal of text type.  char literal is enclosed within the single quotes.  Eg: ‘X’, ‘a’, ‘ ‘

 String literals: The second type of text literal is a String.  Example: “Enter your name”.  This is the only literal that is not of primitive type.  Note that the string is different from char.  String- “X”  char – ‘x’

 Sometimes you will see an escape- sequence inside the single-quotes for a character-literal or one or more inside double- quotes for a string-literal (see above); each escape sequence is translated into a character that prints in some "special" way.  Some commonly used escape sequences are:

 \n – new line  \t – horizontal tab  \v – vertical tab  \b – backspace  Eg:  If we output "Pack\nage", Java would print on the console  Pack age

 null literal: special kind of literal that is used to represent a special value.  Comments : The sixth and final category of tokens is the Comment.  Comments allow us to place any form of documentation inside our Java code. They can contain anything that we can type on the keyboard comment.

 Comments:  Comments are declared in two ways:  Line-Oriented: begins with // and continues until the end of the line.  Block-Oriented: begins with /* and continues (possibly over many lines) until */ is reached.

 There are two types of data types:  1. Primitive data types  2. Non-primitive data types  Primitive data types: There are eight primitive data types supported by Java.

 Size: 1 byte.  Range: -128 to 127.  Default value: 0.  Example: byte a = 100;

 Size: 2 bytes  Range: -32,768 to 32,767  Default value: 0  Example: short s = 1000;

 Size: 4 bytes  Range: -2,147,483,648 to 2,147,483,647  Default value: 0  Example: int a = 10000;

 Size: 8 bytes  Range: --9,223,372,036,854,775,808 to 9,223,372,036,854,775,807  Default value: 0  Example: long a=100000L;

 Size: 4 bytes  Default value: 0.0f  Example: float f1 = 3.14f;

 Size: 8 bytes  Default value: 0.0d  Example: double d1= 3.14d;

 boolean data type represents one bit of information.  There are only two possible values: true and false.  This data type is used for simple flags that track true/false conditions.  Default value is false.  Example: boolean one = true

 Size: 2 bytes  Range: 0 to 65,535  Example: char a=‘A’;

 Reference variables are created using defined constructors of the classes.  They are used to access objects. These variables are declared to be of a specific type that cannot be changed.  Example: Animal animal = new Animal(“dog");

 A variable is a named memory location, which holds a data value of a particular data type.

 int age;  float principalAmount;  int a;  double b;

 int age = 50;  float principalAmount = 5000;  int a = 10;  double b = 20.0;

 int age = 50;  int b = age * 10;  int c = age;