tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Google Guava > Basic > Check Not Null Precondition

Check Not Null Precondition 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Preconditions.checkNotNull() API. It throws NullPointerException if the given reference is null.

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.guava.base_tests;


public class CheckNotNullPreTest {

   @param args
  public static void main(String[] args) {

    //NullPointerException - if reference is null
    //Preconditions.checkNotNull(reference, errorMessage)
     * Negative case
    try {
        "This program requires MY_APP_HOME system property");
    catch (NullPointerException e) {
     * Positive case
      "This program requires MY_APP_HOME system property");
    System.out.println("Thanks for providing valid input");


It gives the following output,
java.lang.NullPointerException: This program requires MY_APP_HOME system property
Thanks for providing valid input



Books Recommendation

Your Ad Here
bl  br