TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

Similar documents
Getting started with Java

CS 106 Introduction to Computer Science I

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

CMPT 125: Lecture 3 Data and Expressions

Java Basic Datatypees

A variable is a name for a location in memory A variable must be declared

Lecture 3: Variables and assignment

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Strings, Strings and characters, String class methods. JAVA Standard Edition

Variables, Constants, and Data Types

Section 2.2 Your First Program in Java: Printing a Line of Text

Chapter 2: Data and Expressions

CS11 Java. Fall Lecture 1

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

We now start exploring some key elements of the Java programming language and ways of performing I/O

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

Full file at

6.096 Introduction to C++ January (IAP) 2009

Lecture 2 Tao Wang 1

Basics of Java Programming

Lecture Set 2: Starting Java

Course Outline. Introduction to java

Table of Contents Date(s) Title/Topic Page #s. Abstraction

Lecture Set 2: Starting Java

First Java Program - Output to the Screen

Section 2.2 Your First Program in Java: Printing a Line of Text

Chapter 2: Programming Concepts

Chapter. Let's explore some other fundamental programming concepts

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Chapter 2: Data and Expressions

4 Programming Fundamentals. Introduction to Programming 1 1

B.V. Patel Institute of BMC & IT, UTU 2014

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Fundamentals of Programming. By Budditha Hettige

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

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Week 2: Data and Output

An overview of Java, Data types and variables

Software Practice 1 Basic Grammar

What did we talk about last time? Examples switch statements

2 rd class Department of Programming. OOP with Java Programming

Program Fundamentals

Chapter 2: Data and Expressions

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

CS111: PROGRAMMING LANGUAGE II

Introduction to Java Applications

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

COMP 202 Java in one week

2: Basics of Java Programming

Chapter 6 Primitive types

COMP String and Console I/O. Yi Hong May 18, 2015

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections

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

CSc Introduction to Computing

Chapter 2 Elementary Programming

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

McGill University School of Computer Science COMP-202A Introduction to Computing 1

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

Section 2: Introduction to Java. Historical note

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

Darrell Bethea May 25, 2011

Java Identifiers, Data Types & Variables

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Full file at

1007 Imperative Programming Part II

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

JAVA Programming Concepts

CSE20 : Lab #4 - Data Types

Programming with Java

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Object Oriented Programming. Java-Lecture 1

Zheng-Liang Lu Java Programming 45 / 79

CSEN 202 Introduction to Computer Programming

Program Elements -- Introduction

Object-Oriented Programming

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

Language Reference Manual

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

Introduction to Java Unit 1. Using BlueJ to Write Programs

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

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

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Introduction to Java Applications; Input/Output and Operators

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Operators in java Operator operands.

Transcription:

1 INSTRUCTOR: FAZLI CAN TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN Week 12/02/2007-16/02/2007 Lecture Notes: When we write a program we must design our programs to take correct output. For correct output, we use PSEUDO CODE. Although pseudo code similar to programming code, this code is not a real code. Purpose of the pseudo code is to create a map to be understandable. For example; a = x / 5 = +6 we learn that from this equitation x > 0 1. read x If end ıf. else x > 0 then a = x a = -x And print if absolute value of x is equal to a ABSRACTION: It means that make it easy. With abstraction, you can hide details, you show that what is done, how it is done. For example; 1. Read X 2. Assign absolute value of x to a 1

2 3. print a SEQUENCE ITERATION >>>> TYPES OF PROGRAMMING<<<<< SELECTION EX1 : Find summation of numbers 0 to n? 1. Begin 2. Read n 3. sum = 0 i = 0 ---------------------------------------- ----------- ---------------------------------------------------- ----------- TRUE ------------------------ --------------- i <= 0 sum = sum + i ------- i = i + 1 ------- ------------------------ ---------------- ----------------------------------------------------------- --- FALSE Sum STOP In programming we have int i, n, sum 2

3 If we write for PSEUDO code: 1. Read n 2. sum = 0 3. i = 0 4. if ( i < = n) then 5. sum = sum + i i = i + 1 End if Print sum Stop NOTE: we do not write our programs with GO TO because we have FOR instead of GO TO With ABSTRACTION: 1. read n 2. sum = 0 3. i = 0 4. while ( I < = 0 ) sum = sum + i i = i + 1 end while 5. print sum 3

TYPES OF PROGARMMING (programming paradigms) 4 Procedural Programming Sequence Selection(e.g if statement) Iteration(e.g for, while statement Object-Oriented Programming Encapsulation Polymorphism Inheritance JAVA PROGRAM STRUCTURE In a class definitio we have two key components: I. Variables II. Methods And all of these components are encapsulated in the class. A simple example of Java program 4

5 // This line and the following three lines are comments // Example program // **************************************************** Comment lines The name of the library public class Example { public static void main(string[] args) { System.out.print ("Hello"); System.out.println("world"); System.out.println(); System.out.println("Good bye!"); } // end of main() Method Parameter(argument you pass to the method print) } OUTPUT Hello world (blank line) Good bye! Be sure that you use meaningful names while creating your own variables! And be careful for the indentation! Identifiers 5

6 These are the words defined by using a railroad diagram. I. public, static,void...(reserved WORDS) (You can not use these words as variables) II. PROGRAMMER DEFINED IDENTIFIERS Class name Method name Variable name How can we construct our own identifiers? Java letters : all letters (a z, A Z) _ under score $ dolar sign Java digits(0 9) Java letter Java letter Java digit System.out.println( He is + 16 + years old. ); constant 6

7 or similarly... Concatenation int age =16; System.out.prinln( He is + age + years old. ); When we say, System.out.println( He is + 16+1 + years old. ); OUTPUT He is 161 years old. When we say, System.out.println( He is + (16+1) + years old. ); OUTPUT He is 17 years old. Escape Sequences: \b : backspare \t: tab \n: newline \r: carriage return \ :double quote \ :single quote \\ :backslash If you write code in java : System.out.println( He said \ Please see me later.\ and didn\ t stop ); Output: He said Please see me later and didn t stop. 7

8 System.out.println ( He said ); System.out.println( Hello ); OR System.out println( He said \n Hello ); Output: He said Hello Variable Declaration: TYPES VARIABLE DECLARATION, Variable Declarator: IDENTIFIER = EXPRESSION TYPE: 8

9 byte short int long ***: final int KDV _RATE =18; If you write final in your code in java then you can not change it!!! Primitive Data Types: byte: 8 bits short:16 bits int: 32 bits long: 64 bits 1,2,3 are : int 1.0 float point 1 string 12 1 char 12 byte a ; 8 bits: xxxx xxxx 0000 0101 9

10 ASCII: AMERICAN STANDART CODE FOR INFORMATION INTERCHANCE 8 bits: 10

11 Questions: 1. What is pseudo code? Why we need pseudo code in our programs? 2. What is abstraction? 3. Write a program which gives an output if result is negative. Write this program with pseudo code and abstraction. 4. What are the difference between procedural programming and object oriented programming? 5. What is the aim for writing comments while we are writing programs? 6. Explain the difference between print and println methods? 7. What does concatenation mean? 8. What is the difference between println and print in java?write outputs of following codes with using print method?? a. System.out.println( Welcome To Java World! ); b. System.out.println( It s First Step to be a Computer Enginer ); 9. How Variable Declarator behave if you put final at the beginning of your variable? 10. What is ASCII why it is needed to do a table?? Write Decimal 39, 43, 126 in Hexa decimal by looking table?? 11