Programming is a journey. To achieve effective, clean, easy-to-read, and beautiful Java code, you have to practice programming every day. This session shares some lessons collected along 15 years of Java programming. It includes live code examples of how to write truly object-oriented code; when to make a type (and how to use it on JPA providers); how to properly use encapsulation and polymorphism in "ifless" programming; how to properly take advantage of the enum power; and how to use some very useful open source libraries such as Google Guava and Joda-Time to achieve clean Java code.
Session presented at JavaOne Latin America 2012.
2. Edson Yanaga
• Bacharel em Ciência da Computação/UEM
• Mestre em Engenharia Elétrica/UTFPR
• Desenvolvedor Java desde 1997
• Administrador Unix desde 1999
• Instrutor Líder da GlobalCode desde 2012
3. Certificações
• Oracle Certified Professional, Java Platform,
Enterprise Edition 6 Enterprise JavaBeans
Developer
• Sun Certified Enterprise Architect for the Java
Platform,Enterprise Edition 5 (i)
• Certified ScrumMaster
• Sun Certified Developer for Java Web Services 5
• Sun Certified Specialist for NetBeans IDE
• Sun Certified Web Component Developer for J2EE
1.4
• Sun Certified Programmer for Java 2 Platform 1.4
19. public class Conta {
private BigDecimal saldo = new BigDecimal("0.00");
public BigDecimal getSaldo() {
return saldo;
}
public void setSaldo(BigDecimal saldo) {
this.saldo = saldo;
}
}
20. public class ContaService {
public void somar(Conta conta, BigDecimal valor) {
if (conta == null) {
throw new IllegalArgumentException("Conta não pode ser nula!");
}
if (valor == null) {
throw new IllegalArgumentException("Valor não pode ser nulo!");
}
BigDecimal saldo = conta.getSaldo();
if (saldo == null) {
saldo = new BigDecimal("0.00");
}
saldo = saldo.add(valor);
conta.setSaldo(saldo);
}
}
21. public class Conta {
private BigDecimal saldo = new BigDecimal("0.00");
public BigDecimal getSaldo() {
return saldo;
}
public Conta somar(BigDecimal valor) {
checkNotNull(valor);
saldo = saldo.add(valor);
return this;
}
}
22. public class ContaService {
public void somarValorNaConta(Conta conta, BigDecimal valor) {
checkNotNull(conta);
conta.somar(valor);
}
}