Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Julz Cutaran - Common Pitfalls in Java

on

  • 1,174 views

 

Statistics

Views

Total Views
1,174
Views on SlideShare
1,174
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Julz Cutaran - Common Pitfalls in Java Julz Cutaran - Common Pitfalls in Java Presentation Transcript

  • Common Pitfalls
  • 1. Not specifying columns in your select statement (select *)
  • 2. Select and Transfer . . StringBuffer queryString = new StringBuffer(); queryString.append( &quot;SELECT DISTINCT o.name, o.code, o.price, d.discount “ ); queryString.append( &quot;FROM com.exist.model.Order as o, “ ); queryString.append( &quot;com.exist.model.Discounts as d “ ); . . . Session session = sessionFactory.getCurrentSession(); Query selectQuery = session.createQuery(queryString.toString()); List<Order> orders= selectQuery.list(); . . . List<OrderTo> orderTo = new ArrayList<OrderTo>(); ... for(Order order:orders){ OrderTo oto = new OrderTo oto.setName(order.getName()); . . . orderTo.add(oto); } . . .
  • . . . StringBuffer queryString = new StringBuffer(); queryString.append( &quot;SELECT DISTINCT new com.exist.to.OrdersTO &quot; ); queryString.append( &quot;(o.name, o.code, o.price, d.discount) &quot; ); queryString.append( &quot;FROM com.exist.model.Orders as o, &quot; ); queryString.append( &quot;com.exist.model.Discounts as d “ ); . . . Session session = sessionFactory.getCurrentSession(); Query selectQuery = session.createQuery(queryString.toString()); . . . List<OrdersTO> data = selectQuery.list();
  • 3. Not delegating computations . . . double bills = someService.getBills(referenceNo); double payments = someService.getPayments(referenceNo) double due = bills - payments; . . .
  • public class Computations { private SomeService someService; private double bills; private double payments; private double due; public Computations(SomeService someService, String reference) { bills = someService.getBills(referenceNo); payments = someService.getPayments(referenceNo) due = bills - payments; } ... <getters of bills, payments and due> }
  • . . . Computations computations = new Computations(someService, referenceNo); double bills = computations.getBills(); double payments = computations.getPayments(); double due = computations.getDue(); . . .
  • 4. equals String literal variable.equals(“String Literal”);
  • “ String literal”.equals(variable);
  • 5. Computing using double or Double double minuend = 1.1d; double subtrahend = 1.0d; double difference = minuend – subtrahend; Or Double minuend = 1.1d; Double subtrahend = 1.0d; Double difference = minuend.doubleValue() – subtrahend.doubleValue();
  • BigDecimal minuend = new BigDecimal(1.1).setScale(2, RoundingMode.HALF_EVEN); BigDecimal subtrahend = 1.0d; BigDecimal difference = minuend.subtract(subtrahend);
  • 6. using objects in if If (object.getBooleanProperty()) { ... }
  • if (object!=null && object.getBooleanProperty()) { ... } Or if (object!=null && object.getNumericProperty()>0) { ... }
  • Thanks!