Imports. Lexicon. Java/Lespérance 1. PROF. Y. LESPÉRANCE Dept. of Electrical Engineering & Computer Science

Similar documents
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

An overview of Java, Data types and variables

Programming in C++ 4. The lexical basis of C++

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Declaration and Memory

Language Fundamentals Summary

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Program Fundamentals

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Java Basic Datatypees

The MaSH Programming Language At the Statements Level

Computer Components. Software{ User Programs. Operating System. Hardware

COMP 202 Java in one week

3. Java - Language Constructs I

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Java Programming. Atul Prakash

Basic Types, Variables, Literals, Constants

2 rd class Department of Programming. OOP with Java Programming

Java Programming Language Mr.Rungrote Phonkam

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

Computer Components. Software{ User Programs. Operating System. Hardware

Java Notes. 10th ICSE. Saravanan Ganesh

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Tony Valderrama, SIPB IAP 2009

CSC 1214: Object-Oriented Programming

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

Index COPYRIGHTED MATERIAL

Java Overview An introduction to the Java Programming Language

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

CHAPTER 2 Java Fundamentals

CSCI 2101 Java Style Guide

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Tony Valderrama, SIPB IAP 2010

The Java Language The Java Language Reference (2 nd ed.) is the defining document for the Java language. Most beginning programming students expect

Introduction to Programming Using Java (98-388)

JAVA Programming Fundamentals

6.096 Introduction to C++ January (IAP) 2009

Preview from Notesale.co.uk Page 9 of 108

The Java Language Rules And Tools 3

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

MP 3 A Lexer for MiniJava

Basic Elements of C. Staff Incharge: S.Sasirekha

Accelerating Information Technology Innovation

Java Fall 2018 Margaret Reid-Miller

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

Pace University. Fundamental Concepts of CS121 1

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

ECE 122 Engineering Problem Solving with Java

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

VLC : Language Reference Manual

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Lecture Set 2: Starting Java

Variables. Data Types.

Chapter 2. Elementary Programming

Objec+ves. Review. Basics of Java Syntax Java fundamentals. What are quali+es of good sooware? What is Java? How do you compile a Java program?

Lecture Set 2: Starting Java

Tokens, Expressions and Control Structures

CompSci 125 Lecture 02

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Data Types and Variables in C language

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Syntax and Variables

Types, Variables, and Constants

Key Differences Between Python and Java

Week 6: Review. Java is Case Sensitive

Presented By : Gaurav Juneja

3. Java - Language Constructs I

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Language Reference Manual

Introduc)on to C++ CS 16: Solving Problems with Computers I Lecture #2

Programming Lecture 3

Lecture 2 Tao Wang 1

For the course, we will be using JCreator as the IDE (Integrated Development Environment).

LECTURE 02 INTRODUCTION TO C++

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Introduction to C++ General Rules, Conventions and Styles CS 16: Solving Problems with Computers I Lecture #2

c) And last but not least, there are javadoc comments. See Weiss.

Java Programming Basics. COMP 401, Spring 2017 Lecture 2

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

VARIABLES AND CONSTANTS

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

2 nd Week Lecture Notes

Chapter 2: Introduction to C++

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Getting started with Java

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

A web-based IDE for Java

Programming. C++ Basics

Transcription:

Lexicon CS1022 MOBIL COMPUTING PROF Y LSPÉRANC Dept of lectrical ngineering & Computer Science 1 2 Imports 3 Imported Class = DelegaKon 4 Java/Lespérance 1

Lexicon Class Header Class Body, a Block import javalang*; Method Header Method Body, a Block 5 6 Style Class naming conven:on A noun Use Pascal/Title case, eg Math, ArrayList Method naming conven:on A verb Use camel case, eg equals, tostring, isleapyear Variable naming conven:on A noun Use camel case, eg length, interestrate, gender Applies also to anributes and parameters Block layout Braces must align ver:cally and the all statements must be leh jus:fied and indented by one tab posi:on Lexical lements Without worrying about syntax or semankcs, let us idenkfy the elements of a program: Keywords Iden:fiers Literals Operators Separators 7 8 Java/Lespérance 2

Lexicon Keywords Identifiers Literals Operators Separators The reserved words are the keywords plus the literals: true, false, null Must not be a reserved word, must begin with a letter, and its character set must be: 0-9, A-Z, a-z,, _ Recognized by the presence of a number, 'character', "characters", or one of: true, false, null The character set of operators: = > <! ~? : & + - * / ^ % The separators are:, ; ( ) [ ] 9 Keywords abstract assert boolean break byte case catch char class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while 10 xample IdenKfy the language elements in the following program Keywords, Identifiers, Literals, Operators, Separators Keywords, Identifiers, Literals, Operators, Separators 11 12 Java/Lespérance 3

Lexicon Keywords, Identifiers, Literals, Operators, Separators 13 Keywords, Identifiers, Literals, Operators, Separators 14 Compile Time vs Run Time rrors Before program can run, it must be compiled to (transalted) Java bytecode Studio does this as you enter/edit your code; it flags compile-:me errors: Syntax errors, eg missing ; ( Type errors, eg abc * 3 Compile Time vs Run Time rrors When you execute your program, you may get run:me errors: Arithmeticxception, eg 10 / 0 ArrayIndexOutOfBoundxception, etc Logic errors: program appears to run normally but does not behave as required 15 16 Java/Lespérance 4

Declara'on CS1022 MOBIL COMPUTING The Declara7on Statement type name; The name of a primi7ve or nonprimi7ve type, eg int, double A separator CS4413/ Roumani An iden7fier to be associated with a memory block PROF Y LSPÉRANC Dept of lectrical ngineering & Computer Science The scope of the variable = the enclosing block of the declara6on The variable is not known outside its scope Declara6on does not ini6alize Not with 0 or null or anything else 1 2 Primi7ve & Non-Primi7ve Primitive number character Integer int long 4 8 ±2G exact ±2 exact Non-Primitive boolean class interface array Integer literals are int by default unless suffixed with L Real float double 4 8 ±10 38 SD=7 ±10 308 SD=15 Real literals are recognized by a decimal point or an exponent They are double by default unless suffixed with F For exponen'al nota'on, use 3 4 Java/Lespérance 1

Declara'on The Type boolean Integer Real Use for integer data, eg count 100% exact Use for real data, eg amount Inherently inaccurate Stores the result on a condi7on Has only two possible values true and false are reserved words Boolean variables are not integers The Boolean operators are: && (for and), (for or), and ^ (for xor) Note: Boolean literals are the easiest to recognize! 5 6 The Character Type char A lewer, digit, or symbol Digits versus Numbers Store the code, not the typeface The case of nglish: ASCII vs UniCode char is thus an (unsigned) integer type No char operators! They auto-promote to int Character literals are recognized by single quotes surrounding the character, eg 'A' More on Characters Code Character 0 32 space 48-57 '0'-'9' 65-90 'A'-'Z' 97-122 'a'-'z' 65535 scape \uxxxx \' Meaning The character whose code is (hex) xxxx Single quote \" Double quote \\ Backslash \n New line \r Carriage return \f Form Feed \t Tab \b Backspace 7 8 Java/Lespérance 2

Declara'on N U M B R Java s Primitive Type PRIMITIV TYPS I N T G R Type Size (bytes) Approximate Range min max SD S byte 1-128 +127 N/A? I G short 2-32,768 +32,767 N/A? N int 4-2 10 9 +2 10 9 N/A? D long 8-9 10 18 +9 10 18 N/A? UNSIGND char 2 0 65,535 N/A? R SINGL float 4 +34 10 38 +34 10 38 7 A L DOUBL double 8-17 10 308 +17 10 308 15 BOOLAN boolean 1 true/false N/A 9 Class Type String Stores a sequence of characters Op7mized for speed à immutable Op7mized declara7on à shortcut (in javalang) Op7mized concatena7on à + operator Rich API (eg indexof, charat, substring) Note: String literals are surrounded with double quotes and can use the same escape sequences as chars 10 Class Type Date Stores an instance of 7me Captures both date and 7me Accurate to a millisecond Simple API (tostring and gettime) (in javau6l) Class Type RectangleModel (in our package) Stores an instance of a rectangle Captures the height and width as int API (getarea and getcircumference) Note: Like all class types (except for String), Date has no literals and no operators Like all class types (except for String), it has no literals and no operators 11 12 Java/Lespérance 3

Declara'on Class Type FractionModel (in our package) Stores an instance of a frac7on Numerator and denominator are long API (add, sub, mul7ply, divide, ) Class Type TextView (in androidwidget) Stores a UI label Many awributes: text, layout, style, API (gettext, settext, settypeface, ) Like all class types (except for String), it has no literals and no operators Like all class types (except for String), it has no literals and no operators 13 14 An operator name = value; - Pre-declared and in-scope - Its type can hold RHS - Its content will be overwriwen A separator - a Literal - a Name, or - an xpression 15 Java/Lespérance 4