CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

Similar documents
Introduction to Programming Using Java (98-388)

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010

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

VARIABLES AND TYPES CITS1001

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

PROGRAMMING FUNDAMENTALS

Introduction to Java

Pace University. Fundamental Concepts of CS121 1

3. Java - Language Constructs I

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

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

Getting started with Java

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

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

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Fall 2017 CISC124 9/16/2017

2 rd class Department of Programming. OOP with Java Programming

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

An overview of Java, Data types and variables

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

9 Working with the Java Class Library

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

CHAPTER 7 OBJECTS AND CLASSES

1 Shyam sir JAVA Notes

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

Programming Language Basics

Lecture 1: Object Oriented Programming. Muhammad Hafeez Javed

CMPT 125: Lecture 3 Data and Expressions

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

CS 11 java track: lecture 1

Introduction to Java

CE221 Programming in C++ Part 1 Introduction

BM214E Object Oriented Programming Lecture 8

JAVA GUI PROGRAMMING REVISION TOUR III

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

Getting started with Java

CS 231 Data Structures and Algorithms, Fall 2016

Basics of Java Programming

Identifiers and Variables

Computational Expression

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

Building Java Programs

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

THE CONCEPT OF OBJECT

Operators and Expressions

Fundamentals of Programming Data Types & Methods

Lecture 1: Overview of Java

Selected Java Topics

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

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lecture Set 4: More About Methods and More About Operators

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

Building Java Programs

Array. Prepared By - Rifat Shahriyar

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Lecture 06: Classes and Objects

CS11 Java. Fall Lecture 1

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

Program Fundamentals

CS162: Introduction to Computer Science II

Java Basic Datatypees

CS 112 Introduction to Programming

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

ECE 122. Engineering Problem Solving with Java

What is Inheritance?

CHAPTER 7 OBJECTS AND CLASSES

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Programming. Syntax and Semantics

Answer1. Features of Java

CS121/IS223. Object Reference Variables. Dr Olly Gotel

CS162: Introduction to Computer Science II. Primitive Types. Primitive types. Operations on primitive types. Limitations

Java Basic Programming Constructs

Introduction to Programming (Java) 4/12

Programming Language Concepts: Lecture 2

CLASSES AND OBJECTS. Fundamentals of Computer Science I

COE318 Lecture Notes Week 6 (Oct 10, 2011)

CS111: PROGRAMMING LANGUAGE II

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types

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

CLASSES AND OBJECTS. Fundamentals of Computer Science I

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

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

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

Computer Science II (20082) Week 1: Review and Inheritance

CSC Java Programming, Fall Java Data Types and Control Constructs

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture Set 4: More About Methods and More About Operators

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 (Java) 2/12

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

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

AP Computer Science A

1993: renamed "Java"; use in a browser instead of a microwave : Sun sues Microsoft multiple times over Java

Chapter 6 Classes and Objects

CS Week 2. Jim Williams, PhD

3. Java - Language Constructs I

Transcription:

CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Programming in JAVA II (A Whirlwind Tour of Java) Course Lecture Slides 17 May 2010 Ganesh Viswanathan

JAVA Java 1.0 was first released by Sun Microsystems in 1995. Duke, the JAVA mascot Java became popular for web programming. "Write Once, Run Anywhere" (WORA) philosophy. Key design principles: - Platform independence - Security - Stability

How Java works!

Programming in JAVA I Basic concepts in Java Values Variables Complex data/objects Methods Expressions Conditionals Loops

Programming in JAVA English to JAVA translation: Piece of data: value Kind of data: type Place to store a value: variable Structured group of variables: object Kind of object: class Object of a particular class: class instance Variable belonging to an object: instance variable

Programming in JAVA Values and Types: All data values in Java have a type The type of a value determines: Allowed operations Memory representation Allowed operations Conversion to other types Allowed operations Types are program invariants Help to catch errors Default initial values (if omitted) are based on type

Programming in JAVA Primitive Types: EIGHT basic pre-defined types: values on which Java can operate directly. byte, short, int, long, float, double, boolean, char Plus, special support for character strings - using java.lang.string class

Programming in JAVA - II Numeric Types in Java are characterized by their size (how much memory they occupy) Integral types Floating point types Size Range (inclusive) byte 1 byte -128: 127 short 2 bytes -32,768: 32,767 char 2 bytes 0: 65,535 int 4 bytes -2 31 : 2 31-1 long 8 bytes -2 63 : 2 63-1 float 4 bytes 2-149 : (2-2 -23 ) 2 127 double 8 bytes 2-1074 : (2-2 -52 ) 2 1023

Strings Built-in non-primitive type String String s1 = my string ; Strings are sequence of characters UF Pugh Hall string literals + means concatenation Pugh + + Hall => Pugh Hall Automatic conversion of numbers to strings Go + 2 + UF => Go2UF Text in a String is immutable

Variables Variables store values myscore = 100; israining = true; monthlysalary = 1656.89; PI = 3.141592653589793; myname = Buzz Aldrin ; All variables must be declared!

Variables Assignment statement = int myscore = 100; boolean israining = true; float monthlysalary = 1656.89; double PI = 3.141592653589793; String myname = Buzz Aldrin ; Variables must store values of the correct type myscore = true; israining = 1; Prevent nonsensical calculations

Initializing Variables Preferred usage: Combine declaration and value initialization in one step: String mycar = Mustang ; Boolean israining = true; Default initial values (unless specified) are based on type.

Default type values Default initial values (unless explicitly specified) are based on type. Type byte 0 short 0 int 0 long Default value 0L float 0.0f double 0.0d char String (or any Object) boolean '\u0000' null false

Methods A set of instructions referenced by a name that can be called whenever required public class Report{ public static void main(string args[]){ printhelloworld(); } } //simple print method public static void printhelloworld(){ System.out.println( Hello World! ); } http://java.sun.com/docs/books/tutorial/java/javaoo/methods.html

Demystifying the main( ) method public static void main (String args[ ]) The keyword public indicates that the method can be called by any object. The keyword static indicates that the method is a class method, which can be called without the requirement to instantiate an object of the class. The keyword void indicates that the method doesn't return any value. The boss function! : When you execute a class with the Java interpreter, the runtime system starts by calling the class's main() method. The main() method then calls all the other methods required to run your application. String args[] - an array of strings : Mechanism through which the runtime system passes command line arguments to your application.

Parameters vs Arguments Parameters specify data that must be provided in an invocation public getname (String ufid, int year) { searchufid = ufid; searchyear=year; } Arguments are the actual values supplied to a method String name = getname ( 1234-5678, 2010);

Naming Conventions Kind Identifier Class GradeBook Variable initialgrade Constant MAXIMUM_GRADE Method getstudentgrade

Java Expressions Compute values of different types Boolean values: 10>5 Numeric values: 2+3, 5%2 String values: Pugh + Hall Object values: new GradeBook();

Control Flow Statements Use a condition to choose which action to take. If, Else If, Else (Multi-way decisions, Nested decisions) Switch-case While, Do-While For http://java.sun.com/docs/books/tutorial /java/nutsandbolts/flow.html

Control Flow Statements If, Else-If, Else (Multi-way decisions, Nested decisions) public String transport() { if (isfrigid()) return "skis"; else if (istropical()) return "surfboard"; else return "bicycle"; } public String dominant() { String animal; if (isfrigid()) { } else if (latitude > 0) animal = "polar bear"; else animal = "penguin"; animal = cat"; } return animal;

Get more info! (Online) Search keywords: Java data types Java basics Floating point numbers Java Class methods vs Instance methods Java statements