Java Advanced Features

Michael Redlich
Michael RedlichSystems Analyst, Polymer Physicist at Amateur Computer Group of New Jersey
1
Java Advanced
Features
Trenton Computer Festival
March 17, 2018
Michael P. Redlich
@mpredli
about.me/mpredli/
Who’s Mike?
• BS in CS from
• “Petrochemical Research Organization”
• Java Queue News Editor, InfoQ
• Ai-Logix, Inc. (now AudioCodes)
• Amateur Computer Group of New Jersey
2
Objectives (1)
• Java Beans
• Exception Handling
• Generics
• Java Database Connectivity
• Java Collections Framework
3
Java Beans
4
What are Java Beans?
• A method for developing reusable Java
components
• Also known as POJOs (Plain Old Java Objects)
• Easily store and retrieve information
5
Java Beans (1)
• A Java class is considered a bean when it:
• implements interface Serializable
• defines a default constructor
• defines properly named getter/setter methods
6
Java Beans (2)
• Getter/Setter methods:
• return (get) and assign (set) a bean’s data
members
• Specified naming convention:
•getMember
•setMember
•isValid
7
8
// PersonBean class (partial listing)
public class PersonBean implements Serializable {
private static final long serialVersionUID = 7526472295622776147L;
private String lastName;
private String firstName;
private boolean valid;
public PersonBean() {
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
// getter/setter for firstName
public boolean isValid() {
return valid;
}
}
Demo Time…
9
Exception Handling
10
What is Exception
Handling?
• A more robust method for handling errors
than fastidiously checking for error codes
• error code checking is tedious and can obscure
program logic
11
Exception Handling (1)
• Throw Expression:
• raises the exception
• Try Block:
• contains a throw expression or a method that
throws an exception
12
Exception Handling (2)
• Catch Clause(s):
• handles the exception
• defined immediately after the try block
• Finally Clause:
• always gets called regardless of where exception
is caught
• sets something back to its original state
13
Java Exception Model
(1)
• Checked Exceptions
• enforced by the compiler
• Unchecked Exceptions
• recommended, but not enforced by the compiler
14
Java Exception Model
(2)
• Exception Specification
• specify what type of exception(s) a method will
throw
• Termination vs. Resumption semantics
15
16
// ExceptionDemo class
public class ExceptionDemo {
public static void main(String[] args) {
try {
initialize();
}
catch(Exception exception) {
exception.printStackTrace();
}
public void initialize() throws Exception {
// contains code that may throw an exception of type Exception
}
}
Demo Time…
17
Generics
18
What are Generics?
• A mechanism to ensure type safety in Java
collections
• introduced in Java 5
• Similar concept to C++ Template
mechanism
19
Generics (1)
• Prototype:
• visibilityModifier class |
interface name<Type> {}
20
21
// Iterator demo *without* Generics...
List list = new ArrayList();
for(int i = 0;i < 10;++i) {
list.add(new Integer(i));
}
Iterator iterator = list.iterator();
while(iterator.hasNext()) {
System.out.println(“i = ” + (Integer)iterator.next());
}
22
// Iterator demo *with* Generics...
List<Integer> list = new ArrayList<Integer>();
for(int i = 0;i < 10;++i) {
list.add(new Integer(i));
}
Iterator<Integer> iterator = list.iterator();
while(iterator.hasNext()) {
System.out.println(“i = ” + iterator.next());
}
23
// Defining Simple Generics
public interface List<E> {
add(E x);
}
public interface Iterator<E> {
E next();
boolean hasNext();
}
Java Database
Connectivity (JDBC)
24
What is JDBC?
• A built-in API to access data sources
• relational databases
• spreadsheets
• flat files
• The JDK includes a JDBC-ODBC bridge for
use with ODBC data sources
• type 1 driver
25
Java Database
Connectivity (1)
• Install database driver and/or ODBC driver
• Establish a connection to the database:
• Class.forName(driverName);
• Connection connection =
DriverManager.getConnection();
26
Java Database
Connectivity (2)
• Create JDBC statement:
•Statement statement =
connection.createStatement();
• Obtain result set:
• Result result =
statement.execute();
• Result result =
statement.executeQuery();
27
28
// JDBC example
import java.sql.*;
public class DatabaseDemo {
public static void main(String[] args) {
String sql = “SELECT * FROM timeZones”;
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection connection =
DriverManager.getConnection(“jdbc:odbc:timezones”,””,””);
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(sql);
while(result.next()) {
System.out.println(result.getDouble(2) + “ “
+ result.getDouble(3));
}
connection.close();
}
}
Java Collections
Framework
29
What are Java
Collections? (1)
• A single object that groups together
multiple elements
• Collections are used to:
• store
• retrieve
• manipulate
30
What is the Java
Collection Framework?
• A unified architecture for collections
• All collection frameworks contain:
• interfaces
• implementations
• algorithms
• Inspired by the C++ Standard Template
Library
31
What is a Collection?
• A single object that groups together
multiple elements
• sometimes referred to as a container
• Containers before Java 2 were a
disappointment:
• only four containers
• no built-in algorithms
32
Collections (1)
• Implement the Collection interface
• Built-in implementations:
• List
• Set
33
Collections (2)
• Lists
• ordered sequences that support direct
indexing and bi-directional traversal
• Sets
• an unordered receptacle for elements
that conform to the notion of
mathematical set
34
35
// the Collection interface
public interface Collection<E> extends Iterable<E>{
boolean add(E e);
boolean addAll(Collection<? extends E> collection);
void clear();
boolean contains(Object object);
boolean containsAll(Collection<?> collection);
boolean equals(Object object);
int hashCode();
boolean isEmpty();
Iterator<E> iterator();
boolean remove(Object object);
boolean removeAll(Collection<?> collection);
boolean retainAll(Collection<?> collection);
int size();
Object[] toArray();
<T> T[] toArray(T[] array);
}
Iterators
• Used to access elements within an ordered
sequence
• All collections support iterators
• Traversal depends on the collection
• All iterators are fail-fast
• if the collection is changed by something other
than the iterator, the iterator becomes invalid
36
37
// Iterator demo
import java.util.*;
List<Integer> list = new ArrayList<Integer>();
for(int i = 0;i < 9;++i) {
list.add(new Integer(i));
}
Iterator iterator = list.iterator();
while(iterator.hasNext()) {
System.out.println(iterator.next());
}
0 1 2 3 4 5 6 7 8
current last
Demo Time…
38
Java IDEs (1)
• IntelliJ IDEA 2017.3
•jetbrains.com/idea
• stay tuned for version 2018.1 coming soon
• Eclipse IDE
•eclipse.org/ide
39
Java IDEs (2)
• NetBeans 8.2
•netbeans.org
• currently being moved from Oracle to Apache
40
Local Java User Groups
(1)
• ACGNJ Java Users Group
• facilitated by Mike Redlich
• javasig.org
• Princeton Java Users Group
• facilitated byYakov Fain
• meetup.com/NJFlex
41
Local Java User Groups
(2)
• NYJavaSIG
• facilitated by Frank Greco
• javasig.com
• PhillyJUG
• facilitated by Martin Snyder, et. al.
• meetup.com/PhillyJUG
42
Local Java User Groups
(3)
• Capital District Java Developers Network
• facilitated by Dan Patsey
•cdjdn.com
• currently restructuring
43
Further Reading
44
Upcoming Events
• ACGNJ Java Users Group
• Dr. Venkat Subramaniam
• Monday, March 19, 2018
• DorothyYoung Center for the Arts, Room 106
• Drew University
• 7:30-9:00pm
• “Twelve Ways to Make Code Suck Less”
45
46
Thanks!
mike@redlich.net
@mpredli
redlich.net
slideshare.net/mpredli01
github.com/mpredli01
Upcoming Events
• March 17-18, 2017
•tcf-nj.org
• April 18-19, 2017
•phillyemergingtech.com
47
1 of 47

Recommended

C++ Advanced Features by
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced FeaturesMichael Redlich
280 views62 slides
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System» by
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»
Дмитрий Контрерас «Back to the future: the evolution of the Java Type System»Anna Shymchenko
372 views25 slides
C++ Advanced Features by
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced FeaturesMichael Redlich
96 views62 slides
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ... by
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ....NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...NETFest
324 views46 slides
Java Programming - 06 java file io by
Java Programming - 06 java file ioJava Programming - 06 java file io
Java Programming - 06 java file ioDanairat Thanabodithammachari
974 views18 slides
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac by
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javacAnna Brzezińska
484 views22 slides

More Related Content

What's hot

core java by
core javacore java
core javaVinodh Kumar
734 views25 slides
Code generation for alternative languages by
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languagesRafael Winterhalter
436 views16 slides
Elementary Sort by
Elementary SortElementary Sort
Elementary SortSri Prasanna
1.5K views49 slides
Java by
JavaJava
JavaJAy YourJust'one
294 views33 slides
Understanding Java byte code and the class file format by
Understanding Java byte code and the class file formatUnderstanding Java byte code and the class file format
Understanding Java byte code and the class file formatRafael Winterhalter
4.2K views24 slides
GateIn Frameworks by
GateIn FrameworksGateIn Frameworks
GateIn Frameworksjviet
1.3K views32 slides

What's hot(20)

Understanding Java byte code and the class file format by Rafael Winterhalter
Understanding Java byte code and the class file formatUnderstanding Java byte code and the class file format
Understanding Java byte code and the class file format
Rafael Winterhalter4.2K views
GateIn Frameworks by jviet
GateIn FrameworksGateIn Frameworks
GateIn Frameworks
jviet1.3K views
Native code in Android applications by Dmitry Matyukhin
Native code in Android applicationsNative code in Android applications
Native code in Android applications
Dmitry Matyukhin4.2K views
Java 8 and beyond, a scala story by ittaiz
Java 8 and beyond, a scala storyJava 8 and beyond, a scala story
Java 8 and beyond, a scala story
ittaiz575 views
Java and XML Schema by Raji Ghawi
Java and XML SchemaJava and XML Schema
Java and XML Schema
Raji Ghawi2.8K views
Object Oriented Exploitation: New techniques in Windows mitigation bypass by Sam Thomas
Object Oriented Exploitation: New techniques in Windows mitigation bypassObject Oriented Exploitation: New techniques in Windows mitigation bypass
Object Oriented Exploitation: New techniques in Windows mitigation bypass
Sam Thomas9.9K views
Java OOP Programming language (Part 8) - Java Database JDBC by OUM SAOKOSAL
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
OUM SAOKOSAL1.8K views

Similar to Java Advanced Features

Java Advanced Features (TCF 2014) by
Java Advanced Features (TCF 2014)Java Advanced Features (TCF 2014)
Java Advanced Features (TCF 2014)Michael Redlich
754 views44 slides
java training faridabad by
java training faridabadjava training faridabad
java training faridabadWoxa Technologies
282 views47 slides
Java Tutorials by
Java Tutorials Java Tutorials
Java Tutorials Woxa Technologies
605 views47 slides
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig) by
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)   A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig) David Salz
3.6K views40 slides
Java by
Java Java
Java Prabhat gangwar
536 views50 slides
Getting Started with Java by
Getting Started with JavaGetting Started with Java
Getting Started with JavaMichael Redlich
237 views41 slides

Similar to Java Advanced Features(20)

Java Advanced Features (TCF 2014) by Michael Redlich
Java Advanced Features (TCF 2014)Java Advanced Features (TCF 2014)
Java Advanced Features (TCF 2014)
Michael Redlich754 views
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig) by David Salz
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)   A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)
A simple and powerful property system for C++ (talk at GCDC 2008, Leipzig)
David Salz3.6K views
Java 8 - Project Lambda by Rahman USTA
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
Rahman USTA5K views
JavaScript in 2016 by Codemotion
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
Codemotion636 views
JavaScript in 2016 (Codemotion Rome) by Eduard Tomàs
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs1.2K views
Collections - Array List by Hitesh-Java
Collections - Array List Collections - Array List
Collections - Array List
Hitesh-Java944 views
Ahead-Of-Time Compilation of Java Applications by Nikita Lipsky
Ahead-Of-Time Compilation of Java ApplicationsAhead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java Applications
Nikita Lipsky3.6K views
Synapseindia reviews.odp. by Tarunsingh198
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198211 views
Java EE 6 CDI Integrates with Spring & JSF by Jiayun Zhou
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSF
Jiayun Zhou3.9K views

More from Michael Redlich

Getting Started with GitHub by
Getting Started with GitHubGetting Started with GitHub
Getting Started with GitHubMichael Redlich
153 views30 slides
Building Microservices with Micronaut: A Full-Stack JVM-Based Framework by
Building Microservices with Micronaut:  A Full-Stack JVM-Based FrameworkBuilding Microservices with Micronaut:  A Full-Stack JVM-Based Framework
Building Microservices with Micronaut: A Full-Stack JVM-Based FrameworkMichael Redlich
415 views55 slides
Building Microservices with Helidon: Oracle's New Java Microservices Framework by
Building Microservices with Helidon:  Oracle's New Java Microservices FrameworkBuilding Microservices with Helidon:  Oracle's New Java Microservices Framework
Building Microservices with Helidon: Oracle's New Java Microservices FrameworkMichael Redlich
274 views58 slides
Introduction to Object Oriented Programming & Design Principles by
Introduction to Object Oriented Programming & Design PrinciplesIntroduction to Object Oriented Programming & Design Principles
Introduction to Object Oriented Programming & Design PrinciplesMichael Redlich
377 views59 slides
Introduction to Object Oriented Programming &amp; Design Principles by
Introduction to Object Oriented Programming &amp; Design PrinciplesIntroduction to Object Oriented Programming &amp; Design Principles
Introduction to Object Oriented Programming &amp; Design PrinciplesMichael Redlich
117 views59 slides
Building Realtime Access to Data Apps with jOOQ by
Building Realtime Access to Data Apps with jOOQBuilding Realtime Access to Data Apps with jOOQ
Building Realtime Access to Data Apps with jOOQMichael Redlich
225 views21 slides

More from Michael Redlich(16)

Building Microservices with Micronaut: A Full-Stack JVM-Based Framework by Michael Redlich
Building Microservices with Micronaut:  A Full-Stack JVM-Based FrameworkBuilding Microservices with Micronaut:  A Full-Stack JVM-Based Framework
Building Microservices with Micronaut: A Full-Stack JVM-Based Framework
Michael Redlich415 views
Building Microservices with Helidon: Oracle's New Java Microservices Framework by Michael Redlich
Building Microservices with Helidon:  Oracle's New Java Microservices FrameworkBuilding Microservices with Helidon:  Oracle's New Java Microservices Framework
Building Microservices with Helidon: Oracle's New Java Microservices Framework
Michael Redlich274 views
Introduction to Object Oriented Programming & Design Principles by Michael Redlich
Introduction to Object Oriented Programming & Design PrinciplesIntroduction to Object Oriented Programming & Design Principles
Introduction to Object Oriented Programming & Design Principles
Michael Redlich377 views
Introduction to Object Oriented Programming &amp; Design Principles by Michael Redlich
Introduction to Object Oriented Programming &amp; Design PrinciplesIntroduction to Object Oriented Programming &amp; Design Principles
Introduction to Object Oriented Programming &amp; Design Principles
Michael Redlich117 views
Building Realtime Access to Data Apps with jOOQ by Michael Redlich
Building Realtime Access to Data Apps with jOOQBuilding Realtime Access to Data Apps with jOOQ
Building Realtime Access to Data Apps with jOOQ
Michael Redlich225 views
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017) by Michael Redlich
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
Building Realtime Access Data Apps with Speedment (TCF ITPC 2017)
Michael Redlich281 views
Building Realtime Web Apps with Angular and Meteor by Michael Redlich
Building Realtime Web Apps with Angular and MeteorBuilding Realtime Web Apps with Angular and Meteor
Building Realtime Web Apps with Angular and Meteor
Michael Redlich319 views
Introduction to Object-Oriented Programming & Design Principles (TCF 2014) by Michael Redlich
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Introduction to Object-Oriented Programming & Design Principles (TCF 2014)
Michael Redlich2.4K views
Getting Started with Meteor (TCF ITPC 2014) by Michael Redlich
Getting Started with Meteor (TCF ITPC 2014)Getting Started with Meteor (TCF ITPC 2014)
Getting Started with Meteor (TCF ITPC 2014)
Michael Redlich902 views
Getting Started with Java (TCF 2014) by Michael Redlich
Getting Started with Java (TCF 2014)Getting Started with Java (TCF 2014)
Getting Started with Java (TCF 2014)
Michael Redlich777 views
Getting Started with C++ (TCF 2014) by Michael Redlich
Getting Started with C++ (TCF 2014)Getting Started with C++ (TCF 2014)
Getting Started with C++ (TCF 2014)
Michael Redlich1.3K views
C++ Advanced Features (TCF 2014) by Michael Redlich
C++ Advanced Features (TCF 2014)C++ Advanced Features (TCF 2014)
C++ Advanced Features (TCF 2014)
Michael Redlich1.4K views
Getting Started with MongoDB (TCF ITPC 2014) by Michael Redlich
Getting Started with MongoDB (TCF ITPC 2014)Getting Started with MongoDB (TCF ITPC 2014)
Getting Started with MongoDB (TCF ITPC 2014)
Michael Redlich2.2K views

Recently uploaded

DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...Deltares
6 views28 slides
LAVADORA ROLO.docx by
LAVADORA ROLO.docxLAVADORA ROLO.docx
LAVADORA ROLO.docxSamuelRamirez83524
7 views1 slide
Software evolution understanding: Automatic extraction of software identifier... by
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...Ra'Fat Al-Msie'deen
7 views33 slides
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Donato Onofri
711 views34 slides
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...Deltares
9 views32 slides
Winter '24 Release Chat.pdf by
Winter '24 Release Chat.pdfWinter '24 Release Chat.pdf
Winter '24 Release Chat.pdfmelbourneauuser
9 views20 slides

Recently uploaded(20)

DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by Deltares
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
Deltares6 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri711 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares9 views
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm13 views
What Can Employee Monitoring Software Do?​ by wAnywhere
What Can Employee Monitoring Software Do?​What Can Employee Monitoring Software Do?​
What Can Employee Monitoring Software Do?​
wAnywhere21 views
A first look at MariaDB 11.x features and ideas on how to use them by Federico Razzoli
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use them
Federico Razzoli45 views
Cycleops - Automate deployments on top of bare metal.pptx by Thanassis Parathyras
Cycleops - Automate deployments on top of bare metal.pptxCycleops - Automate deployments on top of bare metal.pptx
Cycleops - Automate deployments on top of bare metal.pptx
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares16 views
Consulting for Data Monetization Maximizing the Profit Potential of Your Data... by Flexsin
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Flexsin 15 views
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols by Deltares
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - DolsDSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
Deltares7 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info3349224 views
Roadmap y Novedades de producto by Neo4j
Roadmap y Novedades de productoRoadmap y Novedades de producto
Roadmap y Novedades de producto
Neo4j50 views
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views

Java Advanced Features

  • 1. 1 Java Advanced Features Trenton Computer Festival March 17, 2018 Michael P. Redlich @mpredli about.me/mpredli/
  • 2. Who’s Mike? • BS in CS from • “Petrochemical Research Organization” • Java Queue News Editor, InfoQ • Ai-Logix, Inc. (now AudioCodes) • Amateur Computer Group of New Jersey 2
  • 3. Objectives (1) • Java Beans • Exception Handling • Generics • Java Database Connectivity • Java Collections Framework 3
  • 5. What are Java Beans? • A method for developing reusable Java components • Also known as POJOs (Plain Old Java Objects) • Easily store and retrieve information 5
  • 6. Java Beans (1) • A Java class is considered a bean when it: • implements interface Serializable • defines a default constructor • defines properly named getter/setter methods 6
  • 7. Java Beans (2) • Getter/Setter methods: • return (get) and assign (set) a bean’s data members • Specified naming convention: •getMember •setMember •isValid 7
  • 8. 8 // PersonBean class (partial listing) public class PersonBean implements Serializable { private static final long serialVersionUID = 7526472295622776147L; private String lastName; private String firstName; private boolean valid; public PersonBean() { } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } // getter/setter for firstName public boolean isValid() { return valid; } }
  • 11. What is Exception Handling? • A more robust method for handling errors than fastidiously checking for error codes • error code checking is tedious and can obscure program logic 11
  • 12. Exception Handling (1) • Throw Expression: • raises the exception • Try Block: • contains a throw expression or a method that throws an exception 12
  • 13. Exception Handling (2) • Catch Clause(s): • handles the exception • defined immediately after the try block • Finally Clause: • always gets called regardless of where exception is caught • sets something back to its original state 13
  • 14. Java Exception Model (1) • Checked Exceptions • enforced by the compiler • Unchecked Exceptions • recommended, but not enforced by the compiler 14
  • 15. Java Exception Model (2) • Exception Specification • specify what type of exception(s) a method will throw • Termination vs. Resumption semantics 15
  • 16. 16 // ExceptionDemo class public class ExceptionDemo { public static void main(String[] args) { try { initialize(); } catch(Exception exception) { exception.printStackTrace(); } public void initialize() throws Exception { // contains code that may throw an exception of type Exception } }
  • 19. What are Generics? • A mechanism to ensure type safety in Java collections • introduced in Java 5 • Similar concept to C++ Template mechanism 19
  • 20. Generics (1) • Prototype: • visibilityModifier class | interface name<Type> {} 20
  • 21. 21 // Iterator demo *without* Generics... List list = new ArrayList(); for(int i = 0;i < 10;++i) { list.add(new Integer(i)); } Iterator iterator = list.iterator(); while(iterator.hasNext()) { System.out.println(“i = ” + (Integer)iterator.next()); }
  • 22. 22 // Iterator demo *with* Generics... List<Integer> list = new ArrayList<Integer>(); for(int i = 0;i < 10;++i) { list.add(new Integer(i)); } Iterator<Integer> iterator = list.iterator(); while(iterator.hasNext()) { System.out.println(“i = ” + iterator.next()); }
  • 23. 23 // Defining Simple Generics public interface List<E> { add(E x); } public interface Iterator<E> { E next(); boolean hasNext(); }
  • 25. What is JDBC? • A built-in API to access data sources • relational databases • spreadsheets • flat files • The JDK includes a JDBC-ODBC bridge for use with ODBC data sources • type 1 driver 25
  • 26. Java Database Connectivity (1) • Install database driver and/or ODBC driver • Establish a connection to the database: • Class.forName(driverName); • Connection connection = DriverManager.getConnection(); 26
  • 27. Java Database Connectivity (2) • Create JDBC statement: •Statement statement = connection.createStatement(); • Obtain result set: • Result result = statement.execute(); • Result result = statement.executeQuery(); 27
  • 28. 28 // JDBC example import java.sql.*; public class DatabaseDemo { public static void main(String[] args) { String sql = “SELECT * FROM timeZones”; Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection connection = DriverManager.getConnection(“jdbc:odbc:timezones”,””,””); Statement statement = connection.createStatement(); ResultSet result = statement.executeQuery(sql); while(result.next()) { System.out.println(result.getDouble(2) + “ “ + result.getDouble(3)); } connection.close(); } }
  • 30. What are Java Collections? (1) • A single object that groups together multiple elements • Collections are used to: • store • retrieve • manipulate 30
  • 31. What is the Java Collection Framework? • A unified architecture for collections • All collection frameworks contain: • interfaces • implementations • algorithms • Inspired by the C++ Standard Template Library 31
  • 32. What is a Collection? • A single object that groups together multiple elements • sometimes referred to as a container • Containers before Java 2 were a disappointment: • only four containers • no built-in algorithms 32
  • 33. Collections (1) • Implement the Collection interface • Built-in implementations: • List • Set 33
  • 34. Collections (2) • Lists • ordered sequences that support direct indexing and bi-directional traversal • Sets • an unordered receptacle for elements that conform to the notion of mathematical set 34
  • 35. 35 // the Collection interface public interface Collection<E> extends Iterable<E>{ boolean add(E e); boolean addAll(Collection<? extends E> collection); void clear(); boolean contains(Object object); boolean containsAll(Collection<?> collection); boolean equals(Object object); int hashCode(); boolean isEmpty(); Iterator<E> iterator(); boolean remove(Object object); boolean removeAll(Collection<?> collection); boolean retainAll(Collection<?> collection); int size(); Object[] toArray(); <T> T[] toArray(T[] array); }
  • 36. Iterators • Used to access elements within an ordered sequence • All collections support iterators • Traversal depends on the collection • All iterators are fail-fast • if the collection is changed by something other than the iterator, the iterator becomes invalid 36
  • 37. 37 // Iterator demo import java.util.*; List<Integer> list = new ArrayList<Integer>(); for(int i = 0;i < 9;++i) { list.add(new Integer(i)); } Iterator iterator = list.iterator(); while(iterator.hasNext()) { System.out.println(iterator.next()); } 0 1 2 3 4 5 6 7 8 current last
  • 39. Java IDEs (1) • IntelliJ IDEA 2017.3 •jetbrains.com/idea • stay tuned for version 2018.1 coming soon • Eclipse IDE •eclipse.org/ide 39
  • 40. Java IDEs (2) • NetBeans 8.2 •netbeans.org • currently being moved from Oracle to Apache 40
  • 41. Local Java User Groups (1) • ACGNJ Java Users Group • facilitated by Mike Redlich • javasig.org • Princeton Java Users Group • facilitated byYakov Fain • meetup.com/NJFlex 41
  • 42. Local Java User Groups (2) • NYJavaSIG • facilitated by Frank Greco • javasig.com • PhillyJUG • facilitated by Martin Snyder, et. al. • meetup.com/PhillyJUG 42
  • 43. Local Java User Groups (3) • Capital District Java Developers Network • facilitated by Dan Patsey •cdjdn.com • currently restructuring 43
  • 45. Upcoming Events • ACGNJ Java Users Group • Dr. Venkat Subramaniam • Monday, March 19, 2018 • DorothyYoung Center for the Arts, Room 106 • Drew University • 7:30-9:00pm • “Twelve Ways to Make Code Suck Less” 45
  • 47. Upcoming Events • March 17-18, 2017 •tcf-nj.org • April 18-19, 2017 •phillyemergingtech.com 47