Data Types and Expressions

Slides:



Advertisements
Similar presentations
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Advertisements

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.
Computer Science 1620 Other Data Types. Quick Review: checklist for performing user input: 1) Be sure variable is declared 2) Prompt the user for input.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
CS102 Data Types in Java CS 102 Java’s Central Casting.
JavaScript, Third Edition
Basic Elements of C++ Chapter 2.
Expressions, Data Conversion, and Input
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Operator Overloading and Type Conversions
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
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.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Chapter 2: Using Data.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
CPS120: Introduction to Computer Science
CISC105 – General Computer Science Class 9 – 07/03/2006.
Unit 3 Lesson 4 How Data Types Affect Calculations Dave Clausen La Cañada High School.
Mathematical Calculations in Java Mrs. G. Chapman.
Chapter 4 Introduction to Classes, Objects, Methods and strings
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Copyright Curt Hill Variables What are they? Why do we need them?
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Chapters 2 & 3. .NET Software development model that allows applications created in disparate programming languages to communicate Universal data access.
Mathematical Calculations in Java Mrs. C. Furman.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
CPS120: Introduction to Computer Science Variables and Constants.
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
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.
LESSON 5 – Assignment Statements JAVA PROGRAMMING.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
April 13, 1998CS102-02Lecture 3-1 Data Types in Java CS Lecture 3-1 Java’s Central Casting.
LESSON 06.
Chapter Topics The Basics of a C++ Program Data Types
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Programming Fundamentals
Basic Elements of C++.
Revision Lecture
Multiple variables can be created in one declaration
Type Conversion, Constants, and the String Object
Chapter 3: Understanding C# Language Fundamentals
MIS Professor Sandvig MIS 324 Professor Sandvig
Basic Elements of C++ Chapter 2.
Chapter 2.
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Arithmetic Expressions & Data Conversions
C++ Data Types Data Type
Arrays .
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Data Types and Expressions
An Introduction to Programming with C++ Fifth Edition
Primitive Types and Expressions
Java’s Central Casting
C++ Programming Basics
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
Arrays, Casting & User Defined Variables
Review of Java Fundamentals
Arithmetic Expressions & Data Conversions
Presentation transcript:

Data Types and Expressions AKEEL AHMED

Overview Identifiers Variable and Literal Types, Classes, and Objects Converting data types Arrays

What is Identifiers? Identifiers are names of elements that appear in a program, such as data items. predefined identifiers System, Main, Console, and WriteLine. user defined identifiers class name like TestClass, method name like sum

C# Keywords/Reserve words From MSDN

Variable and Literal Value A variable represents an area in the computer memory where a value of a particular data type can be stored. Declaring a variable type identifier = expression; int examNumber=23; Literals are the numbers, characters, and combinations of characters used in your program

Types, Classes, and Objects Types: A kind of group that can be differentiated from other kinds of groups by a particular set of characteristics Classes: Types are actually implemented through classes in C#. The Framework class library, which is part of .NET, includes over 2000 classes that you can use in your programs. Objects: an object is an instance of a class

Predefined Data Types

Predefined Data Types

Variables (Syntax) int i = 7; double d=45.8; float fValue= 23f; string message = "Welcome"; object obj = new object(); bool male = false; decimal n3 = 1.234m;

Consts (Syntax) Variable is a place in memory that can be changed const int constValue = 50; constValue = 51; // Will cause compilation error

Converting data types Explicit conversion (also known as cast ) – Programmer forces the conversion and takes the risk of loosing data. byte b = 128; int i = b;

Converting data types Implicit conversion – Conversion is done by the complier automatically. No data is lost because of the conversion. Example: converting byte value (range: 0 to 255) to integer value (range: -2 147 483 648 to 2 147 483 647). decimal pi = 3.14; int notPi = (int)pi;

Converting data types Other conversions – Sometimes one needs to convert not-compatible types – for example convert string value “123” to integer value 123. For such case there are usually special methods. string text = "123"; int number = int.Parse(text); // number == 123

Arrays (Syntax) The array is a complex data type which handles a collection of elements. Each of the elements can be accessed by an index. All the elements of an array must be of the same data type. int[] numbers = new int[5]; numbers[0] = 3; numbers[1] = 2; numbers[2] = 1; numbers[3] = 5; numbers[4] = 6; int len = numbers.Length; for (int i=0; i<len; i++) { Console.WriteLine(numbers[i]); }