READ-ONLY OBJECT IN OBJECT-ORIENTED PROGRAMMING

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

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

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

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

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

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

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

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

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

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

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

Managing Variability in Software Architectures 1 Felix Bachmann*

Managing Variability in Software Architectures 1 Felix Bachmann* Managing Variability in Software Architectures Felix Bachmann* Carnegie Bosch Institute Carnegie Mellon University Pittsburgh, Pa 523, USA fb@sei.cmu.edu Len Bass Software Engineering Institute Carnegie

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

Umbrello UML Modeller Handbook

Umbrello UML Modeller Handbook 2 Contents 1 Introduction 7 2 UML Basics 8 2.1 About UML......................................... 8 2.2 UML Elements........................................ 9 2.2.1 Use Case Diagram.................................

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

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

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

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

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

Stack Allocation. Run-Time Data Structures. Static Structures

Stack Allocation. Run-Time Data Structures. Static Structures Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

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

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms. COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation

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

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

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

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

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

Parameter Passing in Pascal

Parameter Passing in Pascal Parameter Passing in Pascal Mordechai Ben-Ari Department of Science Teaching Weizmann Institute of Science Rehovot 76100 Israel ntbenari@wis.weizmann.ac.il Abstract This paper claims that reference parameters

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

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

Introduction to Data Structures

Introduction to Data Structures Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate

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

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

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

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

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

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

Serialization in Java (Binary and XML)

Serialization in Java (Binary and XML) IOWA STATE UNIVERSITY Serialization in Java (Binary and XML) Kyle Woolcock ComS 430 4/4/2014 2 Table of Contents Introduction... 3 Why Serialize?... 3 How to Serialize... 3 Serializable Interface... 3

More information

A Web Services Created Online Training and Assessment Scheme

A Web Services Created Online Training and Assessment Scheme International Journal of Current Engineering and Technology E-ISSN 2277 4106, P-ISSN 2347 5161 2015 INPRESSCO, All Rights Reserved Available at http://inpressco.com/category/ijcet Research Article Md Mobin

More information

Algorithms, Flowcharts & Program Design. ComPro

Algorithms, Flowcharts & Program Design. ComPro Algorithms, Flowcharts & Program Design ComPro Definition Algorithm: o sequence of steps to be performed in order to solve a problem by the computer. Flowchart: o graphical or symbolic representation of

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

Basic Object-Oriented Programming in Java

Basic Object-Oriented Programming in Java core programming Basic Object-Oriented Programming in Java 1 2001-2003 Marty Hall, Larry Brown http:// Agenda Similarities and differences between Java and C++ Object-oriented nomenclature and conventions

More information

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be: Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

More information

A deeper look at Inline functions

A deeper look at Inline functions A deeper look at Inline functions I think it s safe to say that all Overload readers know what C++ inline functions are. When we declare a function or member function as inline we are trying to avoid the

More information

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

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

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

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points

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

Passing Arguments. A comparison among programming languages. Curtis Bright. April 20, 2011

Passing Arguments. A comparison among programming languages. Curtis Bright. April 20, 2011 Passing Arguments A comparison among programming languages Curtis Bright April 20, 2011 Abstract This report describes and compares the argument passing styles used in contemporary programming languages,

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

In this Chapter you ll learn:

In this Chapter you ll learn: Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

More information

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Kenneth M. Anderson Lecture 20 CSCI 5828: Foundations of Software Engineering OO Design 1 Object-Oriented Design Traditional procedural systems separate data and procedures, and

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

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

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

A Java-based system support for distributed applications on the Internet

A Java-based system support for distributed applications on the Internet A Java-based system support for distributed applications on the Internet D. Hagimont 1, D. Louvegnies 2 SIRAC Project INRIA, 655 av. de l Europe, 38330 Montbonnot Saint-Martin, France Abstract: We have

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

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

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

Arrays in Java. Working with Arrays

Arrays in Java. Working with Arrays Arrays in Java So far we have talked about variables as a storage location for a single value of a particular data type. We can also define a variable in such a way that it can store multiple values. Such

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

A Reusability Concept for Process Automation Software

A Reusability Concept for Process Automation Software A Reusability Concept for Process Automation Software Wolfgang Narzt, Josef Pichler, Klaus Pirklbauer, Martin Zwinz Business Information Systems C. Doppler Laboratory for Software Engineering University

More information

CACHÉ: FLEXIBLE, HIGH-PERFORMANCE PERSISTENCE FOR JAVA APPLICATIONS

CACHÉ: FLEXIBLE, HIGH-PERFORMANCE PERSISTENCE FOR JAVA APPLICATIONS CACHÉ: FLEXIBLE, HIGH-PERFORMANCE PERSISTENCE FOR JAVA APPLICATIONS A technical white paper by: InterSystems Corporation Introduction Java is indisputably one of the workhorse technologies for application

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program CS 2112 Lecture 27 Interpreters, compilers, and the Java Virtual Machine 1 May 2012 Lecturer: Andrew Myers 1 Interpreters vs. compilers There are two strategies for obtaining runnable code from a program

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

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

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

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

Class 16: Function Parameters and Polymorphism

Class 16: Function Parameters and Polymorphism Class 16: Function Parameters and Polymorphism SI 413 - Programming Languages and Implementation Dr. Daniel S. Roche United States Naval Academy Fall 2011 Roche (USNA) SI413 - Class 16 Fall 2011 1 / 15

More information

Adapter, Bridge, and Façade

Adapter, Bridge, and Façade CHAPTER 5 Adapter, Bridge, and Façade Objectives The objectives of this chapter are to identify the following: Complete the exercise in class design. Introduce the adapter, bridge, and façade patterns.

More information

Input/Output Subsystem in Singularity Operating System

Input/Output Subsystem in Singularity Operating System University of Warsaw Faculty of Mathematics, Computer Science and Mechanics Marek Dzikiewicz Student no. 234040 Input/Output Subsystem in Singularity Operating System Master s Thesis in COMPUTER SCIENCE

More information

Quotes from Object-Oriented Software Construction

Quotes from Object-Oriented Software Construction Quotes from Object-Oriented Software Construction Bertrand Meyer Prentice-Hall, 1988 Preface, p. xiv We study the object-oriented approach as a set of principles, methods and tools which can be instrumental

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

A Methodological Approach to Domain Engineering for Software Variability Enhancement

A Methodological Approach to Domain Engineering for Software Variability Enhancement A Methodological Approach to Domain Engineering for Software Variability Enhancement Alexandre Bragança 1,2 and Ricardo J. Machado 3 1 Dep. I&D, I2S Informática Sistemas e Serviços SA, Porto, Portugal,

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

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY

CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY CHAPTER 2 DATABASE MANAGEMENT SYSTEM AND SECURITY 2.1 Introduction In this chapter, I am going to introduce Database Management Systems (DBMS) and the Structured Query Language (SQL), its syntax and usage.

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

A Comparison of Programming Languages for Graphical User Interface Programming

A Comparison of Programming Languages for Graphical User Interface Programming University of Tennessee, Knoxville Trace: Tennessee Research and Creative Exchange University of Tennessee Honors Thesis Projects University of Tennessee Honors Program 4-2002 A Comparison of Programming

More information

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

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

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris 1 Collections - Set What is a Set? A Set is an unordered sequence of data with no duplicates Not like a List where you

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

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012 Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

More information

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes

D06 PROGRAMMING with JAVA. Ch3 Implementing Classes Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch3 Implementing Classes PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com,

More information

Design Patterns. Advanced Software Paradigms (A. Bellaachia) 1

Design Patterns. Advanced Software Paradigms (A. Bellaachia) 1 Design Patterns 1. Objectives... 2 2. Definitions... 3 2.1. What is a Pattern?... 3 2.2. Categories of Patterns... 4 3. Pattern Characteristics [Buschmann]:... 5 4. Essential Elements of a Design Pattern

More information

Konzepte objektorientierter Programmierung

Konzepte objektorientierter Programmierung Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 3: Some More OO Languages Wintersemester 04/05 Agenda for Today 2 Homework Finish

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

Module 9. User Interface Design. Version 2 CSE IIT, Kharagpur

Module 9. User Interface Design. Version 2 CSE IIT, Kharagpur Module 9 User Interface Design Lesson 21 Types of User Interfaces Specific Instructional Objectives Classify user interfaces into three main types. What are the different ways in which menu items can be

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

Syllabus for CS 134 Java Programming

Syllabus for CS 134 Java Programming - Java Programming Syllabus Page 1 Syllabus for CS 134 Java Programming Computer Science Course Catalog 2000-2001: This course is an introduction to objectoriented programming using the Java language.

More information