George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Written by: Dr. JJ Shepherd
George Blank University Lecturer.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Chapter 10 Introduction to Arrays
Road Map Introduction to object oriented programming. Classes
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
March 2005Java Programming1. March 2005Java Programming2 Why Java? Platform independence Object Oriented design Run-time checks (fewer bugs) Exception.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
OOP Languages: Java vs C++
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
May 9, 2002Serguei A. Mokhov, 1 Kickstart Intro to Java Part I COMP346/ Operating Systems Revision 1.6 February 9, 2004.
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.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
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.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Programming in Java CSCI-2220 Object Oriented Programming.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 6 Objects and Classes.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
JAVA INTRODUCTION. What is Java? 1. Java is a Pure Object – Oriented language 2. Java is developing by existing languages like C and C++. How Java Differs.
Written by: Dr. JJ Shepherd
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Object Oriented Programming Lecture 2: BallWorld.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Topic: Classes and Objects
Objects as a programming concept
JAVA MULTIPLE CHOICE QUESTION.
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Chapter 3: Using Methods, Classes, and Objects
Programming Language Concepts (CIS 635)
Programmazione I a.a. 2017/2018.
Object Based Programming
Chapter 3 Introduction to Classes, Objects Methods and Strings
Java Programming Language
Object Oriented Programming
Units with – James tedder
Units with – James tedder
Object Oriented Programming in java
Chap 2. Identifiers, Keywords, and Types
Review for Midterm 3.
Presentation transcript:

George Blank University Lecturer

CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4

Elements of Java This chapter is a catalog of the Java language. It contains a lot of information in a highly compressed format. Some students may wish to use another supplementary Java textbook that has a lot of exercises to practice different features of the language instead of having so many at once. There are lots of such texts in bookstores.

Java Uniqueness Purely object-oriented—no compromises! Primitive types are not objects No multiple inheritance (simulate with interfaces) No GOTO statement 16 bit international characters only (Unicode) Exception handling Automatic memory management (garbage collection) Multithreaded programming.

Standardization In many computer languages, there are differences between implementations of the language on different platforms or with different compilers. For example, C long integers might have different maximum and minimum values. It is a strength of Java that everything is standardized on all platforms.

Variables and Types A variable is a location in memory where values can be stored and referenced. Variables are associated with types, which have particular data sizes and a restricted set of valid operations that can be performed on them. Variable declarations assign an identifier, a type, and may declare an initial value. Many types have a default value. For example, an uninitialized integer defaults to 0.

Variable (a memory location) address a value (a default value) a name a type The address or value may be passed as a parameter

Constructors A constructor is a special form of method that has only one purpose—to create an instance of a class. This is different from other methods, which add behavior to a class. It is good Java practice to supply a no-arguments constructor in addition to any that take parameters to allow the Java Virtual Machine to create instances of the class dynamically at run time. The text shows two constructors for Point (next slide).

Point example (text, p. 104) public class Point { public double x, y; public Point() { //no-arg constructor x = 0.0; y = 0.0; } public Point(double init_x, double init_y) { x = init_x; y = init_y; } … } Here, the no-arg constructor supplies default values for the point location.

Singleton Classes Classes that are not supposed to have more than one instance at a time, such as a top- level window or a system timer, can be limited as a singleton class, an instance of the Singleton design pattern that will be discussed in a future lecture. The following slide shows a singleton class.

Singleton Class Note the private static constructor that prevents multiple instances.

Reference Types References to classes, interfaces and arrays are implemented in Java as 32 bit pointers and are called reference types. While C and C++ pointers can be cast to other types, that is forbidden in Java. No direct manipulation of reference types is permitted. This reduces errors and increases security.

Variable Scope Local variables are only valid within the block in which they are declared. Blocks in Java open with { and close with } and can have other blocks embedded in them. Local variables are not automatically initialized. Variable declarations must be terminated with a ;

Flow Control return ends a method and returns control to the caller if and else are used for selection while, do-while and for are used for loops break and continue expand flow control

Class Declarations Class declarations define classes, which can be instantiated as objects and are assigned to a reference type. A class declaration includes a class name and fields, methods, and nested class declarations. The fields are known as the variables or attributes of a class.

Class and Method Modifiers –Field is accessible by all others within a package public –Field is accessible by any class private –Field is accessible only by itself static –Field is shared by all instances of a class abstract –Class contains only abstract methods, method defers implementation to subclasses final –Field may not be extended with subclasses A field may be a class or method.

Specialized Method Modifiers synchronized – an atomic thread in a multithread environment native –implemented in C and C++

main Method Every program must have a main method, declared as public static void main(String [] args) { … } The array of String arguments allows initialization values to be passed to the class at start up time. Only one class in the program requires a main method.

Print Command args (NetBeans)

Things to understand Here are some of the features of Java that students have had trouble with in the past, with page numbers from the text: String concatenation p. 84 Assignment p. 87 Casts p. 89 Initialization p. 91

More things to understand Multidimensional arrays p. 93 Expressions for object creation p. 94 Local variables and scope p. 95 The return statement p. 95 Break and continue p. 99 Class and method modifiers pp Accessibility p. 103

More things to understand Constructors p. 104 Accessors p. 106 Parameter Passing pp Class fields pp Singletons p. 114 This pp Interfaces pp

More things to understand String methods p. 119 Standard input, output and error pp. 123ff Wrappers pp Packages pp Exceptions pp The chapter summary contains many references to key concepts.

Code Examples from text Note: All the code that follows contains the following header which has been removed to fit on the screen: /* * Copyright (c) , Xiaoping Jia. * All Rights Reserved. */ Respect the author’s copyright!

Break Records

Bubble Sort

Copy

Copy Text File

Digital Clock page 1

Digital Clock page 2

MaxMin

Maximum (with try-catch)

String Compare An Interned String is a copy of a String that has the same content but is a different String.

Word: String Tokenizer

String Handling Understand the difference between the immutable String class and the mutable StringBuffer class. Strings have special privileges not shared by ordinary classes including the creation of string literals and the use of concatenation operators.

Garbage collection Garbage collection, especially remote garbage collection, is a big deal in Java. See the explanation on page 90. One reason that garbage collection is so important is that C does not have it, and a substantial number of problems in Microsoft Windows come from the failure to free resources no longer in use.

Bibliography Jia, Xiaoping, Object Oriented Software Development Using Java. Addison Wesley, 2003