Advanced Programming Languages Effective Java Item 1. Spring 2015 Chungnam National Univ Eun-Sun Cho

Size: px
Start display at page:

Download "Advanced Programming Languages Effective Java Item 1. Spring 2015 Chungnam National Univ Eun-Sun Cho"

Transcription

1 Advanced Programming Languages Effective Java Item 1 Spring 2015 Chungnam National Univ Eun-Sun Cho 1

2 1. Introduction 2. Creating and Destroying Objects Item 1: Consider static factory methods instead of constructors Item 2: Consider a builder when faced with many constructor parameters Item 3: Enforce the singleton property with a private constructor or an enum type Item 4: Enforce noninstantiability with a private constructor Item 5: Avoid creating unnecessary objects Item 6: Eliminate obsolete object references Item 7: Avoid finalizers 2

3 Item 1 Consider static factory methods instead of constructors 3

4 Motivation Examples class Boolean { } private final boolean value; public static final Boolean TRUE = new Boolean(true); public static final Boolean FALSE = new Boolean(false); public Boolean(boolean value){ this.value = value; } Usage Boolean condition = null; if (1 == 1) condition = new Boolean(true); else condition = new Boolean(false); if (condition == new Boolean(true)) // always false.. Why? 4

5 Notes: Checks on Basics Two separate type systems in Java values vs. objects (what is an object?) cf. boxing/unboxing Initializing instance variables in Java Execution sequence of a constructor Final instance variables in Java Reference equality 5

6 Motivation Examples conts class Boolean { } private final boolean value; public static final Boolean TRUE = new Boolean(true); public static final Boolean FALSE = new Boolean(false); public Boolean(boolean value){ this.value = value; } Usage Boolean condition = null; if (1 == 1) condition = Boolean.TRUE; else condition = Boolean.FALSE; if (condition == Boolean.TRUE) // true. <- good if (condition == new Boolean(true)) // true? false? 6

7 Related Codes in APIs public final class Boolean implements java.io.serializable, Comparable<Boolean> { private final boolean value; public static final Boolean TRUE = new Boolean(true); public static final Boolean FALSE = new Boolean(false); public static Boolean valueof(boolean b) { return (b? TRUE : FALSE); } // Unless a new instance is required, the static factory valueof(boolean) is generally a better choice. It is likely to yield significantly better space and time performance. } public Boolean(boolean value){ this.value = value; } 7

8 Static Factory Method (SFM) A static method that returns an instance of a class Similar to constructors public final class Boolean.. { }... public static Boolean valueof(boolean b) { return (b? TRUE : FALSE); } 8

9 1. Have names Advantages of SFMs Over Constructors 2. Not required to create a new object each time 3. Return an object of any subtype of their return type 4. Reduce the verbosity of creating parameterized type instances. 9

10 1. Have names Advantages of SFMs Over Constructors easier to use and read eg. Constructor BigInteger(int, int, Random) emits a probable prime number object. Bad readability SFM BigInteger.probablePrime() solves the problem (from 1.4) multiple methods with a given signature eg. If a programmar wants to make more than one different constructors of class A with int and boolean, what he/she can do is to create A(int, boolean) and A(boolean, int). poor readability and non-determinism Two SFMs with different names would solve this problem 10

11 Advantages of SFMs conts Over Constructors 2. Not required to create a new object each time preserve immutability (Item 15) avoid creating unnecessary duplicate objects control the number of instances Why do we need instance-control? 1) singleton (Item 3) 2) noninstantiable (Item 4) 3) immutable class (Item 15) 4) to keep equality constraint like a.equals(b) a == b for performance improvement eg, Enum types improve performance space and time (by caching) easy to check equality (by reference equality) 11

12 Advantages of SFMs conts Over Constructors 3. Return an object of any subtype of their return type create objects without making their classes public hide implementation classes enable interface-based framework s (Item 18) BTW, an interface cannot have static method. solved by interface Type and a noninstantiable class Types (see Item 4) (See More Examples *Later*) 12

13 Advantages of SFMs conts Over Constructors 4. Reduce the verbosity of creating parameterized type instances. Note: basic generic type specification principle (from 1.5) Set<String> s = new HashSet<String>(); // variable types and object creations need type parameters s.add( dumb ); // method invocations do not need type parameters Thus, SFM does not need type parameters while a constructors does Map<String, List<String>> m = new HashMap<String, List<String>> (); vs. Map<String, List<String>> m = HashMap.newInstance(); 13

14 Advantages of SFMs conts Over Constructors 4. Reduce the verbosity of creating parameterized type instances. The Truth (1) Actually, following SFM is not provided in HashMap public static <K, V> HashMap<K, V> newinstance() {return new HashMap<K, V>();} (2) Now, type inference for generic object creation is supported (from 1.7) Map<String, List<String>> mymap = new HashMap<>(); 14

15 More on Advantage #3 of SFM 3. Returning an Object of Subtype of Their Return Type Examples 1) JCF (Java Collection Frameworks) 2) java.util.enumset 3) Service Provider Framework JDBC (Java Database Connection API) JCE (Java Cryptography Extension) 15

16 Example 1 JCF (Java Collection Frameworks) The Java Collections Framework (JCF) eg. class java.util.collections The result of method ncopies() is an instance of interface List but we do not have to know which class (i.e. implementation) of the List it belongs to. ArrayList? LinkedList? Vector? achieves smaller conceptual weight! 16

17 more on JCF (Java Collections Framework) The core collection interfaces General-purpose Implementations Interfaces Hash table Resizable array Implementations Tree Linked list Hash table + Linked list Set HashSet TreeSet LinkedHashSet List ArrayList LinkedList Queue Deque ArrayDeque LinkedList Map HashMap TreeMap LinkedHashMap 17

18 more on JCF (Java Collections Framework) conts JCF reduced the bulk of API but also conceptual weight conceptual weight (mentioned by Bloch) minimize developers overhead of learning new abstract concepts API Should Be As Small As Possible But No Smaller General principles for APIs API should satisfy its requirements When in doubt leave it out Functionality, classes, methods, parameters, etc. You can always add, but you can never remove Conceptual weight more important than bulk Look for a good power-to-weight ratio by Bloch 18

19 Example 2 java.util.enumset abstract class java.util.enumset (from 1.5) represents a set of enum doesn t have public constructors only with static factories two implementations : RegularEnumSet and JumboEnumSet public static <E extends Enum<E>> EnumSet<E> noneof(class<e> elementtype) { //static factory method //Creates an empty enum set with the specified element type.... if (universe.length <= 64) return new RegularEnumSet<E>(elementType, universe); else return new JumboEnumSet<E>(elementType, universe); } 19

20 Example 3 Service Provider Framework Service provider framework : multiple service providers implements a service implementations are available to clients three essential components service interface : service-specific methods that providers implement. provider registration API : system uses to register implementations service access API : clients use to obtain an instance of the service (optional) service provider interface: providers implement to create instances of their service implementation 20

21 // Service interface public interface Service {... // Service-specific methods go here } // Service provider interface public interface Provider { Service newservice(); } // Noninstantiable class for service registration and access public class Services { private Services() { } // Prevents instantiation (Item 4) // Maps service names to services private static final Map<String, Provider> providers = new ConcurrentHashMap<String, Provider>(); public static final String DEFAULT_PROVIDER_NAME = "<def>"; // Provider registration API public static void registerdefaultprovider(provider p) { registerprovider(default_provider_name, p); } public static void registerprovider(string name, Provider p) { providers.put(name, p);} // Service access API public static Service newinstance() {return newinstance(default_provider_name); } public static Service newinstance(string name) { Provider p = providers.get(name); if (p == null) throw new IllegalArgumentException( "No provider registered with name: " + name); return p.newservice(); } } 21

22 Example 3 Service Provider Framework conts JDBC (Java Database Connectivity API) service provider interface service interface Driver adriver = new oracle.jdbc.driver.oracledriver(); DriverManager.registerDriver( adriver ); // or Class.forName( oracle.jdbc.driver.oracledriver ); provider registration String URL = "jdbc:oracle:thin:@amrood:1521:emp"; API String USER = "username"; String PASS = "password ; Connection conn = DriverManager.getConnection(URL, USER, PASS); service access API Statement stmt = conn.createstatement(); String sql= "SELECT id, first, last, age FROM Employees"; ResultSet rs = stmt.executequery(sql); while(rs.next()){ int id = rs.getint( id"); int age =... 22

23 Example 3 Service Provider Framework conts JCE (Java Cryptography Extension) a framework/implementation for encryption, key generation and key agreement, and etc. eg. user (sender) // MessageDigest md = MessageDigest.getInstance( SHA ); //for default usage MessageDigest md = MessageDigest.getInstance( SHA", "ProviderCNU"); ObjectOutputStream oos = new ObjectOutputStream ( new FileOutputStream( test )); String data = This is a sentence. + It is really long. ; oos.writeobject(data); byte[] buf = data.getbytes(); md.update(buf); oos.writeobject(md.digest()); eg. fill provider interface public class ProviderCNU extends Provider { public ProviderCNU () { super( CNU, 1.0, CNU Security Provider v1.0 ); put names of the classes put( KeyGenerator.CNU, kr.ac.cnu.plas.cnukeygenerator ); put( MessageDigest.CNU, kr.ac.cnu.plas.cnumessagedigest );...}}

24 eg. by user (receiver) ObjectInputStream ois = new ObjectInputStream(new FileInputStream( test )); // read delivered data Object o = ois.readobject(); if (!(o instanceof String)) { System.out.println( Unexpected Data in file ); System.exit(-1); } String data = (String) o; // read delivered md value o = ois.readobject(); if (!(o instanceof byte[])) { System.out.println( Unexpected Data in file ); System.exit(-1); } byte[] origdigest = (byte[]) o; // check md md = MessageDigest.getInstance( SHA, ProviderCNU ); md.update(data.getbytes()); if (MessageDigest.isEqual(md.digest(), origdigest)) System.out.println( Message is valid ); else System.our.println( Message was corrupted. ); }catch (Exception e) { System.out.println(e);} 24

25 Example 3 Service Provider Framework conts Comparisons service interface provider registration API service access API service provider interface JDBC class Connection DriverManager.registerDriver() DriverManager.getConnection() class Driver JCE class MessageDigest put() in constructors of class Provider and more MessageDigest.getInstance() class Provider 25

26 Disadvantages of SFMs Compared to Constructors 1. Classes without public or protected constructors cannot be subclassed cf. favor composition over inheritance (Item 16) 2. Not readily distinguishable from other static methods SFMs represent a deviation from the norm solutions adhering to standard naming conventions (e.g. valueof, getinstance and etc.) 26

27 valueof Returns an instance that has, loosely speaking, the same value as its parameters. Such static factories are effectively type-conversion methods. of A concise alternative to valueof, popularized by EnumSet (Item 32). getinstance Returns an instance that is described by the parameters but cannot be said to have the same value. In the case of a singleton, getinstance takes no parameters and returns the sole instance. newinstance Like getinstance, except that newinstance guarantees that each instance returned is distinct from all others. gettype Like getinstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method. newtype Like newinstance, but used when the factory method is in a different class. Type indicates the type of object returned by the factory method. 27

28 Related Design Patterns Flyweight Pattern minimizes memory use by sharing as much data as possible with other similar objects; greatly improve performance if equivalent objects are requested often, especially if they are expensive to create Adapter Pattern translates one interface for a class into a compatible interface. service access API in Service Provider Framework can return a richer service interface than the one required of the provider using this pattern 28

Core Java Contents. Duration: 25 Hours (1 Month)

Core Java Contents. Duration: 25 Hours (1 Month) Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java

More information

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6 Computational Applications in Nuclear Astrophysics using Java Java course Lecture 6 Prepared for course 160410/411 Michael C. Kunkel m.kunkel@fz-juelich.de Materials taken from; docs.oracle.com Teach Yourself

More information

Learn Java/J2EE Basic to Advance level by Swadeep Mohanty

Learn Java/J2EE Basic to Advance level by Swadeep Mohanty Basics of Java Java - What, Where and Why? History and Features of Java Internals of Java Program Difference between JDK,JRE and JVM Internal Details of JVM Variable and Data Type OOPS Conecpts Advantage

More information

Topic 10: The Java Collections Framework (and Iterators)

Topic 10: The Java Collections Framework (and Iterators) Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of

More information

Complete Java Contents

Complete Java Contents Complete Java Contents Duration: 60 Hours (2.5 Months) Core Java (Duration: 25 Hours (1 Month)) Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing

More information

JAVA. Duration: 2 Months

JAVA. Duration: 2 Months JAVA Introduction to JAVA History of Java Working of Java Features of Java Download and install JDK JDK tools- javac, java, appletviewer Set path and how to run Java Program in Command Prompt JVM Byte

More information

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server.

JDBC Drivers Type. JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server. JDBC Drivers Type 1 What is JDBC Driver? JDBC drivers implement the defined interfaces in the JDBC API for interacting with your database server. For example, using JDBC drivers enable you to open database

More information

JAVA. 1. Introduction to JAVA

JAVA. 1. Introduction to JAVA JAVA 1. Introduction to JAVA History of Java Difference between Java and other programming languages. Features of Java Working of Java Language Fundamentals o Tokens o Identifiers o Literals o Keywords

More information

Java Collections Framework

Java Collections Framework Java Collections Framework Introduction In this article from my free Java 8 course, you will be given a high-level introduction of the Java Collections Framework (JCF). The term Collection has several

More information

Fundamental language mechanisms

Fundamental language mechanisms Java Fundamentals Fundamental language mechanisms The exception mechanism What are exceptions? Exceptions are exceptional events in the execution of a program Depending on how grave the event is, the program

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

Credit is where Credit is Due. Lecture 28: OO Design Heuristics (Part 2) This Lecture. Last Lecture: OO Heuristics. Rules of Thumb

Credit is where Credit is Due. Lecture 28: OO Design Heuristics (Part 2) This Lecture. Last Lecture: OO Heuristics. Rules of Thumb Credit is where Credit is Due Lecture 28: OO Design Heuristics (Part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some material for this lecture is taken

More information

Collections Framework: Part 2

Collections Framework: Part 2 Collections Framework: Part 2 Computer Science and Engineering College of Engineering The Ohio State University Lecture 18 Collection Implementations Java SDK provides several implementations of Collection

More information

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the Answers 1) B 2) C 3) A 4) D 5) Non-static members 6) Static members 7) Default 8) abstract 9) Local variables 10) Data type default value 11) Data type default value 12) No 13) No 14) Yes 15) No 16) No

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Hal Perkins Autumn 2013 Design Patterns I (Slides by Mike Ernst and David Notkin) 1 Outline Introduction to design patterns Creational patterns (constructing objects)

More information

Today's Agenda. > To give a practical introduction to data structures. > To look specifically at Lists, Sets, and Maps

Today's Agenda. > To give a practical introduction to data structures. > To look specifically at Lists, Sets, and Maps Today's Agenda > To give a practical introduction to data structures > To look specifically at Lists, Sets, and Maps > To talk briefly about Generics in Java > To talk about interfaces in Java Data Structures

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2 Online Resources

More information

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Database Connection Budditha Hettige Department of Statistics and Computer Science Budditha Hettige 1 From database to Java There are many brands of database: Microsoft

More information

Section 8: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst

Section 8: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst Section 8: Design Patterns Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst Announcements HW8 due tonight 10 pm Quiz 7 due tonight 10 pm Industry guest speaker tomorrow!

More information

Section 9: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst

Section 9: Design Patterns. Slides by Alex Mariakakis. with material from David Mailhot, Hal Perkins, Mike Ernst Section 9: Design Patterns Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst What Is A Design Pattern A standard solution to a common programming problem A technique for

More information

Collections. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Collections. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff Collections by Vlad Costel Ungureanu for Learn Stuff Collections 2 Collections Operations Add objects to the collection Remove objects from the collection Find out if an object (or group of objects) is

More information

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

5/23/2015. Core Java Syllabus. VikRam ShaRma 5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5

More information

Interfaces. An interface defines a set of methods. An interface declaration contains signatures, but no implementations.

Interfaces. An interface defines a set of methods. An interface declaration contains signatures, but no implementations. Interface Interface definition Interface implementation by classes Benefits of interfaces Implementation of multiple interface Java Collection Framework Interfaces An interface defines a set of methods.

More information

Top Down Design vs. Modularization

Top Down Design vs. Modularization 6.170 Quiz Review Topics: 1. Decoupling 2. 3. AF & RI 4. Iteration Abstraction & Iterators 5. OMs and Invariants 6. Equality, Copying, Views 7. 8. Design Patterns 9. Subtyping 10. Case Studies Decomposition

More information

USAL1J: Java Collections. S. Rosmorduc

USAL1J: Java Collections. S. Rosmorduc USAL1J: Java Collections S. Rosmorduc 1 A simple collection: ArrayList A list, implemented as an Array ArrayList l= new ArrayList() l.add(x): adds x at the end of the list l.add(i,x):

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

Advanced Programming Generics Collections

Advanced Programming Generics Collections Advanced Programming Generics Collections The Context Create a data structure that stores elements: a stack, a linked list, a vector a graph, a tree, etc. What data type to use for representing the elements

More information

Collections (Java) Collections Framework

Collections (Java) Collections Framework Collections (Java) https://docs.oracle.com/javase/tutorial/collections/index.html Collection an object that groups multiple elements into a single unit. o store o retrieve o manipulate o communicate o

More information

CMSC 132: Object-Oriented Programming II. Effective Java. Department of Computer Science University of Maryland, College Park

CMSC 132: Object-Oriented Programming II. Effective Java. Department of Computer Science University of Maryland, College Park CMSC 132: Object-Oriented Programming II Effective Java Department of Computer Science University of Maryland, College Park Effective Java Textbook Title Effective Java, Second Edition Author Joshua Bloch

More information

Implementation. (Mapping to Java) Jörg Kienzle & Alfred Strohmeier. COMP-533 Implementation

Implementation. (Mapping to Java) Jörg Kienzle & Alfred Strohmeier. COMP-533 Implementation Implementation (Mapping to Java) Jörg Kienzle & Alfred Strohmeier COMP-533 Implementation Datatype Enumeration Class Attribute Association Inheritance Method Visibility Collections Overview 2 Data Type

More information

182 review 1. Course Goals

182 review 1. Course Goals Course Goals 182 review 1 More experience solving problems w/ algorithms and programs minimize static methods use: main( ) use and overload constructors multiple class designs and programming solutions

More information

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS Core Java SYLLABUS COVERAGE Introduction. OOPS Package Exception Handling. Multithreading Applet, AWT, Event Handling Using NetBean, Ecllipse. Input Output Streams, Serialization Networking Collection

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

CSE 331 Final Exam 3/12/12

CSE 331 Final Exam 3/12/12 Name There are 12 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information

Outline of today s class. Design Patterns. Classes and Inheritance. Aside: UML Class Diagrams

Outline of today s class. Design Patterns. Classes and Inheritance. Aside: UML Class Diagrams Outline of today s class Unified Modeling Language (UML) Design Patterns Based on material by Michael Ernst, University of Washington Design patterns Intro to design patterns Creational patterns Factories:

More information

Singleton Pattern Creational

Singleton Pattern Creational Singleton Pattern Creational Intent» Ensure a class has only one instance» Provide a global point of access Motivation Some classes must only have one instance file system, window manager Applicability»

More information

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim ERwin and JDBC Mar. 6, 2007 Myoung Ho Kim ERwin ERwin a popular commercial ER modeling tool» other tools: Dia (open source), Visio, ConceptDraw, etc. supports database schema generation 2 ERwin UI 3 Data

More information

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started Application Development in JAVA Duration Lecture: Specialization x Hours Core Java (J2SE) & Advance Java (J2EE) Detailed Module Part I: Core Java (J2SE) Getting Started What is Java all about? Features

More information

Java SE 8 Programming

Java SE 8 Programming Oracle University Contact Us: Local: 1800 103 4775 Intl: +91 80 67863102 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features

More information

Java SE 8 Programming

Java SE 8 Programming Oracle University Contact Us: +52 1 55 8525 3225 Java SE 8 Programming Duration: 5 Days What you will learn This Java SE 8 Programming training covers the core language features and Application Programming

More information

CSE 331 Software Design and Implementation. Lecture 20 Design Patterns 1

CSE 331 Software Design and Implementation. Lecture 20 Design Patterns 1 CSE 331 Software Design and Implementation Lecture 20 Design Patterns 1 Leah Perlmutter / Spring 2018 Outline Introduction to design patterns Creational patterns (constructing objects) Next lecture: Structural

More information

Core Java Syllabus. Overview

Core Java Syllabus. Overview Core Java Syllabus Overview Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java

More information

JAVA SYLLABUS FOR 6 WEEKS

JAVA SYLLABUS FOR 6 WEEKS JAVA SYLLABUS FOR 6 WEEKS Java 6-Weeks INTRODUCTION TO JAVA History and Features of Java Comparison of C, C++, and Java Java Versions and its domain areas Life cycle of Java program Writing first Java

More information

Java Collections Framework. 24 April 2013 OSU CSE 1

Java Collections Framework. 24 April 2013 OSU CSE 1 Java Collections Framework 24 April 2013 OSU CSE 1 Overview The Java Collections Framework (JCF) is a group of interfaces and classes similar to the OSU CSE components The similarities will become clearly

More information

Software Practice 1 - OOP (3) API Access Control Review Packages Java API Documentation

Software Practice 1 - OOP (3) API Access Control Review Packages Java API Documentation 1 Software Practice 1 - OOP (3) API Access Control Review Packages Java API Documentation Prof. Hwansoo Han T.A. Jeonghwan Park 41 T.A. Sung-in Hong 42 ACCESS CONTROL REVIEW 2 3 Access Control - Bad public

More information

Software Practice 1 - OOP (3) API

Software Practice 1 - OOP (3) API Software Practice 1 - OOP (3) API Access Control Review Packages Java API Documentation Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee (43) 1 / 41 2 / 41 ACCESS CONTROL

More information

Design Patterns (1) CSE 331 University of Washington

Design Patterns (1) CSE 331 University of Washington Design Patterns (1) CSE 331 University of Washington Outline Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout) Behavioral patterns

More information

Peers Techno log ies Pv t. L td. Core Java & Core Java &Adv Adv Java Java

Peers Techno log ies Pv t. L td. Core Java & Core Java &Adv Adv Java Java Page 1 Peers Techno log ies Pv t. L td. Course Brochure Core Java & Core Java &Adv Adv Java Java Overview Core Java training course is intended for students without an extensive programming background.

More information

CS61BL Summer 2013 Midterm 2

CS61BL Summer 2013 Midterm 2 CS61BL Summer 2013 Midterm 2 Sample Solutions + Common Mistakes Question 0: Each of the following cost you.5 on this problem: you earned some credit on a problem and did not put your five digit on the

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 4: Generic Type and Collections Stéphane Airiau Université Paris-Dauphine Lesson 4: Generic Type and Collections (Stéphane Airiau) Java 1 Linked List 1 public class Node

More information

Cloning Enums. Cloning and Enums BIU OOP

Cloning Enums. Cloning and Enums BIU OOP Table of contents 1 Cloning 2 Integer representation Object representation Java Enum Cloning Objective We have an object and we need to make a copy of it. We need to choose if we want a shallow copy or

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 3 Online Resources

More information

Java SE 8 Programming

Java SE 8 Programming Java SE 8 Programming Training Calendar Date Training Time Location 16 September 2019 5 Days Bilginç IT Academy 28 October 2019 5 Days Bilginç IT Academy Training Details Training Time : 5 Days Capacity

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Java: exceptions and genericity

Java: exceptions and genericity Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: exceptions and genericity Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exceptions Exceptions

More information

This lecture. Databases - JDBC I. Application Programs. Database Access End Users

This lecture. Databases - JDBC I. Application Programs. Database Access End Users This lecture Databases - I The lecture starts discussion of how a Java-based application program connects to a database using. (GF Royle 2006-8, N Spadaccini 2008) Databases - I 1 / 24 (GF Royle 2006-8,

More information

PIC 20A Collections and Data Structures

PIC 20A Collections and Data Structures PIC 20A Collections and Data Structures Ernest Ryu UCLA Mathematics Last edited: March 14, 2018 Introductory example How do you write a phone book program? Some programmers may yell hash table! and write

More information

CSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,

CSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding

More information

TECHNICAL WHITEPAPER. Performance Evaluation Java Collections Framework. Performance Evaluation Java Collections. Technical Whitepaper.

TECHNICAL WHITEPAPER. Performance Evaluation Java Collections Framework. Performance Evaluation Java Collections. Technical Whitepaper. Performance Evaluation Java Collections Framework TECHNICAL WHITEPAPER Author: Kapil Viren Ahuja Date: October 17, 2008 Table of Contents 1 Introduction...3 1.1 Scope of this document...3 1.2 Intended

More information

Java Collections Framework reloaded

Java Collections Framework reloaded Java Collections Framework reloaded October 1, 2004 Java Collections - 2004-10-01 p. 1/23 Outline Interfaces Implementations Ordering Java 1.5 Java Collections - 2004-10-01 p. 2/23 Components Interfaces:

More information

CSE 331 Final Exam 3/16/15 Sample Solution

CSE 331 Final Exam 3/16/15 Sample Solution Question 1. (12 points, 3 each) A short design exercise. Suppose Java did not include a Set class in the standard library and we need to store a set of Strings for an application. We know that the maximum

More information

What is Serialization?

What is Serialization? Serialization 1 Topics What is Serialization? What is preserved when an object is serialized? Transient keyword Process of serialization Process of deserialization Version control Changing the default

More information

PVS. Empirical Study of Usage and Performance of Java Collections. Diego Costa, 1 Artur Andrzejak, 1 Janos Seboek, 2 David Lo

PVS. Empirical Study of Usage and Performance of Java Collections. Diego Costa, 1 Artur Andrzejak, 1 Janos Seboek, 2 David Lo Empirical Study of Usage and Performance of Java Collections Diego Costa, Artur Andrzejak, Janos Seboek, 2 David Lo Heidelberg University, 2 Singapore Management University PVS Empirical Study of Usage

More information

CSE 331 Software Design and Implementation. Lecture 20 Design Patterns 1

CSE 331 Software Design and Implementation. Lecture 20 Design Patterns 1 CSE 331 Software Design and Implementation Lecture 20 Design Patterns 1 Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression

More information

Software 1 with Java. Recitation No. 6 (Collections)

Software 1 with Java. Recitation No. 6 (Collections) Software 1 with Java Recitation No. 6 (Collections) Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2

More information

Logistics. Final Exam on Friday at 3pm in CHEM 102

Logistics. Final Exam on Friday at 3pm in CHEM 102 Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create

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

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

COMP 103 : Test. 2018, Sept 12//(Corrected) ** WITH SOLUTIONS

COMP 103 : Test. 2018, Sept 12//(Corrected) ** WITH SOLUTIONS Family Name:.............................. Other Names:............................. Student ID:................................ Signature.................................. COMP 103 : Test 2018, Sept 12//(Corrected)

More information

Devender's Effective Java Reference Sheet

Devender's Effective Java Reference Sheet Devender's Effective Java Reference Sheet NOTE: All of these tips are from the book Effective Java (Second Edition) which is a great book and highly recommended, this sheet is meant to be a quick reference

More information

Design Patterns (1) CSE 331 Spring 2010

Design Patterns (1) CSE 331 Spring 2010 Design Patterns (1) CSE 331 Spring 2010 Outline Introduction to design patterns Creational patterns (constructing objects) Structural patterns (controlling heap layout) Behavioral patterns (affecting object

More information

NAME: c. (true or false) The median is always stored at the root of a binary search tree.

NAME: c. (true or false) The median is always stored at the root of a binary search tree. EE 322C Spring 2009 (Chase) Exam 2: READ THIS FIRST. Please use the back side of each page for scratch paper. For some of the questions you may need to think quite a bit before you write down an answer.

More information

Copyright 2012, Oracle and/or its affiliates. All rights reserved.

Copyright 2012, Oracle and/or its affiliates. All rights reserved. 1 Field guide to Java collections Mike Duigou (@mjduigou) Java Core Libraries 2 Required Reading Should have used most at some point List, Vector, ArrayList, LinkedList, Arrays.asList Set, HashSet, TreeSet

More information

CS11 Java. Winter Lecture 8

CS11 Java. Winter Lecture 8 CS11 Java Winter 2010-2011 Lecture 8 Java Collections Very powerful set of classes for managing collections of objects Introduced in Java 1.2 Provides: Interfaces specifying different kinds of collections

More information

CMSC 202H. Containers and Iterators

CMSC 202H. Containers and Iterators CMSC 202H Containers and Iterators Container Definition A container is a data structure whose purpose is to hold objects. Most languages support several ways to hold objects Arrays are compiler-supported

More information

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal

Enterprise Java Unit 1- Chapter 6 Prof. Sujata Rizal Introduction JDBC is a Java standard that provides the interface for connecting from Java to relational databases. The JDBC standard is defined by Sun Microsystems and implemented through the standard

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

The class Object. Lecture CS1122 Summer 2008

The class Object.  Lecture CS1122 Summer 2008 The class Object http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Lecture 10 -- CS1122 Summer 2008 Review Object is at the top of every hierarchy. Every class in Java has an IS-A relationship

More information

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level CSE1720 Click to edit Master Week text 08, styles Lecture 13 Second level Third level Fourth level Fifth level Winter 2014! Thursday, Feb 27, 2014 1 General Info Continuation of Chapter 9 Read Chapter

More information

Design Patterns (1) CSE 331 University of Washington. Michael Ernst

Design Patterns (1) CSE 331 University of Washington. Michael Ernst Design Patterns (1) CSE 331 University of Washington Michael Ernst What is a design pattern? A standard solution to a common programming problem Example 1: Encapsulation (data hiding) Problem: Exposed

More information

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content Core Java - SCJP Course content NOTE: For exam objectives refer to the SCJP 1.6 objectives. 1. Declarations and Access Control Java Refresher Identifiers & JavaBeans Legal Identifiers. Sun's Java Code

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

Designing a Persistence Framework

Designing a Persistence Framework Designing a Persistence Framework Working directly with code that uses JDBC is low-level data access; As application developers, one is more interested in the business problem that requires this data access.

More information

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Collections & Maps. Lecture 12. Collections & Maps

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Collections & Maps. Lecture 12. Collections & Maps Lecture 12 1 Review: Data Structure A data structure is a collection of data organized in some fashion The structure not only stores data but also supports operations for accessing/manipulating the data

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

MIT AITI Lecture 18 Collections - Part 1

MIT AITI Lecture 18 Collections - Part 1 MIT AITI 2004 - Lecture 18 Collections - Part 1 Collections API The package java.util is often called the "Collections API" Extremely useful classes that you must understand to be a competent Java programmer

More information

JAVA SYLLABUS FOR 6 MONTHS

JAVA SYLLABUS FOR 6 MONTHS JAVA SYLLABUS FOR 6 MONTHS Java 6-Months INTRODUCTION TO JAVA Features of Java Java Virtual Machine Comparison of C, C++, and Java Java Versions and its domain areas Life cycle of Java program Writing

More information

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel)

Programmieren II. Polymorphism. Alexander Fraser. June 4, (Based on material from T. Bögel) Programmieren II Polymorphism Alexander Fraser fraser@cl.uni-heidelberg.de (Based on material from T. Bögel) June 4, 2014 1 / 50 Outline 1 Recap - Collections 2 Advanced OOP: Polymorphism Polymorphism

More information

INTROSPECTION. We need to begin with a more basic concept called type introspection

INTROSPECTION. We need to begin with a more basic concept called type introspection REFLECTION 1 INTROSPECTION We need to begin with a more basic concept called type introspection The ability of a program to examine the type and properties of an object at runtime A few programming languages

More information

Java Database Connectivity (JDBC) 25.1 What is JDBC?

Java Database Connectivity (JDBC) 25.1 What is JDBC? PART 25 Java Database Connectivity (JDBC) 25.1 What is JDBC? JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent connectivity between the Java programming

More information

Adam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods

Adam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods Adam Blank Lecture 5 Winter 2019 CS 2 Introduction to Programming Methods CS 2: Introduction to Programming Methods Java Collections Abstract Data Types (ADT) 1 Abstract Data Type An abstract data type

More information

Interview Questions I received in 2017 and 2018

Interview Questions I received in 2017 and 2018 Interview Questions I received in 2017 and 2018 Table of Contents INTERVIEW QUESTIONS I RECEIVED IN 2017 AND 2018... 1 1 OOPS... 3 1. What is the difference between Abstract and Interface in Java8?...

More information

Tony Valderrama, SIPB IAP 2010

Tony Valderrama, SIPB IAP 2010 Today Java API java.util java.io More OOP Generics Enum.jar files JNI Q & A Announcements Course website: http://sipb.mit.edu/iap/java/ Email: sipb-iap-java@mit.edu package java.io Images from the Java

More information

15CS45 : OBJECT ORIENTED CONCEPTS

15CS45 : OBJECT ORIENTED CONCEPTS 15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?

More information

Section 9: Design Patterns. Slides adapted from Alex Mariakakis, with material from David Mailhot, Hal Perkins, Mike Ernst

Section 9: Design Patterns. Slides adapted from Alex Mariakakis, with material from David Mailhot, Hal Perkins, Mike Ernst Section 9: Design Patterns Slides adapted from Alex Mariakakis, with material from David Mailhot, Hal Perkins, Mike Ernst Agenda What are design patterns? Creational patterns review Structural patterns

More information

CMPUT 391 Database Management Systems. JDBC in Review. - Lab 2 -

CMPUT 391 Database Management Systems. JDBC in Review. - Lab 2 - CMPUT 391 Database Management Systems JDBC in Review - - Department of Computing Science University of Alberta What Is JDBC? JDBC is a programming interface JDBC allows developers using java to gain access

More information

CS61B Lecture #24. Today: Java support for generic programming. Readings for today: A Java Reference, Chapter 10.

CS61B Lecture #24. Today: Java support for generic programming. Readings for today: A Java Reference, Chapter 10. CS61B Lecture #24 Today: Java support for generic programming Readings for today: A Java Reference, Chapter 10. Readings for Monday: Data Structures, 6.4. Last modified: Fri Oct 19 19:33:03 2012 CS61B:

More information

University of Maryland College Park Dept of Computer Science

University of Maryland College Park Dept of Computer Science University of Maryland College Park Dept of Computer Science CMSC132H Fall 2009 Midterm Key Problem 1 (12 pts) Algorithmic Complexity 1. (6 pts) Calculate the asymptotic complexity of the code snippets

More information

27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection

27/04/2012. Objectives. Collection. Collections Framework. Collection Interface. Collection algorithm. Legacy collection Objectives Collection Collections Framework Concrete collections Collection algorithm By Võ Văn Hải Faculty of Information Technologies Summer 2012 Legacy collection 1 2 2/27 Collections Framework "Collection"

More information

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003 Data abstractions: ADTs Invariants, Abstraction function Lecture 4: OOP, autumn 2003 Limits of procedural abstractions Isolate implementation from specification Dependency on the types of parameters representation

More information