READ-ONLY OBJECT IN OBJECT-ORIENTED PROGRAMMING

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "READ-ONLY OBJECT IN OBJECT-ORIENTED PROGRAMMING"

Transcription

1 READ-ONLY OBJECT IN OBJECT-ORIENTED PROGRAMMING Hong Zhou, PhD University of Saint Joseph, West Hartford, CT, USA Abstract Object-oriented programming (OOP) has become the dominant programming paradigm by its promise of easy code maintenance, code reuse, and code evolution. The central dogma in OOP is to model a concept as an object that has its own internal state and behavior. How to limit the access to the internal state of an object is always a tricky question to new OOP programmers. Though OOP languages have various ways of limiting the access to an object s internal state, a call for read-only objects emerges as the protection of data authenticity in information flow becomes more and more critical. Since the existing approaches to achieve read-only concept in programming languages cannot dynamically create read-only objects, this article presents the definition of the keyword readonly and demonstrates how to use it to dynamically generate read-only objects via two case studies. Keywords: Read only, OOP, object, Java Introduction There are primarily two types of programming paradigms: procedural (or structural) and object-oriented. The early programming method is procedural, which means that a program is made of multiple procedures. A procedure can operate on data, but does not store data. Such separation of procedure/code from data causes serious reuse and maintenance problems in cases when the data is changed or the data format is altered. Object-oriented programming (OOP) centers on object creation. An object is a software entity that has its own procedures (which are also called methods or functions) and data, and depending on the data, such an entity has its state. OOP has multiple avenues of advantages over the procedural programming. That is why OOP has become the dominant programming paradigm today. In OOP, a concept is modelled as an object, and therefore each object is designed to accomplish one or more specific tasks or functions. Once an object is created successfully, it can be reused as a 41

2 functional component. This significantly enhances the code reusability in software development. Another advantage of OOP is the inheritance. Through inheritance, a new object can be constructed from an existing object, while this new object can possess all the functions and properties of the existing object. This feature makes the code evolution possible and easy to achieve. Since both the methods and data are stored together in an object, data hiding, i.e., protecting the data of an object, becomes a critical practice in OOP. Data hiding refers to the ability of an object to hide its internal data from being accessed by outside objects. This is usually achieved by defining the internal data of a specific object to be private, thus only the methods inside the object can access the internal data. For some years, it seems that almost every challenge concerning data accessibility in objects has been successfully solved by OOP. However, as data is becoming the center of software development, data access/exchange in the form of objects requires greater attention to protect the data authenticity. For example, when object A gets an array of integers from object B, how do we protect the integrity of this array of integers? In such a case, a call for read-only objects arises. As Java is the most popular OOP language (Hendrickson, 2012), let s use Java as the example to discuss this read-only concept. In this paper, using Java as the example, we analyzed the existing approaches to obtain read-only objects, and presented the keyword readonly to directly and dynamically make an object read-only. Read Only in Java: A read-only object is an object whose data fields can be viewed but cannot be modified. This concept is distinct from data hiding. In data hiding, certain data fields of an object are hidden from direct access but are accessible only through predefined methods; and once accessed or obtained, these data fields may or may not be modified by outside callers. Constants The most common way to achieve the concept of read-only in different OOP languages is to define constants. In Java, the keyword final seems to represent read-only for primitive data types. For example, the statement public final int x = 5; makes the variable x viewable by other outside objects but non-modifiable. Once the variable x is set to a value, it cannot be modified again. A deeper analysis on such constants reveals that such a constant is not bona fide read-only because it only guarantees that the variable cannot be re-assigned. It does not have any restriction on the value itself. Since primitive data is always a literal value which is by default constant, it seems that in this case both the variable and its value are constant 42

3 and therefore read-only. However, if the keyword final is used upon a reference data type, such as in the following statement: private final TestObject tt = new TestObject(); Given TestObject is a class predefined, such a statement only prevents the variable tt from being re-assigned. However, it does not have any restriction on the actions or modifications on the object referenced by tt. If the TestObject has accessible methods to modify its contents, then the content of the TestObject referenced by tt can still be modified by outside callers. Therefore, defining constants does not create real read-only objects. Immutable Objects In Java, there are a few types of objects that are truly read-only. One example is String. String objects are said to be immutable, which means a String object cannot be modified once it is created (Arnold, Gosling, & Holmes, 2000) (Gaddis, 2011). Instead, any changes on a String object will generate a new copy. Such immutable objects are achieved by carefully designing the class template. Therefore, whether an object is immutable or not depends on its class template. The immutability is predefined. The following two statements demonstrate this understanding. 1) String s = new String( Hello World ); 2) s = s.tolowercase(); Statement 1) defines s as a String variable and assigns it the value Hello World. Once created, the value Hello World is constant and cannot be modified. Though statement 2) converts it into lowercase, what really happened is that a new String is generated as hello world and this new value is assigned to variable s. This example illustrates that the variable s can be re-assigned while the String object it references cannot be modified. This example also shows that a variable and its referencing object are treated separately in Java. Though it has been suggested that if possible, classes are better to be designed as immutable (Bloch, 2008), there are not many predefined immutable classes in Java. In Java, another frequently used immutable object is Integer. Both Integer and String are carefully designed so that any changes made upon an object of them will generate a copy, thus leaving the original object unchanged. Certainly, the creation of immutable objects depends on the class design process. To have immutable objects, the class templates must be predefined or predesigned as immutable. Clearly, using predefined classes cannot offer dynamic read-only objects. Wrapper Classes A typical case calling for read-only objects is when a method returns an array of numbers that requires to be read-only. In the current 43

4 programming environment, once the caller obtains the array, it obtains the reference to this array and therefore it can modify the content of the array at will. How to make such an array of numbers read-only? Though a solution to this case is to return a copy of the array leaving the original array intact, such a solution may result in memory shortage when the array is of large size and such copies keep accumulating. An alternate solution to this case is to use a wrapper class. For an array of numbers or of any other primitive data types, it is easy to design a wrapper class such that no direct access to the array data is allowed. Instead, the caller can only obtain one item of the array at a time. The following example demonstrates this solution in which the class IntegerArray is a wrapper class to render read-only arrays of integers. public class IntegerArray{ private int[] a; public IntegerArray(int[] v){ a = v; //deep copy is a better practice here public int getlength(){ return a.length; public int getinteger(int index){ return a[index]; The above solution works well for primitive data types, though its disadvantage is to require additional programming for predefined wrapper classes. However, if the returned data is an array of objects, i.e. an array of reference data type, the above solution cannot guarantee that each object inside the array is read-only. When each single element of the array is a referenced object, once the caller obtains an element, the caller can still modify the content of this object element if the object provides such modification accessibility. To ensure that the read-only is fully achieved, the objects in the array must be designed in such a way that modification is prohibited. The complexity of rendering read-only objects via using wrapper classes can become too expensive to seriously impact the software development process. Besides making the programming process less intuitive but more complicated, using wrapper classes still cannot create read-only objects dynamically because all the wrapper classes must be predefined. Therefore, strictly speaking, Java does not offer read-only objects that can be defined and created dynamically. 44

5 The Proposed Read Only: As it seems that currently there is no good way to generate read-only objects on the fly, the keyword readonly is then proposed in this paper. This keyword exists in the programming language c#. Though the keyword readonly of c# is slightly different from the traditional constant as defined by the keyword const, it still places restriction on the variable only, i.e. once the variable is assigned a value, the variable cannot be reassigned, while the referenced object can be modified independently. In this sense, the keyword readonly of programming language c# is not truly read-only. The central idea of this paper is that the keyword readonly makes an object read-only. It does not define an object to be read-only, it makes an object to be read-only. In addition, it makes both the variable and the object referenced by the variable read-only. To understand the keyword readonly proposed in this paper, let s elucidate the rules governing the proposed readonly concept. a) The keyword readonly can apply to variables of both primitive and reference data types. b) Once a variable and its referencing object are made read-only, they stay read-only. c) Once a variable is made read-only, it cannot be assigned a value again, and the object referenced by the read-only variable cannot be modified. d) A method returning a read-only object must be a read-only method marked by the keyword readonly. A read-only object can only be returned by a read-only method. For example: public static readonly TestObject findtheobject() e) The read-only property of a read-only object is remained in the process of serialization and deserialization of this object. f) Before an object is made read-only, all of its composed fields should be read-only. If a field is of reference data type and is not read-only, this field will be assigned null automatically. Rule a) dictates that the readonly keyword can be applied to both primitive and reference data types. When applied to a primitive data type, it functions like the keyword final. Nevertheless, it is not recommended to use keyword readonly when the keyword final is supposed to be used on primitive data types. Rule b) dictates that the read-only-making process is irreversible. Once a variable or object is made read-only, it stays read-only. Rule c) dictates that once a variable is made read-only, i.e. once the keyword readonly is used upon a variable, both the variable and its referencing object become read-only. Thus, right from this moment, this 45

6 variable cannot be assigned a value again, and the object referenced by this variable cannot be modified any more either. Rule d) is to help clearly specify the expectation from a method. If a method or function is returning a read-only object without clearly stating it, the caller may not be aware of what it is getting. Rule e) dictates that the read-only property of a read-only object is to be kept even when it is serialized and de-serialized. This rule guarantees that such a read-only property of an object can be saved into a binary file and can also be transported across network. Rule f) dictates that in the case of object aggregation or composition, before the hosting object is made read-only, the contained objects or data fields should better be read-only for good programming practice. However, if a contained field is not read-only at that time, it will be forced to become read-only. In the case when the field is of a primitive data type, the variable is forced to become read-only. In the case where the field is of reference data type, the variable is assigned null to leave the referenced object intact. This rule is critical because it guarantees that nothing obtained from a read-only object can be further modified, thus ensures the full read-only. However, this rule may create dangling objects when some reference variables are assigned null leaving the referenced objects dangling. Therefore, as a rule of good programming practice, it is necessary to make sure that all the fields are read-only before making the hosting object read-only. The following two case studies help illustrate the use of the keyword readonly. Case Study 1 public readonly int[] compute(int i){ int[] data = new int[10]; for(int t=0; t<data.length; t++){ data[t] = t + t * i; readonly data; return data; In the above codes, an integer array was first generated. Before the keyword readonly was applied on the variable data, both the variable data and its referenced integer array are modifiable. The statement readonly data, however, makes both the variable data and its referencing integer array read-only. Any attempts to modify the content of the variable data is now prohibited. Because data is now read-only and will be returned, the method is marked as readonly. 46

7 Case Study 2 public class MyCode{ private int code; private String name; public MyData(int c, String s){ code = c; name = s; public int getcode(){ return code; public void setcode(int c){ code = c; public class CheckCode{ public static void main(string args[]){ MyCode me = new MyCode(100, USA ); readonly me; In the above case study, the class MyCode has two fields and one field is of type String, which is a reference data type. So, in the class CheckCode, the statement readonly me will make the field name of the object me to be null automatically. Nevertheless, once an object of MyCode is made read-only, its internal state cannot be modified any more, i.e. the use of the method setcode() is prohibited. However, the method getcode() is still functional. Discussion and Conclusion Due to the increasing data manipulation and exchange occurring in computer software systems, the protection of data genuineness becomes critical. One way to protect data is to have read-only objects. Though programming languages such as Java has ways to achieve read-only to a certain degree, there is still no dedicated method to dynamically create readonly objects. Meanwhile, though the programming language c# has the keyword readonly, it only prohibits the read-only variable from being reassigned while it does not protect the referenced object from being modified; and it cannot dynamically make an object read-only either. The 47

8 proposed keyword readonly proposed in this article is a step forward in offering read-only objects with dynamism. The keyword readonly introduced in this paper is more like an operator in that it changes the nature of an object. An object can be modifiable initially. When it is ready to make it read-only, the keyword readonly is applied upon the variable referencing this object. This application has two impacts. It makes both the variable and the referenced object readonly. The real challenge lies in the case when an object is composed of other objects and this hosting object is to be made read-only. What should happen to the fields of this hosting object? This paper proposed a reasonable approach in which all the contained fields are forced to become read-only, though this approach has its drawback in that it can generate dangling objects. Thus, it is important to follow good programming practice in the use of the keyword readonly. Abusing the keyword readonly can make it notorious, like the keyword goto which was once very popular but later was considered harmful (Dijkstra, 1968). The proper uses of constants in all programming languages are examined by the compiler. Any attempts to reassign the variable that is defined to be a constant will result in a compilation error. The use of the proposed keyword readonly, however, can make an object read-only dynamically. An object can be modifiable initially, but later is made to be read-only. Enforcing the complete check of proper uses of the keyword/operator readonly requires an intelligent compiler. Nevertheless, run-time errors may occur when the keyword readonly is not properly used. To completely avoid run-time errors, detailed specification about the use of this keyword readonly becomes necessary when implementing this keyword in a programming language. In Java, the operator instanceof tests if an object referenced by a variable is of a certain type. With this keyword/operator readonly, it is reasonable to have another operator to test if a variable and its referencing object are read-only. Having such a testing operator can certainly help ease the programming with read-only objects. The keyword readonly has already appeared in the programming language c#, which testifies the need for read-only objects. True read-only objects that can be created dynamically may be coming soon in other objectoriented programming languages. References: Arnold, K., Gosling, J., & Holmes, D. (2000). The Java Programming Language (third edition). Addison-Wesley. Bloch, J. (2008). Effective Java. Addison-Wesley. 48

9 Dijkstra,, E. W. (1968). Go To Statement Considered Harmful. Communications of the ACM, Gaddis, T. (2011). Starting out with Java Early Objects (4th edition). Boston: Addison Wesley. Hendrickson, M. (2012, April 06). A deep look at the market for books on programming languages. Retrieved from O'Reilly Radar: 49

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

SOFTWARE ENGINEERING 2: OBJECT ORIENTED SOFTWARE ENGINEERING

SOFTWARE ENGINEERING 2: OBJECT ORIENTED SOFTWARE ENGINEERING SOFTWARE ENGINEERING 2: OBJECT ORIENTED SOFTWARE ENGINEERING 1. This is a general question about Object Oriented Software Engineering. a) Compare and contrast how software complexity is handled in Structured

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information

Object Oriented Programming (Interview Questions & Answers)

Object Oriented Programming (Interview Questions & Answers) Object Oriented Programming (Interview Questions & Answers) Collected from different websites. Use for non-commercial purpose. Sohail Basheer Lecturer- Computer Science (visiting) Department of Computer

More information

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,

More information

Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

More information

Introduction to C++ Programming

Introduction to C++ Programming Introduction to C++ Programming C++ is one of the most popular programming languages in use in industry today. According to the TIOBE Programming Community Index, which can be accessed at this url: http://www.tiobe.com/index.php/content/paperinfo/tpci/

More information

Topic Java Class. Library INTRODUCTION LEARNING OUTCOMES. By the end of this topic, you should be able to:

Topic Java Class. Library INTRODUCTION LEARNING OUTCOMES. By the end of this topic, you should be able to: Topic Java Class Library 8 LEARNING OUTCOMES By the end of this topic, you should be able to: 1. Describe the meaning of package in Java; 2. Describe the purpose of keyword import; 3. Describe of how classes

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Java Memory and Intro to OOP

Java Memory and Intro to OOP + Java Memory and Intro to OOP + What is Java? Programming language Standard libraries ex. Math.random() Tools: compiler, runtime, others + What is the compiler? AKA javac A compiler is a program that

More information

AVRO - SERIALIZATION

AVRO - SERIALIZATION http://www.tutorialspoint.com/avro/avro_serialization.htm AVRO - SERIALIZATION Copyright tutorialspoint.com What is Serialization? Serialization is the process of translating data structures or objects

More information

SEARCHING AND SORTING

SEARCHING AND SORTING SEARCHING AND SORTING Searching A basic operation in computer science Problem formulation Given: Collection (array) of values A property on values Find: a value having the property in the array Examples

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

Chapter 1 Fundamentals of Java Programming

Chapter 1 Fundamentals of Java Programming Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The

More information

A CASE STUDY: JAVA IS SECURE PROGRAMMING LANGUAGE

A CASE STUDY: JAVA IS SECURE PROGRAMMING LANGUAGE International Journal of Computer Networking, Wireless and Mobile Communications (IJCNWMC) ISSN(P): 2250-1568; ISSN(E): 2278-9448 Vol. 4, Issue 2, Apr 2014, 5-10 TJPRC Pvt. Ltd. A CASE STUDY: JAVA IS SECURE

More information

Chapter 12. Support for Object-Oriented Programming ISBN

Chapter 12. Support for Object-Oriented Programming ISBN Chapter 12 Support for Object-Oriented Programming ISBN 0-321-33025-0 Chapter 12 Topics Introduction Object-Oriented Programming Design Issues for Object-Oriented Languages Support for Object-Oriented

More information

Using Image Processing and Visualization to Teach Object Oriented Programming in C++

Using Image Processing and Visualization to Teach Object Oriented Programming in C++ Using Image Processing and Visualization to Teach Object Oriented Programming in C++ Author: C. Rolstad, Oslo University College, Cort Adelersgate 30, 0254 Oslo, Norway. cecilier@iu.hio.no Abstract When

More information

Lecture 3. Using Classes and Objects

Lecture 3. Using Classes and Objects Lecture 3 Using Classes and Objects Using Classes and Objects We can create more interesting programs using predefined classes and related objects Chapter 3 focuses on: object creation and object references

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 1 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered include:

More information

C Primer. Fall Introduction C vs. Java... 1

C Primer. Fall Introduction C vs. Java... 1 CS 33 Intro Computer Systems Doeppner C Primer Fall 2016 Contents 1 Introduction 1 1.1 C vs. Java.......................................... 1 2 Functions 1 2.1 The main() Function....................................

More information

CSA 1012 Object-Oriented Programming

CSA 1012 Object-Oriented Programming CSA 1012 Object-Oriented Programming Mr. Joseph Cordina Rm 203, New Comp. Bldg. E-mail: joseph.cordina@um.edu.mt 1 Course Objectives Familiarity with the syntax of the Java or C# language Programming in

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

2. Names, Scopes, and Bindings

2. Names, Scopes, and Bindings 2. Names, Scopes, and Bindings Binding, Lifetime, Static Scope, Encapsulation and Modules, Dynamic Scope Copyright 2010 by John S. Mallozzi Names Variables Bindings Binding time Language design issues

More information

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming Java has become enormously popular. Java s rapid rise and wide acceptance can be traced to its design

More information

C# and Other Languages

C# and Other Languages C# and Other Languages Rob Miles Department of Computer Science Why do we have lots of Programming Languages? Different developer audiences Different application areas/target platforms Graphics, AI, List

More information

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. JAVA TYPES BASIC DATA TYPES GENERAL Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type

More information

Course: Introduction to Java Using Eclipse Training

Course: Introduction to Java Using Eclipse Training Course: Introduction to Java Using Eclipse Training Course Length: Duration: 5 days Course Code: WA1278 DESCRIPTION: This course introduces the Java programming language and how to develop Java applications

More information

Orphaned Linked List

Orphaned Linked List Orphaned Linked List An Object-Oriented approach to collapsing multiple Progress Bars Danny Ruijters danny.ruijters@philips.com Abstract. Everybody knows the frustration caused by a new progress bar popping

More information

10266A: Programming in C# with Microsoft Visual Studio 2010

10266A: Programming in C# with Microsoft Visual Studio 2010 10266A: Programming in C# with Microsoft Visual Studio 2010 Course Overview The course focuses on the C# program structure, language syntax, and implementation details with.net Framework 4.0. This course

More information

Chapter 1 Java Program Design and Development

Chapter 1 Java Program Design and Development presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 7: Object-Oriented Programming Introduction One of the key issues in programming is the reusability of code. Suppose that you have written a program

More information

modifier returnvaluetype methodname(list of parameters) { // Method body; }

modifier returnvaluetype methodname(list of parameters) { // Method body; } JAVA METHODS METHODS A Java method is similar to function in C/C++. It is a collection of statements that are grouped together to perform an operation. When you call the System.out.println method, for

More information

Limitations of Data Encapsulation and Abstract Data Types

Limitations of Data Encapsulation and Abstract Data Types Limitations of Data Encapsulation and Abstract Data Types Paul L. Bergstein University of Massachusetts Dartmouth pbergstein@umassd.edu Abstract One of the key benefits provided by object-oriented programming

More information

Computer Programming I

Computer Programming I Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,

More information

Part I:( Time: 90 minutes, 30 Points)

Part I:( Time: 90 minutes, 30 Points) Qassim University Deanship of Educational Services Preparatory Year Program- Computer Science Unit Final Exam - 1434/1435 CSC111 Time: 2 Hours + 10 Minutes 1 MG Student name: Select the correct choice:

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

COMPARISON OF OBJECT-ORIENTED AND PROCEDURE-BASED COMPUTER LANGUAGES: CASE STUDY OF C++ PROGRAMMING

COMPARISON OF OBJECT-ORIENTED AND PROCEDURE-BASED COMPUTER LANGUAGES: CASE STUDY OF C++ PROGRAMMING COMPARISON OF OBJECT-ORIENTED AND PROCEDURE-BASED COMPUTER LANGUAGES: CASE STUDY OF C++ PROGRAMMING Kuan C. Chen, Ph.D. Assistant Professor Management Information Systems School of Management Purdue University

More information

Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous

Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information

CLEAN DIGITAL GARBAGE

CLEAN DIGITAL GARBAGE CLEAN DIGITAL GARBAGE Hong Zhou, PhD Joseph Manthey, PhD Ekaterina Lioutikova, PhD University of Saint Joseph, West Hartford, Connecticut, USA Abstract Along with the vast price drop in computer disk space

More information

An Introduction to the Java Programming Language History of Java

An Introduction to the Java Programming Language History of Java An Introduction to the Java Programming Language History of Java In 1991, a group of Sun Microsystems engineers led by James Gosling decided to develop a language for consumer devices (cable boxes, etc.).

More information

McGraw-Hill The McGraw-Hill Companies, Inc., 20 1. 01 0

McGraw-Hill The McGraw-Hill Companies, Inc., 20 1. 01 0 1.1 McGraw-Hill The McGraw-Hill Companies, Inc., 2000 Objectives: To describe the evolution of programming languages from machine language to high-level languages. To understand how a program in a high-level

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Programs and Methods Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Programs and Methods 1 / 8 The Anatomy of a Java Program It is customary

More information

Chapter 12. Support for. Oi t Programming

Chapter 12. Support for. Oi t Programming Chapter 12 Support for Object-Oriented Oi t Programming Chapter 12 Topics Introduction Object-Oriented Programming Design Issues for Object-Oriented Languages Support for Object-Oriented Programming g

More information

Review questions for Chapter 9

Review questions for Chapter 9 Answer first, then check at the end. Review questions for Chapter 9 True/False 1. A compiler translates a high-level language program into the corresponding program in machine code. 2. An interpreter is

More information

Summary. Pre requisition. Content Details: 1. Basics in C++

Summary. Pre requisition. Content Details: 1. Basics in C++ Summary C++ Language is one of the approaches to provide object-oriented functionality with C like syntax. C++ adds greater typing strength, scoping and other tools useful in object-oriented programming

More information

COMP1008 Inheritance. Outline. Subclass and Superclass. Inheritance. Multiple Subclasses. Inheritance Hierarchy

COMP1008 Inheritance. Outline. Subclass and Superclass. Inheritance. Multiple Subclasses. Inheritance Hierarchy Outline COMP1008 Inheritance Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented programming. 2 Inheritance Subclass and Superclass Models the kind-of

More information

using java 1.5 generics

using java 1.5 generics Weiss_3e_04 Page 131 Wednesday, January 12, 2005 3:05 PM 4.7 implementing generic components using java 1.5 generics 131 4.7 implementing generic components using java 1.5 generics We have already seen

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Object oriented programming. Lecture 13: Object orientation. Object oriented programming. Introduction. OO and ADT:s. Introduction

Object oriented programming. Lecture 13: Object orientation. Object oriented programming. Introduction. OO and ADT:s. Introduction Lecture 13: Object orientation Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO support in C++ and Java Object

More information

Module 1. Introduction to Software Engineering. Version 2 CSE IIT, Kharagpur

Module 1. Introduction to Software Engineering. Version 2 CSE IIT, Kharagpur Module 1 Introduction to Software Engineering Lesson 2 Structured Programming Specific Instructional Objectives At the end of this lesson the student will be able to: Identify the important features of

More information

Strings in C++ and Java. Questions:

Strings in C++ and Java. Questions: Strings in C++ and Java Questions: 1 1. What kind of access control is achieved by the access control modifier protected? 2 2. There is a slight difference between how protected works in C++ and how it

More information

CS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I. 2-marks

CS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I. 2-marks CS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I 2-marks 1) Give some characteristics of procedure-oriented language. Emphasis is on doing things (algorithms). Larger programs are divided

More information

Lecture 7: Class design for security

Lecture 7: Class design for security Lecture topics Class design for security Visibility of classes, fields, and methods Implications of using inner classes Mutability Design for sending objects across JVMs (serialization) Visibility modifiers

More information

Johannes Sametinger. C. Doppler Laboratory for Software Engineering Johannes Kepler University of Linz A-4040 Linz, Austria

Johannes Sametinger. C. Doppler Laboratory for Software Engineering Johannes Kepler University of Linz A-4040 Linz, Austria OBJECT-ORIENTED DOCUMENTATION C. Doppler Laboratory for Software Engineering Johannes Kepler University of Linz A-4040 Linz, Austria Abstract Object-oriented programming improves the reusability of software

More information

Structural Design Patterns Used in Data Structures Implementation

Structural Design Patterns Used in Data Structures Implementation Structural Design Patterns Used in Data Structures Implementation Niculescu Virginia Department of Computer Science Babeş-Bolyai University, Cluj-Napoca email address: vniculescu@cs.ubbcluj.ro November,

More information

Software Engineering Techniques

Software Engineering Techniques Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

C++ Keywords. If/else Selection Structure. Looping Control Structures. Switch Statements. Example Program

C++ Keywords. If/else Selection Structure. Looping Control Structures. Switch Statements. Example Program C++ Keywords There are many keywords in C++ that are not used in other languages. bool, const_cast, delete, dynamic_cast, const, enum, extern, register, sizeof, typedef, explicit, friend, inline, mutable,

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

C++ How to Program, 8/e by Pearson Education, Inc. All Rights Reserved.

C++ How to Program, 8/e by Pearson Education, Inc. All Rights Reserved. C++ How to Program, 8/e 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. 1992-2012 by Pearson Education, Inc. We ve studied fixed-size data structures such as one-dimensional arrays

More information

Chapter 7. Arrays and Collections. Instructor s Manual Table of Contents. At a Glance. Chapter Overview. Chapter Objectives.

Chapter 7. Arrays and Collections. Instructor s Manual Table of Contents. At a Glance. Chapter Overview. Chapter Objectives. C# Programming: From Problem Analysis to Program Design, 2nd ed. 7-1 Chapter 7 Arrays and Collections At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes

More information

Keywords Compared in Various Languages

Keywords Compared in Various Languages Keywords Compared in Various Languages Visual Studio 2010 This topic lists common programming tasks that can be summarized with a language keyword. For more information about tasks that need code examples,

More information

NEW. php architect NEW. For existing subscribers. Upgrade to the Print edition and save!

NEW. php architect NEW. For existing subscribers. Upgrade to the Print edition and save! You ll never know what we ll come up with next For existing subscribers Upgrade to the Print edition and save! Login to your account for more details. NEW LOWER PRICE! php architect The Magazine For PHP

More information

Short Introduction to the Concepts of Programming in Java Overview over the most important constructs

Short Introduction to the Concepts of Programming in Java Overview over the most important constructs Introduction to Java Short Introduction to the Concepts of Programming in Java Overview over the most important constructs OOIS 1998/99 Ulrike Steffens Software Systems Institute ul.steffens@tu- harburg.de

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Java Classes. GEEN163 Introduction to Computer Programming

Java Classes. GEEN163 Introduction to Computer Programming Java Classes GEEN163 Introduction to Computer Programming Never interrupt someone doing what you said couldn't be done. Amelia Earhart Classes, Objects, & Methods Object-oriented programming uses classes,

More information

The IC Language Specification. Spring 2006 Cornell University

The IC Language Specification. Spring 2006 Cornell University The IC Language Specification Spring 2006 Cornell University The IC language is a simple object-oriented language that we will use in the CS413 project. The goal is to build a complete optimizing compiler

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

Object Oriented System Development with VB.NET

Object Oriented System Development with VB.NET Chapter 1 Object Oriented System Development with Objectives In this chapter, you will: Learn about OO development and Understand object-oriented concepts Recognize the benefits of OO development Preview

More information

Item 7: Prefer Immutable Atomic Value Types

Item 7: Prefer Immutable Atomic Value Types Item 7: Prefer Immutable Atomic Value Types 1 Item 7: Prefer Immutable Atomic Value Types Immutable types are simple: After they are created, they are constant. If you validate the parameters used to construct

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

An Overview of Java. overview-1

An Overview of Java. overview-1 An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2

More information

Using Classes and Objects

Using Classes and Objects Chapter 3: Using Classes and Objects Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Using Classes and Objects We can create more interesting programs using predefined

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Java 101 primer: Composition and inheritance. Use composition to overcome the problem with inheritance

Java 101 primer: Composition and inheritance. Use composition to overcome the problem with inheritance Java 101 primer: Composition and inheritance Use composition to overcome the problem with inheritance BY JEFF FRIESEN, JAVAWORLD, OCTOBER 2015 In Java 101: Inheritance in Java, Part 1, you learned how

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Replacing and Patching Core Java Classes

Replacing and Patching Core Java Classes Replacing and Patching Core Java Classes 15 IN THIS CHAPTER A path without obstacles probably leads nowhere. Defalque Why Bother? In Chapter 5, Replacing and Patching Application Classes, we talked about

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

IT Fresher Training Program. Course Contents

IT Fresher Training Program. Course Contents IT Fresher Training Program Course Contents Following courses are covered as a part of Fresher Training program Introduction to.net C# ASP.NET Core Java Advance Java Concept Overview SQL Server & MySQL

More information

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1 The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose

More information

C++ for Game Programmers

C++ for Game Programmers C++ for Game Programmers Course Description C++ has become one of the favourite programming language for game programmers. Reasons for wide spread acceptability of C++ are plenty, but primary reasons are,

More information

Group number 24 Joni Saarinen Daniel Kullberg

Group number 24 Joni Saarinen Daniel Kullberg C# Group number 24 Joni Saarinen Daniel Kullberg C# (pronounced C sharp) is a multi paradigm programming language developed by Microsoft. It is primarily an imperative language but support for functional

More information

1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Page 1

1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Page 1 CS 1621 MIDTERM EXAM 1 Name: Problem 1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Score Page 1 1. (1 x 17 = 17 points) Determine if each of the following statements

More information

Arrays - Introduction. Declaration of Arrays. Initialisation of Arrays. Creation of Arrays. Arrays, Strings and Collections [1]

Arrays - Introduction. Declaration of Arrays. Initialisation of Arrays. Creation of Arrays. Arrays, Strings and Collections [1] Arrays - Introduction Arrays, Strings and Collections [] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering University of Melbourne,

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

C Compiler Targeting the Java Virtual Machine

C Compiler Targeting the Java Virtual Machine C Compiler Targeting the Java Virtual Machine Jack Pien Senior Honors Thesis (Advisor: Javed A. Aslam) Dartmouth College Computer Science Technical Report PCS-TR98-334 May 30, 1998 Abstract One of the

More information

CS271: Data Structures. Binary Search Trees

CS271: Data Structures. Binary Search Trees CS271: Data Structures Binary Search Trees This project has three parts: an implementation of a binary search tree class, a testing plan, and an experiment in tree height. 1. PART 1 Implement a binary

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

Master s Project Proposal An Application to create Problem- Specific DOMs for XML

Master s Project Proposal An Application to create Problem- Specific DOMs for XML Master s Project Proposal An Application to create Problem- Specific DOMs for XML Liangxiao Zhu lxz0062@cs.rit.edu October 9, 2002 1. SUMMARY... 2 2. OVERVIEW... 2 3. FUNCTIONAL SPECIFICATION... 3 3.1

More information

CS106A, Stanford Handout #38. Strings and Chars

CS106A, Stanford Handout #38. Strings and Chars CS106A, Stanford Handout #38 Fall, 2004-05 Nick Parlante Strings and Chars The char type (pronounced "car") represents a single character. A char literal value can be written in the code using single quotes

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

GAME development can be a complicated

GAME development can be a complicated SENIOR PROJECT OF COMPUTER ENGINEERING, JUNE 2014 1 ECS Game Engine Design Daniel Hall, Student, Cal Poly SLO, Zoe Wood, Advisor, Cal Poly SLO, Abstract Game programming design and organization can be

More information

Java Programming Fundamentals

Java Programming Fundamentals Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

JAVA PRIMITIVE DATA TYPE

JAVA PRIMITIVE DATA TYPE JAVA PRIMITIVE DATA TYPE Description Not everything in Java is an object. There is a special group of data types (also known as primitive types) that will be used quite often in programming. For performance

More information

NEW YORK CITY COLLEGE OF TECHNOLOGY/CUNY Computer Systems Technology Department

NEW YORK CITY COLLEGE OF TECHNOLOGY/CUNY Computer Systems Technology Department NEW YORK CITY COLLEGE OF TECHNOLOGY/CUNY Computer Systems Technology Department COURSE: CST1201 Programming Fundamentals (2 class hours, 2 lab hours, 3 credits) Course Description: This course is an intensive

More information

Lecture 4 Notes: Arrays and Strings

Lecture 4 Notes: Arrays and Strings 6.096 Introduction to C++ January 10, 2011 Massachusetts Institute of Technology John Marrero Lecture 4 Notes: Arrays and Strings 1 Arrays So far we have used variables to store values in memory for later

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information