Using null type annotations in practice

Size: px
Start display at page:

Download "Using null type annotations in practice"

Transcription

1 Using null type annotations in practice Till Brychcy, Mercateo

2 What they are, why and when to use vs. java.util.optional Configuration choices Switching from declaration annotations to type annotations How to get warning free code - Code Patterns and Antipatterns Free Type variables and Arrays Improvements released with Oxygen Preview to Photon

3

4 Some Statistics First commit: Sep First commit with null annotations: Jul Switched to java 8 and null type annotations: Apr Sample size: 7866 java files (approx. 20% of total code base) 3025 files (no package annotations) annotation in 2175 files annotations in 709 files null")

5 Before null annotations /** * catalogid groupid searchspec * (may be null) minindex maxindex sortby sortascending String */

6 Null annotation advantages One thing less to worry about Code that is easier to understand, change and debug No more NullPointerException Fewer other bugs

7 Null annotations disadvantages Compiler sometimes needs help: Avoid some code patterns Syntax a bit ugly

8 Newer languages: nice syntax kotlin var x: String? = null; swift var x: String? = nil; c# (announced for version 8) string? x = null;

9 Null Annotations Normal + only for type parameters and during migration

10 Declaration vs. type annotations Declaration FIELD, METHOD, PARAMETER, LOCAL_VARIABLE }) Nullable { } Type TYPE_USE }) Nullable { } "Mixed" annotations are allowed by Java, but bad as null TYPE_USE, FIELD, METHOD, PARAMETER, LOCAL_VARIABLE }) Nullable { }

11 Declaration annotation public class Example String String add(@nullable String arg1, List<String> String[] array) { // just to show the syntax (local variables usually don't need String local = arg1; list.add(null); // is this OK? if(array!= null) { array[0] = null; // or this? } } } return local;

12 Equivalent with type FIELD, PARAMETER, RETURN_TYPE }) public class Example String String add(@nullable String arg1, List<String> list, [] array) { // just to show the syntax (local variables usually don't need String local = arg1; list.add(null); // is this OK? if(array!= null) { array[0] = null; // or this? } } } return local;

13 Completely FIELD, PARAMETER, RETURN_TYPE, ARRAY_CONTENTS, TYPE_ARGUMENT }) public class Example String String add(@nullable String arg1, List<@Nullable String> [] array) { // just to show the syntax (local variables usually don't need String local = arg1; list.add(null); // OK! if (array!= null) { array[0] = null; // OK! } } } return local;

14 @NonNullByDefault defaults public enum DefaultLocation { PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE }) NonNullByDefault { DefaultLocation[] value() default { DefaultLocation.PARAMETER, DefaultLocation.RETURN_TYPE, DefaultLocation.FIELD, DefaultLocation.TYPE_ARGUMENT, DefaultLocation.TYPE_BOUND }; }

15 Type bounds: "extends" Think in types: Object x = ""; // OK String s = new Object(); // String s1 = ""; // String s2 = null; // error "String extends Object" corresponds to "@NonNull String String" So: "@NonNull String Object" "@NonNull String Object" "@Nullable String Object"

16 Free Type variables and With class List<T> { } T can user chooses List<@Nullable Integer> or List<String> (=List<@NonNull String>) class NumberList<T extends Number>{ } T must same as class NumberList<T Number> same as NumberList<@NonNull T> class NumberList<@Nullable Number>: T must class NumberList<T Number>: T can

17 Principles Warning free in new code to existing code with other changes If necessary, annotate related is OK in certain situations Must be easy to use with maven (now: no maven settings at all, IDE-only)

18 @SuppressWarnings Generated code: hashcode & equals stream.filter(x->x!= null). optional.orelse(null) Tests (still Overrides for which we don t want to add external annotations

19 Configuration choices Enable annotations based analysis in workspace settings (not project) File template DefaultLocation as favorites External annotations added to the JDK in Workspace Hide INFO in problems view

20

21

22 Why custom annotations Different defaults (e.g. exclude for testing framework Easier to accept for users of other IDEs

23 Workspace-wide EEA for the JDK

24

25

26 Challenges when switching to type annotations Syntax for qualified names File file (easy to fix) Syntax for Arrays (we used some regular expressions) Generics: Map.get() (configure external annotations) Generics that take a.class literal

27 [] x; Problem during migration from declaration annotations Problem: String[10] contains nulls methods that don't care about nullness about array contents <T String concat(t[] strings)

28 Observed null parameter handling 1. Don't think about it, let method caller guess 2. if(param==null) return null 3. Objects.requireNonNull(param) 4. try{ }catch(exception e){ } 5. Assume nonnull, use javadoc for nullable

29 Some Antipatterns No correlation analysis boolean b=(x!= null); if(b) {x.somemethod()} int length = array == null? 0 : array.length; for (int i = 0; i < length; i++) No intraprocedural analysis: init( )-methods in constructor if(isvalid(x)) { x.something() } boolean isvalid(some x) {return x!= null && } Event callbacks without context: e.g., org.xml.sax.contenthandler Struts form beans some builder patterns

30 Some Good Patterns Empty string / collection / NOP-implementation instead of null final fields or even completely immutable fields Avoid null literals except to define class specific NULL constants

31 @Nullable vs. java.util.optional Two solutions for the same topic. "Don't care": Convenient mapping to other Optionals Code with Optional gets reliable so use both Use Optional only for return values Optional is not better when overriding methods Problem Optional#orElse (Guava had: #ornull)

32 Improvements in Oxygen 54 bug fixes and enhancements related to null analysis and null annotations Quick Fix to move type DefaultLocation.ARRAY_CONTENTS implemented No warning for "T String" Many quick assists avoid creating

33 extract local variable create local variable for missing symbol create field for missing symbol create parameter for missing symbol override method create method (parameters, details of return type) change method: (add parameter) change method: (change parameter) assign expression to new local variable create constructor using fields generate delegate methods create method type change and signature change introduce parameter object extract class

34 Preview to Photon Quick fix to to package Java in module-info.java Maybe support 3rd-party NonNullByDefault variations (TypeQualifierDefault) More quick assists that avoid creating

A Deep Dive into the Void

A Deep Dive into the Void A Deep Dive into the Void Java ready Advanced null Type Annotations Stephan Herrmann GK Software Stephan Herrmann: A Deep Dive into the Void - EclipseCon Europe 2014 # 2 An Old Problem 1965 Tony Hoare

More information

Annotations in Java. Jeszenszky, Péter University of Debrecen, Faculty of Informatics

Annotations in Java. Jeszenszky, Péter University of Debrecen, Faculty of Informatics Annotations in Java Jeszenszky, Péter University of Debrecen, Faculty of Informatics jeszenszky.peter@inf.unideb.hu Kocsis, Gergely (English version) University of Debrecen, Faculty of Informatics kocsis.gergely@inf.unideb.hu

More information

Annotations in Java. Jeszenszky, Péter University of Debrecen, Faculty of Informatics

Annotations in Java. Jeszenszky, Péter University of Debrecen, Faculty of Informatics Annotations in Java Jeszenszky, Péter University of Debrecen, Faculty of Informatics jeszenszky.peter@inf.unideb.hu Kocsis, Gergely (English version) University of Debrecen, Faculty of Informatics kocsis.gergely@inf.unideb.hu

More information

Using Type Annotations to Improve Your Code

Using Type Annotations to Improve Your Code Using Type Annotations to Improve Your Code Birds-of-a-Feather Session Werner Dietl, University of Waterloo Michael Ernst, University of Washington Open for questions Survey: Did you attend the tutorial?

More information

Topics in Object-Oriented Systems Item 35. Spring 2014 Chungnam National Univ Eun-Sun Cho

Topics in Object-Oriented Systems Item 35. Spring 2014 Chungnam National Univ Eun-Sun Cho Topics in Object-Oriented Systems Item 35 Spring 2014 Chungnam National Univ Eun-Sun Cho 1 1. Introduction 2. Creating and Destroying Objects 3. Methods Common to All Objects 4. Classes and Interfaces

More information

Code verification. CSE 331 University of Washington. Michael Ernst

Code verification. CSE 331 University of Washington. Michael Ernst Code verification CSE 331 University of Washington Michael Ernst Specification and verification To find an error, compare two things Mental model Verification Specification Program Example input & output

More information

JSR-305: Annotations for Software Defect Detection

JSR-305: Annotations for Software Defect Detection JSR-305: Annotations for Software Defect Detection William Pugh Professor Univ. of Maryland pugh@cs.umd.edu http://www.cs.umd.edu/~pugh/ 1 Why annotations? Static analysis can do a lot can even analyze

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Collections, Maps and Generics

Collections, Maps and Generics Collections API Collections, Maps and Generics You've already used ArrayList for exercises from the previous semester, but ArrayList is just one part of much larger Collections API that Java provides.

More information

The Checker Framework: pluggable static analysis for Java

The Checker Framework: pluggable static analysis for Java The Checker Framework: pluggable static analysis for Java http://checkerframework.org/ Werner Dietl University of Waterloo https://ece.uwaterloo.ca/~wdietl/ Joint work with Michael D. Ernst and many others.

More information

Metadata Features in Java SE 8

Metadata Features in Java SE 8 Metadata Features in Java SE 8 Joel Borggrén-Franck Java Platform Group Oracle @joelbf Metadata Features in Java SE 8 Joel Borggrén-Franck Java Platform Group Oracle @joelbf First, a message from our lawyers:

More information

Annotation File Specification

Annotation File Specification Annotation File Specification Javari Team MIT Computer Science and Artificial Intelligence Lab javari@csail.mit.edu October 2, 2007 1 Purpose: External storage of annotations Java annotations are meta-data

More information

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Familiarize yourself with all of Kotlin s features with this in-depth guide Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Copyright 2017 Packt Publishing First

More information

6.005 Elements of Software Construction Fall 2008

6.005 Elements of Software Construction Fall 2008 MIT OpenCourseWare http://ocw.mit.edu 6.005 Elements of Software Construction Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.005 elements

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

Swift. Introducing swift. Thomas Woodfin

Swift. Introducing swift. Thomas Woodfin Swift Introducing swift Thomas Woodfin Content Swift benefits Programming language Development Guidelines Swift benefits What is Swift Benefits What is Swift New programming language for ios and OS X Development

More information

Status Report. JSR-305: Annotations for Software Defect Detection. William Pugh Professor

Status Report. JSR-305: Annotations for Software Defect Detection. William Pugh Professor JSR-305: Annotations for Software Defect Detection William Pugh Professor Status Report Univ. of Maryland pugh@cs.umd.edu http://www.cs.umd.edu/~pugh/ 1 This JSR is under active development Slides have

More information

Enum Types. Built-in support for types of discrete values Advantages over C++ s enum: Type-safety Body can include methods and fields

Enum Types. Built-in support for types of discrete values Advantages over C++ s enum: Type-safety Body can include methods and fields Enum Types Built-in support for types of discrete values Advantages over C++ s enum: Enum declaration defines a class Type-safety Body can include methods and fields Values may be objects Support for iteration,

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

CSE 331 Software Design and Implementation. Lecture 16 Checker Framework

CSE 331 Software Design and Implementation. Lecture 16 Checker Framework CSE 331 Software Design and Implementation Lecture 16 Checker Framework Zach Tatlock / Winter 2016 Motivation java.lang.nullpointerexception Problem: Your code has bugs Who discovers the problems? If you

More information

Lecture 19 Checker Framework

Lecture 19 Checker Framework CSE 331 Software Design and Implementation Motivation Lecture 19 Checker Framework java.lang.nullpointerexception Zach Tatlock / Spring 2018 Problem: Your code has bugs Who discovers the problems? If you

More information

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley. CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia

More information

Mixed projects: Java + Kotlin. Svetlana Isakova

Mixed projects: Java + Kotlin. Svetlana Isakova Mixed projects: Java + Kotlin Svetlana Isakova Compilation of a mixed project *.kt kotlinc *.class *.jar *.java javac *.class Nullability Nullability Type =? Java Kotlin Nullability annotations @Nullable

More information

For this section, we will implement a class with only non-static features, that represents a rectangle

For this section, we will implement a class with only non-static features, that represents a rectangle For this section, we will implement a class with only non-static features, that represents a rectangle 2 As in the last lecture, the class declaration starts by specifying the class name public class Rectangle

More information

EECS168 Exam 3 Review

EECS168 Exam 3 Review EECS168 Exam 3 Review Exam 3 Time: 2pm-2:50pm Monday Nov 5 Closed book, closed notes. Calculators or other electronic devices are not permitted or required. If you are unable to attend an exam for any

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 15 testing ArrayIntList; pre/post conditions and exceptions reading: 4.4 15.1-15.3 2 Searching methods Implement the following methods: indexof returns first index of element,

More information

Review: Array Initializer Lists

Review: Array Initializer Lists More on Arrays Review of Arrays of ints, doubles, chars Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 7.2 Reading for this lecture: L&L 7.3 7.7,

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented

More information

Making Void Safety Practical

Making Void Safety Practical Making Void Safety Practical Alexander Kogtenkov 2017-06-26 Problem Overview of Void safety components Object initialization issue Examples Solutions Results 2 Problem expr.method (args); 3 Problem expr.method

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce Ch. 3, 8, 11, 15. Type Systems Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using

More information

CSE 331 Software Design and Implementation. Lecture 14 Generics 2

CSE 331 Software Design and Implementation. Lecture 14 Generics 2 CSE 331 Software Design and Implementation Lecture 14 Generics 2 James Wilcox / Winter 2016 Hi, I m James! Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping

More information

All code must follow best practices. Part (but not all) of this is adhering to the following guidelines:

All code must follow best practices. Part (but not all) of this is adhering to the following guidelines: Java Coding Guidelines Version 1.3.2 All code must follow best practices. Part (but not all) of this is adhering to the following guidelines: Development For code development, I recommend the following

More information

CS 360: Programming Languages Lecture 12: More Haskell

CS 360: Programming Languages Lecture 12: More Haskell CS 360: Programming Languages Lecture 12: More Haskell Geoffrey Mainland Drexel University Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia Administrivia Homework 5 due

More information

Arrays. COMS W1007 Introduction to Computer Science. Christopher Conway 10 June 2003

Arrays. COMS W1007 Introduction to Computer Science. Christopher Conway 10 June 2003 Arrays COMS W1007 Introduction to Computer Science Christopher Conway 10 June 2003 Arrays An array is a list of values. In Java, the components of an array can be of any type, basic or object. An array

More information

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science

Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science Marcin Luckner Warsaw University of Technology Faculty of Mathematics and Information Science mluckner@mini.pw.edu.pl http://www.mini.pw.edu.pl/~lucknerm } Annotations do not directly affect program semantics.

More information

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

(800) Toll Free (804) Fax   Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented

More information

FindBugs review of Glassfish v2 b09

FindBugs review of Glassfish v2 b09 FindBugs review of Glassfish v2 b09 William Pugh Univ. of Maryland http://www.cs.umd.edu/~pugh/ FindBugs Open source static analysis tool for finding defects in Java programs Analyzes classfiles Generates

More information

Annotation Hammer Venkat Subramaniam (Also published at

Annotation Hammer Venkat Subramaniam (Also published at Annotation Hammer Venkat Subramaniam venkats@agiledeveloper.com (Also published at http://www.infoq.com) Abstract Annotations in Java 5 provide a very powerful metadata mechanism. Yet, like anything else,

More information

Mod4j Application Architecture. Eric Jan Malotaux

Mod4j Application Architecture. Eric Jan Malotaux Mod4j Application Architecture Eric Jan Malotaux Mod4j Application Architecture Eric Jan Malotaux 1.2.0 Copyright 2008-2009 Table of Contents 1. Introduction... 1 1.1. Purpose... 1 1.2. References...

More information

Media Computation. Lecture 15.2, December 3, 2008 Steve Harrison

Media Computation. Lecture 15.2, December 3, 2008 Steve Harrison Media Computation Lecture 15.2, December 3, 2008 Steve Harrison Today -- new Stuff! Two kinds of methods: object class Creating Classes identifying objects and classes constructors adding a method, accessors

More information

Detecting and preventing null pointer errors with pluggable type-checking

Detecting and preventing null pointer errors with pluggable type-checking print(@readonly Object x) { List lst; Detecting and preventing null pointer errors with pluggable type-checking CSE 331 University of Washington Motivation java.lang.nullpointerexception

More information

Object-Oriented Concepts

Object-Oriented Concepts JAC444 - Lecture 3 Object-Oriented Concepts Segment 2 Inheritance 1 Classes Segment 2 Inheritance In this segment you will be learning about: Inheritance Overriding Final Methods and Classes Implementing

More information

Questions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?

Questions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C? Questions Exams: no Get by without own Mac? Why ios? ios vs Android restrictions Selling in App store how hard to publish? Future of Objective-C? Grading: Lab/homework: 40%, project: 40%, individual report:

More information

interface MyAnno interface str( ) val( )

interface MyAnno interface str( ) val( ) Unit 4 Annotations: basics of annotation-the Annotated element Interface. Using Default Values, Marker Annotations. Single-Member Annotations. The Built-In Annotations-Some Restrictions. 1 annotation Since

More information

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM Objectives Defining a wellformed method to check class invariants Using assert statements to check preconditions,

More information

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, November 2017

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, November 2017 News in RSA-RTE 10.1 updated for sprint 2017.46 Mattias Mohlin, November 2017 Overview Now based on Eclipse Neon.3 (4.6.3) Many general improvements since Eclipse Mars Contains everything from RSARTE 10

More information

Classes, interfaces, & documentation. Review of basic building blocks

Classes, interfaces, & documentation. Review of basic building blocks Classes, interfaces, & documentation Review of basic building blocks Objects Data structures literally, storage containers for data constitute object knowledge or state Operations an object can perform

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM CS 215 Software Design Homework 3 Due: February 28, 11:30 PM Objectives Specifying and checking class invariants Writing an abstract class Writing an immutable class Background Polynomials are a common

More information

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do: Project MindNumber Collaboration: Solo. Complete this project by yourself with optional help from section leaders. Do not work with anyone else, do not copy any code directly, do not copy code indirectly

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple

More information

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004 Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

CSE 331 Software Design and Implementation. Lecture 14 Generics 2

CSE 331 Software Design and Implementation. Lecture 14 Generics 2 CSE 331 Software Design and Implementation Lecture 14 Generics 2 Zach Tatlock / Spring 2018 Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping Using wildcards

More information

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1 CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Singleton Pattern Mar. 13, 2007 What is it? If you need to make sure that there can be one and only one instance of a class. For example,

More information

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, January 2018

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, January 2018 News in RSA-RTE 10.1 updated for sprint 2018.03 Mattias Mohlin, January 2018 Overview Now based on Eclipse Neon.3 (4.6.3) Many general improvements since Eclipse Mars Contains everything from RSARTE 10

More information

Inheritance (Part 5) Odds and ends

Inheritance (Part 5) Odds and ends Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there

More information

Information systems modeling. Tomasz Kubik

Information systems modeling. Tomasz Kubik Information systems modeling Tomasz Kubik Data Access Objects Pattern https://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm Spring framework https://projects.spring.io/spring-framework/

More information

Announcements. Lecture 14 Generics 1. Announcements. CSE 331 Software Design and Implementation. Leah Perlmutter / Summer 2018

Announcements. Lecture 14 Generics 1. Announcements. CSE 331 Software Design and Implementation. Leah Perlmutter / Summer 2018 CSE 331 Software Design and Implementation Lecture 14 Generics 1 Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 5 is due Thursday Homework 6 due Thursday Midterm grades and feedback will

More information

CSE 331 Software Design and Implementation. Lecture 14 Generics 1

CSE 331 Software Design and Implementation. Lecture 14 Generics 1 CSE 331 Software Design and Implementation Lecture 14 Generics 1 Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 5 is due Thursday Homework 6 due Thursday Midterm grades and feedback will

More information

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7

Javadoc. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 7 Javadoc Computer Science and Engineering College of Engineering The Ohio State University Lecture 7 Motivation Over the lifetime of a project, it is easy for documentation and implementation to diverge

More information

Atelier Java - J2. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J2. Marwan Burelle.   EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 1 2 Notions of interfaces describe what an object must provide without describing how. It extends the types name strategy to provide

More information

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Garbage Collection (1)

Garbage Collection (1) Coming up: Today: Finish unit 6 (garbage collection) start ArrayList and other library objects Wednesday: Complete ArrayList, basics of error handling Friday complete error handling Next week: Recursion

More information

Java Concepts: Compatible With Java 5, 6 And 7 By Cay S. Horstmann

Java Concepts: Compatible With Java 5, 6 And 7 By Cay S. Horstmann Java Concepts: Compatible With Java 5, 6 And 7 By Cay S. Horstmann Java Concepts: Compatible with Java 5, 6 and 7 by Horstmann, Cay S. and a great selection of similar Used, New and Collectible Books available

More information

Scala Style Guide Spring 2018

Scala Style Guide Spring 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Scala Style Guide Spring 2018 Contents 1 Introduction 1 2 Naming 1 3 Formatting 2 4 Class Declarations 3 5 Functional Paradigms 4 6 Comments

More information

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/

More information

Welcome to CSSE 220. We are excited that you are here:

Welcome to CSSE 220. We are excited that you are here: Welcome to CSSE 220 We are excited that you are here: Start your computer Do NOT start Eclipse Follow the instructions in the email, if you haven t already Pick up a quiz from the back table Answer the

More information

Topic 9: Type Checking

Topic 9: Type Checking Recommended Exercises and Readings Topic 9: Type Checking From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 13.17, 13.18, 13.19, 13.20, 13.21, 13.22 Readings: Chapter 13.5, 13.6 and

More information

Topic 9: Type Checking

Topic 9: Type Checking Topic 9: Type Checking 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 13.17, 13.18, 13.19, 13.20, 13.21, 13.22 Readings: Chapter 13.5, 13.6

More information

Kotlin for Android Developers

Kotlin for Android Developers Kotlin for Android Developers Learn Kotlin the easy way while developing an Android App Antonio Leiva This book is for sale at http://leanpub.com/kotlin-for-android-developers This version was published

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

An introduction to formal specifications and JML. Invariant properties

An introduction to formal specifications and JML. Invariant properties An introduction to formal specifications and JML Invariant properties Yves Ledru Université Grenoble-1 Laboratoire d Informatique de Grenoble Yves.Ledru@imag.fr 2013 Page 1 Invariant properties Invariants

More information

COURSE 2 DESIGN PATTERNS

COURSE 2 DESIGN PATTERNS COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

CSE 331 Midterm Exam Sample Solution 2/18/15

CSE 331 Midterm Exam Sample Solution 2/18/15 Question 1. (10 points) (Forward reasoning) Using forward reasoning, write an assertion in each blank space indicating what is known about the program state at that point, given the precondition and the

More information

Lecture Questions. Types (binary expressions, etc). Refactoring, abstraction, better engineering. Testing. Error message generation/suppression.

Lecture Questions. Types (binary expressions, etc). Refactoring, abstraction, better engineering. Testing. Error message generation/suppression. . p.1/39 Today 1. Specific questions and discussion from lecture. 2. Types: overloading, subtypes, and coercion. 3. Testing: structure and stress. 4. Objects: when, how, and why? 5. Top-down vs. bottom-up

More information

Not overriding equals

Not overriding equals Not overriding equals what happens if you do not override equals for a value type class? all of the Java collections will fail in confusing ways 1 Not overriding equals Complex y = new Complex(1, -2);

More information

3 ADT Implementation in Java

3 ADT Implementation in Java Object-Oriented Design Lecture 3 CS 3500 Spring 2010 (Pucella) Tuesday, Jan 19, 2010 3 ADT Implementation in Java Last time, we defined an ADT via a signature and a specification. We noted that the job

More information

Programming Languages

Programming Languages CSE 130 : Winter 2009 Programming Languages News PA 2 out, and due Mon 1/26 5pm Lecture 5: Functions and Datatypes t UC San Diego Recap: Environments Phone book Variables = names Values = phone number

More information

A Deep Dive Into Kotlin

A Deep Dive Into Kotlin A Deep Dive Into Kotlin By 1 About me (droidyue.com) @Flipboard China GDG 2 3 Kotlin An official language for Android recently Powered by Jetbrains 4 Why Kotlin Concise Safe interoperable tool-friendly

More information

The Checker Framework Manual

The Checker Framework Manual The Checker Framework Manual http://pag.csail.mit.edu/jsr308/ Version 0.9.6 (29 Jul 2009) For the impatient: Section 1.2 describes how to install and use pluggable type-checkers. Contents 1 Introduction

More information

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs. Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java

More information

Java Programming Training for Experienced Programmers (5 Days)

Java Programming Training for Experienced Programmers (5 Days) www.peaklearningllc.com Java Programming Training for Experienced Programmers (5 Days) This Java training course is intended for students with experience in a procedural or objectoriented language. It

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

Apache NetBeans 9.0 New and Noteworthy

Apache NetBeans 9.0 New and Noteworthy Apache NetBeans 9.0 New and Noteworthy Note: NetBeans 9 is a work in progress and not released yet. Below is a list of features it will have. NetBeans 9 runtime platforms are only JDK8 and JDK9. Until

More information

Pointers and Memory 1

Pointers and Memory 1 Pointers and Memory 1 Pointer values Pointer values are memory addresses Think of them as a kind of integer values The first byte of memory is 0, the next 1, and so on A pointer p can hold the address

More information

18-642: Code Style for Compilers

18-642: Code Style for Compilers 18-642: Code Style for Compilers 9/25/2017 1 Anti-Patterns: Coding Style: Language Use Code compiles with warnings Warnings are turned off or over-ridden Insufficient warning level set Language safety

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented

More information

Detecting and preventing null pointer errors with pluggable type-checking

Detecting and preventing null pointer errors with pluggable type-checking print(@readonly Object x) { List lst; Detecting and preventing null pointer errors with pluggable type-checking Michael Ernst CSE 331 University of Washington Motivation java.lang.nullpointerexception

More information

COE318 Lecture Notes Week 10 (Nov 7, 2011)

COE318 Lecture Notes Week 10 (Nov 7, 2011) COE318 Software Systems Lecture Notes: Week 10 1 of 5 COE318 Lecture Notes Week 10 (Nov 7, 2011) Topics More about exceptions References Head First Java: Chapter 11 (Risky Behavior) The Java Tutorial:

More information

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

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd.

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd. C++11: 10 Features You Should be Using Gordon Brown @AerialMantis R&D Runtime Engineer Codeplay Software Ltd. Agenda Default and Deleted Methods Static Assertions Delegated and Inherited Constructors Null

More information