Monday, 30 November 2015

java junit4

@Ignore("ignore this test")
@AfterClass
@BeforeClass
@After
@Before
@Test (expected =ArithmeticException.class)
@Test

Sunday, 29 November 2015

How get BigdecimalEnum value in java

package com.org.vipul;

import java.math.BigDecimal;

public class BigdecimalEnum {

public static void main(String[] args) {
System.out.println(Vat.FIVE.getValue());

}

public enum Vat {
ONE(new BigDecimal("1")), TWO(new BigDecimal("2")), THREE(
new BigDecimal("3")), FIVE(new BigDecimal("5"));

private final BigDecimal value;

Vat(BigDecimal val) {
value = val;
}

public BigDecimal getValue() {
return value;
}
}
}

Sunday, 16 August 2015

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

To fix this use this jar

http://commons.apache.org/logging/download_logging.cgi

Add to class path

Wednesday, 8 July 2015

Spring REST xml responce


Spring rest json responce

1) Create bean of JSON view resolver

<bean name="jsonTemplate" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>

2) Return this Json view from modelAndView controller

@RequestMapping(value = "/clients")
public String getAllClientsJSON(Model model) {

model.addAttribute("clients", getClientsCollection());
 return "jsonTemplate";

 }

//getClientsCollection() this meothod will have list of clients

Tuesday, 30 June 2015

how to call a constructor from another constructor in java

how to call a constructor from another constructor in java
Use this keyword to achieve this

public class FooConstructor
{
    private int x;

    public FooConstructor ()
    {
        this(1);
    }

    public FooConstructor (int x)
    {
        this.x = x;
    }
}

Monday, 11 May 2015

what are MVC advantages

what are MVC advantages>>
1) Clear architecture design
2) Easy to expand the architecture
3)Multiple view like  pdf, csv, json, xml