SlideShare una empresa de 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/

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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
 

Similar 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
 

Similar 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
 

Más 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
 

Más 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

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

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/