Language Fundamentals Summary

Similar documents
Java Notes. 10th ICSE. Saravanan Ganesh

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

3. Java - Language Constructs I

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

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

Java Programming. Atul Prakash

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

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

DEPARTMENT OF MATHS, MJ COLLEGE

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

JAVA Programming Fundamentals

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

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

Index COPYRIGHTED MATERIAL

An overview of Java, Data types and variables

UNIT- 3 Introduction to C++

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

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

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Fundamental of Programming (C)

CSC 1214: Object-Oriented Programming

Program Fundamentals

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

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

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

JAC444 - Lecture 1. Introduction to Java Programming Language Segment 4. Jordan Anastasiade Java Programming Language Course

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

Accelerating Information Technology Innovation

Introduction to C# Applications

Java Basic Datatypees

Basics of Java Programming

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

A variable is a name that represents a value. For

3. Java - Language Constructs I

Programming Lecture 3

Operators and Expressions

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

The Warhol Language Reference Manual

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

6.096 Introduction to C++ January (IAP) 2009

The MaSH Programming Language At the Statements Level

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

Java Overview An introduction to the Java Programming Language

Visual C# Instructor s Manual Table of Contents

4 Programming Fundamentals. Introduction to Programming 1 1

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

Introduction to Programming (Java) 2/12

Chapter 6 Primitive types

Java Programming Fundamentals. Visit for more.

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Values and Variables 1 / 30

COMP 202 Java in one week

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

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

Introduction to Programming Using Java (98-388)

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

ISA 563 : Fundamentals of Systems Programming

Preview from Notesale.co.uk Page 9 of 108

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

Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C

Variables and literals

1 Lexical Considerations

2 rd class Department of Programming. OOP with Java Programming

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

More Programming Constructs -- Introduction

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

Data Types and Variables in C language

Fundamentals of Programming

Review of the C Programming Language for Principles of Operating Systems

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

TED Language Reference Manual

Lexical Considerations

Lexical Considerations

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Lecture 3. More About C

Operators. Java operators are classified into three categories:

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

A Java program contains at least one class definition.

Lecture 02 C FUNDAMENTALS

Client-Side Web Technologies. JavaScript Part I

2 nd Week Lecture Notes

PYTHON- AN INNOVATION

Differentiate Between Keywords and Identifiers

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Workbook 2. Remember to check the course website regularly for announcements and errata:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

CS313D: ADVANCED PROGRAMMING LANGUAGE

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

COMP6700/2140 Operators, Expressions, Statements

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Language Reference Manual simplicity

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Java Programming Language Mr.Rungrote Phonkam

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Transcription:

Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de Keywords carry fixed semantics must not be used as identifiers elsewhere in the program abstract default if private throw boolean do implements protected throws break double import public transient byte else instanceof return try case extends int short void catch final interface static volatile char finally long super while class float native switch const* for new synchronized continue goto* package this 2 1

Comments /* Simple comments are enclosed like this */ // Are the start of a one-line-comment /** Documentation comments can also be included */ All lines included start with ** Documentation comments are evaluated by the documentation tool of the JDK. Results in HTML pages. Special tags within the comments for information often included lead to special formatting in HTML: @param @return @exception @author @see @version 3 Documentation Comments /** * Compares two objects for <B>equality</B>. * Returns a boolean that indicates whether this Object * is equivalent to the specified Object. * @param obj the object to compare with * @return true if these Objects are equal; * false otherwise. */ public boolean equals(object obj) {... 4 2

Data In Java, almost everything is an object. Objects are described by reference types like the type String, classes or arrays Some simple data types, however, are frequently used as programming basis. These so-called primitive types are built-in types, implying a behaviour different from reference types 5 Primitives Built-in types: not object handles, but variables on the stack like C. boolean, char (Unicode), byte, short, int, long, float, double Consequences for bindings and comparisons. Size of each data type is machine independent. 6 3

Binding and Comparing Primitives Binding a variable to a primitive value means copying this value into the variable's storage cell. int a = 100; a 100 b 75 int b = 75; Assigning a new value to an existing variable means replacing the original value by a copy of the new value. a = b; a 75 b 75 A comparison is done by comparing the bits of the copied values. a == b; 7 Whole Numbers Primitive types for whole numbers are byte (8 bits), short (16 bits), int (32 bits), long (64 bits) Literals can be expressed in decimal, hexadecimal or octal digits. Octals start with '0', hexadecimals with '0X' or '0x'. A whole number is of type int unless the suffix 'L' or 'l' for long is added. int (decimal) int (octal) int (hexadecimal) long (decimal) long (octal) long (hexadecimal) 0 2 0372 0xDada 1l 0777L 0XC0B0L 8 4

Operations on Whole Numbers Comparison: ==,!=, <, >, <=, >= Unary: +, - Multiplication, etc: *, /, % Addition, etc.: +, - Increment and decrement: ++, -- (Side effects!) Shifts: <<, >>, >>> Complement: ~ Bitwise operations: &,, ^ 9 Scope of Whole Number Values byte short int long -128 to 128-32768 to 32767-2147483648 to 2147483647-9223372036854775808 to 9223372036854775808 10 5

Exceptions on Whole Numbers Neither overflow nor underflow is tested for whole numbers. 0 as second operand of / or % throws an ArithmeticException. int i = 1000000; System.out.println(i*i); long l = i; System.out.println(l*l); System.out.println(20296/(l-i)); -727379968 1000000000000 Exception 11 Floating-Point Numbers Primitive types for floating-point numbers are float (32 bits) and double (64 bits) A floating-point literal has the following components: a whole-numbered part, at least one digit, a decimal point, a decimal part, at least one digit, an exponent, starting with the letter 'E' or 'e' a type identification, i.e. the letter 'F' or 'f' for float or 'D' or 'd' for double. At least one of these! float double 2.f.3F 0f 7.38473e+18f 2..3d 1e2 0.0 12 6

Order on Floating-Point Numbers Floating-point numbers include special values: POSITIVE_INFINITY, NEGATIVE_INFINITY 0.0, -0.0 NaN (Not-a-Number) Infinity-values instead of overflow NaN is the result of invalid operations. 0.0 == -0.0 true 0.0 > -0.0 false Math.max(0.0, -0.0) 0.0 Double.NaN == 5.6 false Double.NaN < 3.1415 false Double.NaN!= 9347.234 true 13 Operations on Floating-Point Numbers Comparison: ==,!=, <, >, <=, >= Unary: +, - Multiplication, etc: *, /, % Addition, etc.: +, - Increment and decrement: ++, -- (Side effects!) 14 7

Unicode Characters The primitive types for characters is char (16 bits Unicode) A literal is formed by a single character or escape character included in single quotes. Escape characters are used for characters that cannot represented in any other way: \ b /* backspace */ \ t /* horizontal tab */ \ n /* line feed */ \ f /* form feed */ \ r /* carriage retrun */ \ " /* double quote " */ \ ' /* simple quote' */ \ \ /* backslash\ */ valid char-literals no valid char-literals ' ' ' \' ' 'a' '\uffff' '2' 'Ω' ' ' ' ' \ ' 'abc' 15 Operations on Characters Comparison: ==,!=, <, >, <=, >= Unary: +, - Multiplication, etc: *, /, % Addition, etc.: +, - Increment and decrement: ++, -- (Side effects!) Shifts: <<, >>, >>> Complement: ~ Bitwise operations: &,, ^ Careful! chars are often converted to ints! 16 8

Booleans The primitive type used to express that something can have exactly two different states is called boolean. The two literals are true and false. Operations on booleans: Comparison: ==,!= Negation:! binary logic: &,, ^ short-circuit-evaluation logic: &&, 17 Short-Circuit-Evaluation The evaluation of a short-circuit-expression is a partial evaluation from left to right. As soon as it can be reassured, that the result has a certain value, the evaluation is stopped. Quite useful in some situations. If x == 0, the result is false If x == 0, division by zero!! x!=0 && 1000/x > 100 x!=0 & 1000/x > 100 18 9

Ternary if-else int a,b;... b = a >= 0? a : -a; Does the same as int a,b;... if (a >= 0) b = a; else b = -a; A ternary if-else always results in a value Can also be used for side-effects Shouldn't be used too often for the sake of readable code 19 Controlling Program Flow Variable declaration and assignment Using operations on primitive data types Iteration Conditionals 20 10

Statements There are two general kinds of statement simple statements compound statements Simple statements end with a semicolon. Compound statements encompass several statements and are enclosed in brackets. Compound statements are also called blocks. Blocks are important for scoping. 21 Variables Variables have to be declared before they are used. int a; They can be assigned changing values according to their declared type. a = 3 a= 5 + 2; a = "Oh no!"; Declaration and assignment can be done within a single statement. int b = 8; Some operations involve implicit assignments b = ++a; a 6 b 6 Variables that are used but not initialized cause compile-time errors. 22 11

Scoping { /* <-- Beginning of scope 1 */ int x = 12; /* Only x available */ { /* <-- Beginning of scope 2 */ int q = 96; /* Cannot redefine x here! */ /* Both x & q available */ } /* <-- End of scope 2 */ /* Only x available */ /* q out of scope */ } /* <-- End of scope 1 */ 23 if-else int a;... if (a >= 0) System.out.println("Already positive"); else { a = -a; System.out.println("Turned positive"); } The statements can either be simple (terminated by semicolon) or compound in braces. else is optional 24 12

switch char c;... switch(c) { case 'a': case 'o': case 'u': } case 'e': case 'i': default: System.out.println("dark vowel"); break; System.out.println("bright vowel"); break; System.out.println("no vowel"); 25 What does switch do? Tests all case-conditions and executes the statement behind the colon, if the condition is true. If a condition is true and the attached statement is followed by a break, switch is finished. If no match occurs, the default-statement is executed. switch only works on integral values like int or char. 26 13

for int [] a =...; int sum = 0; for (int i = 0; i < 10; i++) { sum = sum + a[i]; } performs intialization before first iteration, conditional testing at the beginning of each iteration and some form of stepping at the end of each iteration all three parts are optional 27 while int i = 0; while (i < 10) { System.out.println(i); ++i; } Tests a condition and executes the loop-statements as long as the condition is true. 28 14

do-while int i = 0; do { System.out.println(i); ++i;} while (i < 10) Executes the loop-statements until the condition is false. Mind the difference with while: The statements are at least executed once here, even if the condition is never true. 29 15