SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Java Code Conventions  Java Tips & Tricks Italtel, Italtel logo and iMSS (Italtel Multi-Service Solutions) are registered trademarks owned by Italtel S.p.A. All other trademarks mentioned in this document are property of their respective owners.  Italtel S.p.A. cannot guarantee the accuracy of the information presented, which may change without notice.  All contents are  © Copyright 2006 Italtel S.p.A. - All rights reserved.  Domenico Briganti
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Attenzione!! ,[object Object]
Java Code Style ,[object Object],[object Object]
Java Code Style 1/10 ,[object Object],[object Object],[object Object],Dominio Progetto Modulo
Java Code Style 2/10 ,[object Object],[object Object],[object Object],[object Object]
Numeri ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C Con lo “0” davanti, il numero è un ottale.
Java Code Style 3/10 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Code Style 4/10 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Code Style 5/10 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operazione aritmetiche ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C
Java Code Style 6/10 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Code Style 7/10 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Code Style 8/10 ,[object Object],[object Object],[object Object],[object Object],[object Object]
Stringhe ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],A
Java Code Style 9/10 ,[object Object],[object Object],[object Object],[object Object]
Java Code Style 10/10 ,[object Object],[object Object],[object Object]
Java Code Style Riepilogo ,[object Object],[object Object],[object Object],[object Object]
Java Code Style Tools ,[object Object],[object Object],[object Object]
Java Code Style DEMO Classe sottoposta alla verifica ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Code Style DEMO Risulatato della verifica
Debug Remoto (JPDA) - Demo ,[object Object],[object Object],[object Object],[object Object],[object Object]
Ant con JUnit Cobertura e CheckStyle ,[object Object]
FindBug e PDM ,[object Object],[object Object],[object Object],[object Object]
Java Tips & Tricks ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
La gerarchia di classe delle eccezioni Object Throwable Error Exception LinkageError Virtual MachineError AWTError RuntimeException ClassNotFoundException NullPointerException IndexOutOfBoundException ArthemticException NoSuchMethodException Eccezioni non controllate
Eccezioni checked e unchecked ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Catch annidati e blocco finally ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],9
Exception propagation main() : … demo.level1() … level1() : … try{ … level2()  …} catch( ArithmeticException p) {…}  …. level2() : … level3() … level3() : … c = c / 0;  // divided by zero … normal flow exception flow
C’è qualcosa che non va nel codice sotto? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Quando usare le eccezioni ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Gestione della memoria e Memory Leak Java Memory leak Allocated Reachable Live Handled by JVM
UnsupportedClassVersionError (Unsupported major.minor version 49.0)  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Metodo equals  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],@Override public   boolean  equals(Object obj) { if  (obj  instanceof  MioValore) { MioValore valore = (MioValore) obj; if  (valore.val1.equals(val1) &&  valore.val2.equals(val2)) return   true ; } return   false ; } Quale risultato si ottiene? Come Procedere in questo caso?
Metodo Clone – Shallow copy e deep copy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Clone = {(“ The quick brown fox  jumps over the lazy dog ”)}
Argomenti a linea di comando ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a) AnyProg b) Well c) Done d)ArrayIndexOutOfBoundException Risultato? D
StringBuilder ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Keyword  synchronized ,[object Object],[object Object],[object Object],[object Object],B
Thread ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],D
Overloading ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C
Polimorfismo ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C
Sovrascrittura di metodi ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a) Errore qui b) Errore qui c) Runtime Exception Risultato? B
Interfacce ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classi e variabili Final ,[object Object],[object Object],[object Object]
Costruttori ,[object Object],[object Object],[object Object],[object Object],[object Object],B
Ereditarietà ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a) C,B,B,Main b) Main,A,C,B c) Main,A,B,C d) Main,A,B,A Risultato? B
Switch  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a) Output “default” b) Output “10 20” c) Non compila d) Nessuna di queste Risultato? B
Garbage Collection ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C
Passaggio per Valore o per Riferimento ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a) 15 0 20 b) 15 0 15 c) 20 0 20 d) 0 15 20 Risultato? A
Assegnamento ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Risultato? 3
Instanze di oggetti e campi statici ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],a) Output “SCJP” x 2 b) Output “SCJP” c) Non compila d) NullPointerExc… Risultato? A
Cosa e’ un pattern?  1/2 ,[object Object],[object Object],[object Object]
Cosa e’ un pattern? 2/2 ,[object Object],[object Object],[object Object],[object Object]
Classificazione  1/2 ,[object Object],[object Object],[object Object]
Classificazione 2/2 ,[object Object],[object Object],[object Object]
Observer 1/3 ,[object Object],[object Object],[object Object],[object Object]
Observer 2/3
Observer 3/3 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Factory  1/4 ,[object Object],[object Object],[object Object]
Factory 2/4
Factory 3/4 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Factory:  4/4
Proxy 1/4 ,[object Object],[object Object],[object Object]
Proxy 2/4
Proxy 3/4 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Proxy 4/4 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Più interfacce sulla stessa macchina ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

PHP: strutture di controllo e funzioni
PHP: strutture di controllo e funzioniPHP: strutture di controllo e funzioni
PHP: strutture di controllo e funzioniextrategy
 
Baby Steps TripServiceKata
Baby Steps TripServiceKataBaby Steps TripServiceKata
Baby Steps TripServiceKataAndrea Francia
 
Reachability properties &graphical user interface for cex module
Reachability properties &graphical user interface for cex module Reachability properties &graphical user interface for cex module
Reachability properties &graphical user interface for cex module Giuseppe Sessa
 
Linguaggi Di Programmazione Caso Di Studio
Linguaggi Di Programmazione   Caso Di StudioLinguaggi Di Programmazione   Caso Di Studio
Linguaggi Di Programmazione Caso Di StudioAlartzero
 
06 - Programmazione: Scope Variabili
06 - Programmazione: Scope Variabili06 - Programmazione: Scope Variabili
06 - Programmazione: Scope VariabiliMajong DevJfu
 
4 Strutture Condizionali
4   Strutture Condizionali4   Strutture Condizionali
4 Strutture Condizionaliguest60e9511
 
PHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQLPHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQLextrategy
 
Pe a1 perl-unit_testing
Pe a1 perl-unit_testingPe a1 perl-unit_testing
Pe a1 perl-unit_testingMajong DevJfu
 
08 - Programmazione: Passaggio valori tra funzioni per riferimenti
08 - Programmazione: Passaggio valori tra funzioni per riferimenti08 - Programmazione: Passaggio valori tra funzioni per riferimenti
08 - Programmazione: Passaggio valori tra funzioni per riferimentiMajong DevJfu
 
Mocking Objects Practices
Mocking Objects PracticesMocking Objects Practices
Mocking Objects PracticesGrUSP
 
Design Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency InjectionDesign Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency InjectionRiccardo Cardin
 
Acadevmy - TypeScript Overview
Acadevmy - TypeScript OverviewAcadevmy - TypeScript Overview
Acadevmy - TypeScript OverviewFrancesco Sciuti
 
Design pattern template method
Design pattern template methodDesign pattern template method
Design pattern template methodNelson Firmani
 
Acadevmy - ES6 Modern JS Today
Acadevmy - ES6 Modern JS TodayAcadevmy - ES6 Modern JS Today
Acadevmy - ES6 Modern JS TodayFrancesco Sciuti
 

Was ist angesagt? (20)

PHP: strutture di controllo e funzioni
PHP: strutture di controllo e funzioniPHP: strutture di controllo e funzioni
PHP: strutture di controllo e funzioni
 
Corso java base
Corso java baseCorso java base
Corso java base
 
Baby Steps TripServiceKata
Baby Steps TripServiceKataBaby Steps TripServiceKata
Baby Steps TripServiceKata
 
PHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuroPHP 7 - benvenuto al futuro
PHP 7 - benvenuto al futuro
 
Gcc & Make
Gcc & MakeGcc & Make
Gcc & Make
 
Reachability properties &graphical user interface for cex module
Reachability properties &graphical user interface for cex module Reachability properties &graphical user interface for cex module
Reachability properties &graphical user interface for cex module
 
Java lezione 5
Java lezione 5Java lezione 5
Java lezione 5
 
Linguaggi Di Programmazione Caso Di Studio
Linguaggi Di Programmazione   Caso Di StudioLinguaggi Di Programmazione   Caso Di Studio
Linguaggi Di Programmazione Caso Di Studio
 
06 - Programmazione: Scope Variabili
06 - Programmazione: Scope Variabili06 - Programmazione: Scope Variabili
06 - Programmazione: Scope Variabili
 
4 Strutture Condizionali
4   Strutture Condizionali4   Strutture Condizionali
4 Strutture Condizionali
 
iContract
iContractiContract
iContract
 
PHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQLPHP:funzioni e interazione con MySQL
PHP:funzioni e interazione con MySQL
 
Pe a1 perl-unit_testing
Pe a1 perl-unit_testingPe a1 perl-unit_testing
Pe a1 perl-unit_testing
 
08 - Programmazione: Passaggio valori tra funzioni per riferimenti
08 - Programmazione: Passaggio valori tra funzioni per riferimenti08 - Programmazione: Passaggio valori tra funzioni per riferimenti
08 - Programmazione: Passaggio valori tra funzioni per riferimenti
 
Mocking Objects Practices
Mocking Objects PracticesMocking Objects Practices
Mocking Objects Practices
 
Design Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency InjectionDesign Pattern Architetturali - Dependency Injection
Design Pattern Architetturali - Dependency Injection
 
Js intro
Js introJs intro
Js intro
 
Acadevmy - TypeScript Overview
Acadevmy - TypeScript OverviewAcadevmy - TypeScript Overview
Acadevmy - TypeScript Overview
 
Design pattern template method
Design pattern template methodDesign pattern template method
Design pattern template method
 
Acadevmy - ES6 Modern JS Today
Acadevmy - ES6 Modern JS TodayAcadevmy - ES6 Modern JS Today
Acadevmy - ES6 Modern JS Today
 

Ähnlich wie Java codestyle & tipstricks

Webbit 2004: Tiger, java
Webbit 2004: Tiger, javaWebbit 2004: Tiger, java
Webbit 2004: Tiger, javaMatteo Baccan
 
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con ScalaFranco Lombardo
 
corso web developer - Introduzione a Javascript
corso web developer - Introduzione a Javascriptcorso web developer - Introduzione a Javascript
corso web developer - Introduzione a JavascriptRiccardo Piccioni
 
Deep diving C# 4 (Raffaele Rialdi)
Deep diving C# 4 (Raffaele Rialdi)Deep diving C# 4 (Raffaele Rialdi)
Deep diving C# 4 (Raffaele Rialdi)DotNetMarche
 
Caratteristiche del linguaggio c
Caratteristiche del linguaggio cCaratteristiche del linguaggio c
Caratteristiche del linguaggio cughetta
 
Seam unifies Java EE by Massimiliano Ciccazzo
Seam unifies Java EE by Massimiliano CiccazzoSeam unifies Java EE by Massimiliano Ciccazzo
Seam unifies Java EE by Massimiliano CiccazzoJava User Group Roma
 
April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5JBug Italy
 
Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)
Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)
Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)DotNetMarche
 
Cattive abitudini e-lineeguida
Cattive abitudini e-lineeguidaCattive abitudini e-lineeguida
Cattive abitudini e-lineeguidaRobert Casanova
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Libraryjgiudici
 

Ähnlich wie Java codestyle & tipstricks (20)

Applicazioni native in java
Applicazioni native in javaApplicazioni native in java
Applicazioni native in java
 
Webbit 2004: Tiger, java
Webbit 2004: Tiger, javaWebbit 2004: Tiger, java
Webbit 2004: Tiger, java
 
Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con Scala
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
corso web developer - Introduzione a Javascript
corso web developer - Introduzione a Javascriptcorso web developer - Introduzione a Javascript
corso web developer - Introduzione a Javascript
 
Deep diving C# 4 (Raffaele Rialdi)
Deep diving C# 4 (Raffaele Rialdi)Deep diving C# 4 (Raffaele Rialdi)
Deep diving C# 4 (Raffaele Rialdi)
 
Java lezione 10
Java lezione 10Java lezione 10
Java lezione 10
 
Caratteristiche del linguaggio c
Caratteristiche del linguaggio cCaratteristiche del linguaggio c
Caratteristiche del linguaggio c
 
Seam unifies Java EE by Massimiliano Ciccazzo
Seam unifies Java EE by Massimiliano CiccazzoSeam unifies Java EE by Massimiliano Ciccazzo
Seam unifies Java EE by Massimiliano Ciccazzo
 
April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5April 2010 - Seam unifies JEE5
April 2010 - Seam unifies JEE5
 
Il testing con zend framework
Il testing con zend frameworkIl testing con zend framework
Il testing con zend framework
 
Il testing con zend framework
Il testing con zend frameworkIl testing con zend framework
Il testing con zend framework
 
Java OCA teoria 1
Java OCA teoria 1Java OCA teoria 1
Java OCA teoria 1
 
Java lezione1
Java lezione1Java lezione1
Java lezione1
 
Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)
Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)
Potenza e controllo con le Parallel Libraries (Raffaele Rialdi)
 
Unit testing 101
Unit testing 101Unit testing 101
Unit testing 101
 
Dal C a Java (1/3)
Dal C a Java (1/3)Dal C a Java (1/3)
Dal C a Java (1/3)
 
Java lezione 17
Java lezione 17Java lezione 17
Java lezione 17
 
Cattive abitudini e-lineeguida
Cattive abitudini e-lineeguidaCattive abitudini e-lineeguida
Cattive abitudini e-lineeguida
 
JSP Tag Library
JSP Tag LibraryJSP Tag Library
JSP Tag Library
 

Mehr von Domenico Briganti (8)

Software Testing e TDD
Software Testing e TDDSoftware Testing e TDD
Software Testing e TDD
 
XSLT
XSLT XSLT
XSLT
 
XSL-FO
XSL-FOXSL-FO
XSL-FO
 
XML Schema (XSD)
XML Schema (XSD)XML Schema (XSD)
XML Schema (XSD)
 
Xml annessi e connessi
Xml annessi e connessiXml annessi e connessi
Xml annessi e connessi
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Testing
TestingTesting
Testing
 
Xml Xslt
Xml  XsltXml  Xslt
Xml Xslt
 

Java codestyle & tipstricks

  • 1. Java Code Conventions Java Tips & Tricks Italtel, Italtel logo and iMSS (Italtel Multi-Service Solutions) are registered trademarks owned by Italtel S.p.A. All other trademarks mentioned in this document are property of their respective owners. Italtel S.p.A. cannot guarantee the accuracy of the information presented, which may change without notice. All contents are © Copyright 2006 Italtel S.p.A. - All rights reserved. Domenico Briganti
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Java Code Style DEMO Risulatato della verifica
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. La gerarchia di classe delle eccezioni Object Throwable Error Exception LinkageError Virtual MachineError AWTError RuntimeException ClassNotFoundException NullPointerException IndexOutOfBoundException ArthemticException NoSuchMethodException Eccezioni non controllate
  • 27.
  • 28.
  • 29. Exception propagation main() : … demo.level1() … level1() : … try{ … level2() …} catch( ArithmeticException p) {…} …. level2() : … level3() … level3() : … c = c / 0; // divided by zero … normal flow exception flow
  • 30.
  • 31.
  • 32. Gestione della memoria e Memory Leak Java Memory leak Allocated Reachable Live Handled by JVM
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 58.
  • 59.
  • 61.
  • 63.
  • 65.
  • 66.
  • 67.

Hinweis der Redaktion

  1. 1- At the beginning of GC cycle, objects that are allocated but no longer reachable are reclaimed by the Garbage collector.