Agenda Types and identifiers Practice Assignment Keywords in Java

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
The Java Programming Language
Review… Yong Choi BPA CSUB. Access Modifier public class HelloWorldApp –More detailes of Java key (reserved) wordJava key (reserved) word –The keyword,
Outline Java program structure Basic program elements
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
JAVA PROGRAMMING PART II.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Java: Chapter 1 Computer Systems Computer Programming II.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
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.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
1 Primitive data types, expressions, and variables.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
C++ Lesson 1.
Key Words / Reserved Words
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Chapter 4 Assignment Statement
Lecture 2: Data Types, Variables, Operators, and Expressions
CSE 190D, Winter 2013 Building Java Programs Chapter 1
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Variables and Arithmetic Operators in JavaScript
University of Central Florida COP 3330 Object Oriented Programming
Chapter 3 Assignment Statement
Type Conversion, Constants, and the String Object
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
An overview of Java, Data types and variables
Instructor: Alexander Stoytchev
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
Instructor: Alexander Stoytchev
CISC124 TA names and s have been added to the course web site.
Focus of the Course Object-Oriented Software Development
Module 2 - Part 1 Variables, Assignment, and Data Types
CSE 142, Spring 2012 Building Java Programs Chapter 1
Instructor: Alexander Stoytchev
Zorah Fung University of Washington, Spring 2015
Chap 2. Identifiers, Keywords, and Types
CSE 142, Winter 2014 Building Java Programs Chapter 1
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

Agenda Types and identifiers Practice Assignment Keywords in Java Type casting Homework

declaration The first time a variable is introduced in a program. Java is strongly typed. Initialization: a variable get assigned a value. A variable if often initialized in its declaration, but doesn’t have to be. Java demands all variables to be declared before they can be used. Two parts: <type> <name> Example: int intNum; intNum=7; Int intNum=7;

Assignment The value of a variable is changed through assignment: int x; x=10; x=15; 10 15

keywords abstract double int strictfp boolean else interface super break extends long switch byte final native synchronized case finally new this catch float package throw char for private throws class goto protected transient const if public try continue implements return void Default import short volatile do instanceof static while

Types Every identifier has a type Primitive(built-in) types: int – integer boolean – true or false double – floating-point numbers char – character http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Type Casting Type casting converts a number of one type to a number of a different, but compatible type. int intNumber= 35; double doubleNumber = 3.9; double doubleValue=intNumber; //OK int intValue = doubleNumber; //Wrong int intValue = (int)doubleNumber; Test this on Eclipse

Example int intNum=5; double doubleNum=3.98; doubleNum = intNum; System.out.println("doubleNum: " + doubleNum); intNum =(int) doubleNum; System.out.println("intNum: " + intNum); double average; average=(double)(10/3); System.out.println("average: " + average);

AP type questions Which of the following pairs of declarations will cause an error message? I. double x = 14.7; int y = x; II double x = 14.7; int y = (int) x; III int x = 14; double y = x;

double answer = 13/5; System. out. println(“13/5 = “ + answer); //2 double answer = 13/5; System.out.println(“13/5 = “ + answer); //2.0 The programmer intends the output to be 13 / 5 = 2.6; HOW???

Concatenation A System.out.println() statement can be used to output the value of a variable. Variable identifiers are not enclosed by quotation marks. To append, or concatenate, the value of a variable to a string, the + operator is used. The + operator converts the value of the variable to a string and then concatenates the strings before output.

Homework 1 Create a Smile application that displays a smiling face made of keyboard characters. The application output should look similar to: ***** * * * _ _ * * 0 0 * * : * * \ _ / * * * ******

Homework 2 Create a RectanglePerimeter application that calculates and displays the perimeter of a rectangle with width 4 and length 13. The perimeter of a rectangle is calculated as 2w + 2l. Use variables as appropriate and output the perimeter using println.