SlideShare uma empresa Scribd logo
1 de 14
Giacomo Veneri http://jugsi.blogspot.com1
Just to drink a cup of coffee
maybe you don't know … about java
• Java
– Passing by reference or by
value (final keyword)
– stricftp keyword
– Equals .. be caught
• Java EE
– Do NOT override java.library.path
on application server
– Transient work on cluster
• Use Collection
Efficiently
• Multithreading
– TimeZone is synchronized
– DateFormat is NOT thread safe
– Loggings should be synchronized
– Volatile keyword
Giacomo Veneri http://jugsi.blogspot.com2
Java: passing parameter by
reference or by value?
public void myMethod(MyObject a, int b) {
a.setInternalValue(“mystring”);
b++;
}
• Formally speaking: java passes parameter by value.
• However: experienced programmers know that the code listed here will modified the status of 'a' outside the scope of
the method and b will NOT changed outside the scope of the method.
• Indeed java passes for b the value of b and for a the value of the refrence to a instance.
• Then: java passes the value of parameters on both cases.
• Suggestion: consider the final keyword, to use im-mutable object or to make a copy before calling the method.
Giacomo Veneri http://jugsi.blogspot.com3
Java: stricftp
public strictfp double callBystrictFP(double a) {
return (a / 2 ) * 2 ;
}
..
callBystrictFP(Double.MIN_VALUE); // it will return 0 instead of
6..E-341
• Formally speaking: FP-strict expressions must be those predicted by IEEE
754 arithmetic on operands represented using single and double formats
• However: from 1.2 java implementation of FP arithmetic is platform dependent
• Then: to ensure IEEE 754 arithmetic use strictfp
• Suggestion: if you are an ERP programmer consider BigDecimal and
MathContext for approximation, it should save your life
Giacomo Veneri http://jugsi.blogspot.com4
Java: equals
byte b = 'a';
byte c = 'a';
String s = “a”;
s.equals(b); //return false
s.equals(c); //return false
b == c; //return true
s ==”a”; //return true
•Formally speakingFormally speaking: Object.equals return false when the object's classes
are different, value (or refrence) are different
•HoweverHowever: litterals or charecter/integer between 0..128 could surprise us
due to java optimization
•SuggestionSuggestion: use equals for Object or primitive wrapper and “==” for
primitive
•RemeberRemeber: when you re-implement equals on your own class re-implement also
hashCode() method
Giacomo Veneri http://jugsi.blogspot.com5
Java: init
class MyClass {
public MyClass() {
//constructor
}
{
//init before constructor
}
}
• Formally speaking: the block
highlighted is callde before the
constructor
Giacomo Veneri http://jugsi.blogspot.com6
MT: SimpleDateFormat
static DateFormat df = new SimpleDateFormat(“yyyy.MM.dd G
'at' HH:mm:ss z”);
…
df.parse(..);
• Formally speaking: SimpleDateFormat is not thread safe
• Then: if you declare SimpleDateFormat static or on a singletone class on Multi Thread enviroment
(EJB, Web,...) you will experience the most absurd bug of your life
• Suggestion: do NOT declare SimpleDateFormat as attribute or static member of your class
Giacomo Veneri http://jugsi.blogspot.com7
MT: logging
• Some frameworks such as log4j or
logback block execution (synchronization)
to write into a file.
• Suggestion: consult logback or log4j
documentation to use Async Logging
Giacomo Veneri http://jugsi.blogspot.com8
MT: volatile
volatile MyCache cache = null;
public MyCache getCache() {
if (cache ==null) ||
(elapsed(cache)) {
synchronized(this) {
if (cache ==null) {
… // create cache
}
}
} else return cache;
}
• Formally speaking: thread should save local
variable on thread stuck
• Then: if another thread acquire the lock and modify
the local variable the second thread could NOT see
the change
• Suggestion: volatile force s the thread to read the in
memory variable; volatile reduces performance
(1:10)
• Reference: look for “double check” on google
Giacomo Veneri http://jugsi.blogspot.com9
JEE: java.library.path
• When you need to connect your java EE application to an EIS you must use JCA
–Connector Architecture (JCA) is a Java-based technology solution for connecting application
servers and enterprise information systems (EIS)
• However: if you are too lazy to implement your JCA component you might be tempted to
declare the java.library.path to point your native library
• Then: you can overwrite the native library used by your application server
–Weblogic uses java.library.path to pint native io in order to improve performance
• Suggestion: use JCA …. or …. find java.library.path of your application server and adjust it
–Be caught! On multi server or cluster environent you can modify the entire behavior
Giacomo Veneri http://jugsi.blogspot.com10
MT: transient
@EJB
transient MyEjb myEjb;
• Formally speaking: using transient java doesn't serialize the object, rseources
(Connection or EJB) on JEE cannot be serialized
• Then: on Migratable server two node could share session each other
• Suggestion: use transient when you reference resources
Giacomo Veneri http://jugsi.blogspot.com11
java.util collection
efficiency from 10 to 1
10 new HashMap()
08 new TreeMap()
03 new Hashtable(n) :
synchronized and define capacity
02 new Hashtable() :
synchronized
01
Collections.synchronizedMaps
(new HashMap())
01
Collections.synchronizedColle
ctions(new ArrayList())
03 new Vector(n) :
synchronized and define
capacity
02 Vector : synchronized
10 Iterator, Enumeration
09 new ArrayList(n): define capacity
08 new ArrayList()
07 new LinkeList(n) : manage queue
and define capacity
06 new LinkeList() : manage queue
05 new HashSet() : prevent duplicate
04 new TreeSet() : implements sorting
Giacomo Veneri http://jugsi.blogspot.com12
java.util collection
The given table is just a reference to take in
consideration but Map and set are not comprable ...
1.Use ensureCapacity for better performance to write
data
2.Performance of LinkedList decreases when size
increases
3.Iterator is faster than “for cycle” over set, but, on Map,
when you ned to create iterator by keySet, doesn't
produce any valuable difference
Giacomo Veneri http://jugsi.blogspot.com13
Quiz ;-)
• How many issues did you know
– 3 maybe you are 3 year experienced programmer
– 5 maybe you are 5 year experienced programmer
– 7 maybe you are junior JEE architect
– 10 you are senior JEE architect
– ..or maybe not
16/07/13 Giacomo Veneri - http://jugsi.blogspot.com14
Giacomo Veneri, PhD, MCs
(IT Manager, Human Computer Interaction Scientist)
@venergiac
g.veneri@ieee.org
http://jugsi.blogspot.com
My Professional Profile
http://it.linkedin.com/in/giacomoveneri
My Publications on HCI
http://scholar.google.it/citations?user=B40SHWAAAAAJ
My Research Profile
http://www.scopus.com/authid/detail.url?authorId=36125776100
http://www.biomedexperts.com/AuthorDetailsGateway.aspx?auid=2021359
https://www.researchgate.net/profile/Giacomo_Veneri/

Mais conteúdo relacionado

Mais procurados

Spark real world use cases and optimizations
Spark real world use cases and optimizationsSpark real world use cases and optimizations
Spark real world use cases and optimizationsGal Marder
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersNLJUG
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8 Dori Waldman
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey J On The Beach
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsKonrad Malawski
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Developing Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache StormDeveloping Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache StormLester Martin
 
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward SF 2017: Eron Wright - Introducing Flink TensorflowFlink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward SF 2017: Eron Wright - Introducing Flink TensorflowFlink Forward
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play frameworkFelipe
 
Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017
Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017
Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017Big Data Spain
 
Supercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-reactSupercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-reactJohn McClean
 
DotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NETDotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NETMaarten Balliauw
 
Spark stream - Kafka
Spark stream - Kafka Spark stream - Kafka
Spark stream - Kafka Dori Waldman
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 
Spark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongPROIDEA
 
Introduction of failsafe
Introduction of failsafeIntroduction of failsafe
Introduction of failsafeSunghyouk Bae
 

Mais procurados (19)

Spark real world use cases and optimizations
Spark real world use cases and optimizationsSpark real world use cases and optimizations
Spark real world use cases and optimizations
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
whats new in java 8
whats new in java 8 whats new in java 8
whats new in java 8
 
Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey Low latency in java 8 by Peter Lawrey
Low latency in java 8 by Peter Lawrey
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Developing Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache StormDeveloping Java Streaming Applications with Apache Storm
Developing Java Streaming Applications with Apache Storm
 
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward SF 2017: Eron Wright - Introducing Flink TensorflowFlink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
Flink Forward SF 2017: Eron Wright - Introducing Flink Tensorflow
 
Apache Storm
Apache StormApache Storm
Apache Storm
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017
Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017
Deep Learning in Spark with BigDL by Petar Zecevic at Big Data Spain 2017
 
Supercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-reactSupercharged java 8 : with cyclops-react
Supercharged java 8 : with cyclops-react
 
DotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NETDotNetFest - Let’s refresh our memory! Memory management in .NET
DotNetFest - Let’s refresh our memory! Memory management in .NET
 
Spark stream - Kafka
Spark stream - Kafka Spark stream - Kafka
Spark stream - Kafka
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Spark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus GoehausenSpark Summit EU talk by Nimbus Goehausen
Spark Summit EU talk by Nimbus Goehausen
 
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go WrongJDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
JDD 2016 - Grzegorz Rozniecki - Java 8 What Could Possibly Go Wrong
 
Introduction of failsafe
Introduction of failsafeIntroduction of failsafe
Introduction of failsafe
 

Destaque

Cibernetica, modelli computazionali e tecnologie informatiche
Cibernetica, modelli computazionali e tecnologie  informatiche Cibernetica, modelli computazionali e tecnologie  informatiche
Cibernetica, modelli computazionali e tecnologie informatiche Giacomo Veneri
 
Eracle project poster_session_efns
Eracle project poster_session_efnsEracle project poster_session_efns
Eracle project poster_session_efnsGiacomo Veneri
 
Pattern recognition on human vision
Pattern recognition on human visionPattern recognition on human vision
Pattern recognition on human visionGiacomo Veneri
 
Bayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 posterBayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 posterGiacomo Veneri
 
From Java 6 to Java 7 reference
From Java 6 to Java 7 referenceFrom Java 6 to Java 7 reference
From Java 6 to Java 7 referenceGiacomo Veneri
 
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...Giacomo Veneri
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 CertificationsGiacomo Veneri
 

Destaque (9)

Dal web 2 al web 3
Dal web 2 al web 3Dal web 2 al web 3
Dal web 2 al web 3
 
Il web 2.0
Il web 2.0Il web 2.0
Il web 2.0
 
Cibernetica, modelli computazionali e tecnologie informatiche
Cibernetica, modelli computazionali e tecnologie  informatiche Cibernetica, modelli computazionali e tecnologie  informatiche
Cibernetica, modelli computazionali e tecnologie informatiche
 
Eracle project poster_session_efns
Eracle project poster_session_efnsEracle project poster_session_efns
Eracle project poster_session_efns
 
Pattern recognition on human vision
Pattern recognition on human visionPattern recognition on human vision
Pattern recognition on human vision
 
Bayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 posterBayesain Hypothesis of Selective Attention - Raw 2011 poster
Bayesain Hypothesis of Selective Attention - Raw 2011 poster
 
From Java 6 to Java 7 reference
From Java 6 to Java 7 referenceFrom Java 6 to Java 7 reference
From Java 6 to Java 7 reference
 
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH  A MODEL TO E...
Raw 2009 -THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH A MODEL TO E...
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
 

Semelhante a Java best practices and common issues

24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questionsArun Vasanth
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9Gal Marder
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updatesVinay H G
 
Ups and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingUps and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingCsaba Toth
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in JavaMudit Gupta
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On WorkshopArpit Poladia
 
Alfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring MvcAlfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring MvcDaniel Gradecak
 
Effective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's bookEffective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's bookRoman Tsypuk
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 

Semelhante a Java best practices and common issues (20)

Best Of Jdk 7
Best Of Jdk 7Best Of Jdk 7
Best Of Jdk 7
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
Java 8 selected updates
Java 8 selected updatesJava 8 selected updates
Java 8 selected updates
 
How can your applications benefit from Java 9?
How can your applications benefit from Java 9?How can your applications benefit from Java 9?
How can your applications benefit from Java 9?
 
Java 8
Java 8Java 8
Java 8
 
Ups and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingUps and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research setting
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On Workshop
 
Alfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring MvcAlfresco Mvc - a seamless integration with Spring Mvc
Alfresco Mvc - a seamless integration with Spring Mvc
 
Hibernate Advance Interview Questions
Hibernate Advance Interview QuestionsHibernate Advance Interview Questions
Hibernate Advance Interview Questions
 
Effective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's bookEffective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's book
 
es6
es6es6
es6
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Java 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CCJava 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CC
 

Mais de Giacomo Veneri

Giacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of SienaGiacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of SienaGiacomo Veneri
 
Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation Giacomo Veneri
 
Industrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitalyIndustrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitalyGiacomo Veneri
 
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEMEVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEMGiacomo Veneri
 
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH Giacomo Veneri
 
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...Giacomo Veneri
 
Giacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertationGiacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertationGiacomo Veneri
 

Mais de Giacomo Veneri (8)

Giacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of SienaGiacomo Veneri Thesis 1999 University of Siena
Giacomo Veneri Thesis 1999 University of Siena
 
Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation Giiacomo Veneri PHD Dissertation
Giiacomo Veneri PHD Dissertation
 
Industrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitalyIndustrial IoT - build your industry 4.0 @techitaly
Industrial IoT - build your industry 4.0 @techitaly
 
Giacomo Veneri Thesis
Giacomo Veneri ThesisGiacomo Veneri Thesis
Giacomo Veneri Thesis
 
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEMEVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE  BASE SYSTEM
EVA – EYE TRACKING - STIMULUS INTEGRATED SEMI AUTOMATIC CASE BASE SYSTEM
 
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
THE ROLE OF LATEST FIXATIONS ON ONGOING VISUAL SEARCH
 
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
Evaluating Human Visual Search Performance by Monte Carlo methods and Heurist...
 
Giacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertationGiacomo Veneri 2012 phd dissertation
Giacomo Veneri 2012 phd dissertation
 

Último

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Java best practices and common issues

  • 1. Giacomo Veneri http://jugsi.blogspot.com1 Just to drink a cup of coffee maybe you don't know … about java • Java – Passing by reference or by value (final keyword) – stricftp keyword – Equals .. be caught • Java EE – Do NOT override java.library.path on application server – Transient work on cluster • Use Collection Efficiently • Multithreading – TimeZone is synchronized – DateFormat is NOT thread safe – Loggings should be synchronized – Volatile keyword
  • 2. Giacomo Veneri http://jugsi.blogspot.com2 Java: passing parameter by reference or by value? public void myMethod(MyObject a, int b) { a.setInternalValue(“mystring”); b++; } • Formally speaking: java passes parameter by value. • However: experienced programmers know that the code listed here will modified the status of 'a' outside the scope of the method and b will NOT changed outside the scope of the method. • Indeed java passes for b the value of b and for a the value of the refrence to a instance. • Then: java passes the value of parameters on both cases. • Suggestion: consider the final keyword, to use im-mutable object or to make a copy before calling the method.
  • 3. Giacomo Veneri http://jugsi.blogspot.com3 Java: stricftp public strictfp double callBystrictFP(double a) { return (a / 2 ) * 2 ; } .. callBystrictFP(Double.MIN_VALUE); // it will return 0 instead of 6..E-341 • Formally speaking: FP-strict expressions must be those predicted by IEEE 754 arithmetic on operands represented using single and double formats • However: from 1.2 java implementation of FP arithmetic is platform dependent • Then: to ensure IEEE 754 arithmetic use strictfp • Suggestion: if you are an ERP programmer consider BigDecimal and MathContext for approximation, it should save your life
  • 4. Giacomo Veneri http://jugsi.blogspot.com4 Java: equals byte b = 'a'; byte c = 'a'; String s = “a”; s.equals(b); //return false s.equals(c); //return false b == c; //return true s ==”a”; //return true •Formally speakingFormally speaking: Object.equals return false when the object's classes are different, value (or refrence) are different •HoweverHowever: litterals or charecter/integer between 0..128 could surprise us due to java optimization •SuggestionSuggestion: use equals for Object or primitive wrapper and “==” for primitive •RemeberRemeber: when you re-implement equals on your own class re-implement also hashCode() method
  • 5. Giacomo Veneri http://jugsi.blogspot.com5 Java: init class MyClass { public MyClass() { //constructor } { //init before constructor } } • Formally speaking: the block highlighted is callde before the constructor
  • 6. Giacomo Veneri http://jugsi.blogspot.com6 MT: SimpleDateFormat static DateFormat df = new SimpleDateFormat(“yyyy.MM.dd G 'at' HH:mm:ss z”); … df.parse(..); • Formally speaking: SimpleDateFormat is not thread safe • Then: if you declare SimpleDateFormat static or on a singletone class on Multi Thread enviroment (EJB, Web,...) you will experience the most absurd bug of your life • Suggestion: do NOT declare SimpleDateFormat as attribute or static member of your class
  • 7. Giacomo Veneri http://jugsi.blogspot.com7 MT: logging • Some frameworks such as log4j or logback block execution (synchronization) to write into a file. • Suggestion: consult logback or log4j documentation to use Async Logging
  • 8. Giacomo Veneri http://jugsi.blogspot.com8 MT: volatile volatile MyCache cache = null; public MyCache getCache() { if (cache ==null) || (elapsed(cache)) { synchronized(this) { if (cache ==null) { … // create cache } } } else return cache; } • Formally speaking: thread should save local variable on thread stuck • Then: if another thread acquire the lock and modify the local variable the second thread could NOT see the change • Suggestion: volatile force s the thread to read the in memory variable; volatile reduces performance (1:10) • Reference: look for “double check” on google
  • 9. Giacomo Veneri http://jugsi.blogspot.com9 JEE: java.library.path • When you need to connect your java EE application to an EIS you must use JCA –Connector Architecture (JCA) is a Java-based technology solution for connecting application servers and enterprise information systems (EIS) • However: if you are too lazy to implement your JCA component you might be tempted to declare the java.library.path to point your native library • Then: you can overwrite the native library used by your application server –Weblogic uses java.library.path to pint native io in order to improve performance • Suggestion: use JCA …. or …. find java.library.path of your application server and adjust it –Be caught! On multi server or cluster environent you can modify the entire behavior
  • 10. Giacomo Veneri http://jugsi.blogspot.com10 MT: transient @EJB transient MyEjb myEjb; • Formally speaking: using transient java doesn't serialize the object, rseources (Connection or EJB) on JEE cannot be serialized • Then: on Migratable server two node could share session each other • Suggestion: use transient when you reference resources
  • 11. Giacomo Veneri http://jugsi.blogspot.com11 java.util collection efficiency from 10 to 1 10 new HashMap() 08 new TreeMap() 03 new Hashtable(n) : synchronized and define capacity 02 new Hashtable() : synchronized 01 Collections.synchronizedMaps (new HashMap()) 01 Collections.synchronizedColle ctions(new ArrayList()) 03 new Vector(n) : synchronized and define capacity 02 Vector : synchronized 10 Iterator, Enumeration 09 new ArrayList(n): define capacity 08 new ArrayList() 07 new LinkeList(n) : manage queue and define capacity 06 new LinkeList() : manage queue 05 new HashSet() : prevent duplicate 04 new TreeSet() : implements sorting
  • 12. Giacomo Veneri http://jugsi.blogspot.com12 java.util collection The given table is just a reference to take in consideration but Map and set are not comprable ... 1.Use ensureCapacity for better performance to write data 2.Performance of LinkedList decreases when size increases 3.Iterator is faster than “for cycle” over set, but, on Map, when you ned to create iterator by keySet, doesn't produce any valuable difference
  • 13. Giacomo Veneri http://jugsi.blogspot.com13 Quiz ;-) • How many issues did you know – 3 maybe you are 3 year experienced programmer – 5 maybe you are 5 year experienced programmer – 7 maybe you are junior JEE architect – 10 you are senior JEE architect – ..or maybe not
  • 14. 16/07/13 Giacomo Veneri - http://jugsi.blogspot.com14 Giacomo Veneri, PhD, MCs (IT Manager, Human Computer Interaction Scientist) @venergiac g.veneri@ieee.org http://jugsi.blogspot.com My Professional Profile http://it.linkedin.com/in/giacomoveneri My Publications on HCI http://scholar.google.it/citations?user=B40SHWAAAAAJ My Research Profile http://www.scopus.com/authid/detail.url?authorId=36125776100 http://www.biomedexperts.com/AuthorDetailsGateway.aspx?auid=2021359 https://www.researchgate.net/profile/Giacomo_Veneri/