CSC Java Programming, Fall Java Data Types and Control Constructs

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

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

F1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept

JAVA WRAPPER CLASSES

Index COPYRIGHTED MATERIAL

Chapter 2: Using Data

Introduction to Java

CS313D: ADVANCED PROGRAMMING LANGUAGE

CSC 1214: Object-Oriented Programming

Getting started with Java

1 Shyam sir JAVA Notes

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Computational Expression

CS313D: ADVANCED PROGRAMMING LANGUAGE

PROGRAMMING FUNDAMENTALS

(2½ hours) Total Marks: 75

Points To Remember for SCJP

PIC 20A Number, Autoboxing, and Unboxing

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

ECE 122. Engineering Problem Solving with Java

CST141 Thinking in Objects Page 1

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

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

Types, Values and Variables (Chapter 4, JLS)

Instructor: SIR MUHAMMAD NAVEED Created by: ARSLAN AHMED SHAAD ( ) MUHAMMAD BILAL ( ) ISIT:

CS 251 Intermediate Programming Methods and Classes

Java Basic Programming Constructs

Practice exam for CMSC131-04, Fall 2017

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

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003

Language Features. 1. The primitive types int, double, and boolean are part of the AP

15CS45 : OBJECT ORIENTED CONCEPTS

Basics of Java: Expressions & Statements. Nathaniel Osgood CMPT 858 February 15, 2011

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

CSE 431S Type Checking. Washington University Spring 2013

JAVA REVIEW cs2420 Introduction to Algorithms and Data Structures Spring 2015

CISC 323 (Week 9) Design of a Weather Program & Java File I/O

Declarations and Access Control SCJP tips

Chapter 7: Arrays CS 121. April 9, Department of Computer Science College of Engineering Boise State University. Chapter 7: Arrays CS / 41

Brief Summary of Java

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

Full file at

Java Primer 1: Types, Classes and Operators

3.1 Class Declaration

CS 61B Data Structures and Programming Methodology. June David Sun

3. Java - Language Constructs I

Type Conversion. and. Statements

CSC207H: Software Design. Java + OOP. CSC207 Winter 2018

Flow Control. CSC215 Lecture

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Object-Oriented Programming

Java Overview An introduction to the Java Programming Language

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

CS 251 Intermediate Programming Methods and More

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

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

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

An overview of Java, Data types and variables

Selected Questions from by Nageshwara Rao

Java Programming. Atul Prakash

5/23/2015. Core Java Syllabus. VikRam ShaRma

JVM (java) compiler. A Java program is either a library of static methods (functions) or a data type definition

Java Notes. J Pickering Department of Computer Science The University of York Heslington York YO10 5DD UK

Selected Java Topics

Operators and Expressions

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Chapter 2: Using Data

CS 2340 Objects and Design - Scala

Casting. References. References

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

Java 1.8 Programming

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

ESc101 : Fundamental of Computing

Java Identifiers, Data Types & Variables

CS162: Introduction to Computer Science II

From C++ to Java. Duke CPS

Java Programming with Eclipse

CompSci 125 Lecture 11

Java: framework overview and in-the-small features

COMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions

Ticket Machine Project(s)

Program Fundamentals

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals

Programming II (CS300)

TOPICS TO COVER:-- Array declaration and use.

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Short Notes of CS201

Java Programming Lecture 10

Do not turn to the next page until the start of the exam.

1.3b Type Conversion

[TAP:AXETF] Inheritance

H212 Introduction to Software Systems Honors

CS201 - Introduction to Programming Glossary By

Pace University. Fundamental Concepts of CS121 1

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Static Imports, Default Values, Number Types and More!

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

Java Basic Datatypees

Client-Side Web Technologies. JavaScript Part I

Transcription:

CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs

Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

Java Built-in Types byte 8-bit signed short 16-bit signed int 32-bit signed long 64-bit signed float 32-bit double 64-bit boolean true or false char Unicode character String a built-in class representing a sequence of characters

Java Object/Reference Types Object types are accessed via a reference Object a = new Object (); Object b = a; The assignment operator copies the reference

Java Object Construction The constructor has the same name as the class Any method, including the constructor, can be overloaded The new operator creates a new instantiation of an object using an object constructor and returns a reference to that object

Wrapper Classes Wrapper classes provide a mechanism to convert between primitive and object types Wrapper class list: Primitive Type boolean char byte short int long float double Wrapper Class Boolean Character Byte Short Integer Long Float Double

Conversion Examples Convert int into Integer int x = 1; Integer i = Integer. valueof ( x); Integer j = x; Convert Integer into int Integer x = new Integer ( 1); int i = x. intvalue (); int j = x;

Wrapper classes and String Wrapper classes can also be used to convert String types to Primitive types: String s = "3"; int i = Integer. parseint (s);

Basic Exception Handling Integer.parseInt signature: public static int parseint ( String s) throws NumberFormatException Handle the exception: try { String s = "3"; int i = Integer. parseint (s); } catch ( NumberFormatException e) { // code to handle the exception }

Java Control Flow Constructs The basis for control flow is the boolean type for, while, and do while loops if and else selection switch statements break exits the inner-most loop or switch continue jumps to the next iteration of the loop

Logical operators and: && or: not:! Comparison operators equal: == not equal:!= less than: < less than or equal: <= greater than: > greater than or equal: >= Boolean Operators

Object Comparison == compares the references returns true if both operands refer to the same object object.equals() compares objects using an class defined method String s1 = new String ("S"); String s2 = s1; s1 == s2; // true s1. equals (s2 ); // true s1 = new String ("S"); s1 == s2; // false s1. equals (s2 ); // true

Java Static Methods A method is a function associated with an object A static method does not require an object instance int x = java. lang. Integer. parseint ("3"); System. out. println ("x: " + x); An instance method requires an object reference Integer x = new Integer ( 3); System. out. println ("x: " + x. intvalue ());

Java Static and Non-static Data Fields Only one copy of a static data field exists Both static and instance methods can use a static data field For a non-static data field, there is one copy for each instantiated object Only a non-static method can use a non-static data field

Java Access Modifiers public methods and data can be used by any code that imports the class protected methods and data can be used only by the defining class and derived classes private methods and data can be used by the defining class imports the class If there is no explicit access restriction, then the methods and data can be used by any class in the same package

Java Arrays Arrays are constructed using the new operator Arrays are initialized based on type: numeric types (int, float, etc.) are initialized to zero booleans are initializede to false chars are initialized to \0000 objects are initialized to null Examples: float [] numbers = new float [ 10]; int [] counts = {1, 2, 3}; Object [] objects = new Object [ 20];

Basic Java Array Usage Access an element with the [] operator; if the index is outside of the array, a ArrayIndexOutOfBoundsException is thrown The length property contains the size of the array Looping over arrays: int [] numbers = {1, 2, 3}; // for loop for ( int i = 0; i < numbers. length ; i ++) { System. out. println (i); } // foreach loop for ( int element : numbers ) { System. out. println ( element ); }