Tuesday, 29 November 2016

Facts about Variable Length Argument in Java

Variable Length Argument Rules in Java


                 Java included a feature that simplifies the creation of methods that require variable number of arguments. This is known as vararg. vararg is the short for of Variable Length Arguments.

5 Facts about Variable Length Argument Rules in Java


1. A variable-length argument is specified by three periods (…).

     Eg:

            static void TestVariableArgument(int ... v) {
            }

         This syntax tells the compiler that TestVariableArgument( ) can be called with zero or more arguments.

2. In the case of no arguments, the length of the array is zero.

3. A method can have “normal” parameters along with a variable-length parameter and the variable-length parameter must be the last parameter declared by the method.


4. Overloading a method that takes a variable-length argument is possible.

5. If a method call conflicts with two methods that implements variable argument or other leads to error. 

Thursday, 24 November 2016

JQuery - Introduction

jQuery is a small, light-weight and fast JavaScript library. It is cross-platform and supports different types of browsers. It is very useful for data manipulation.
  • jQuery is a small, fast and lightweight JavaScript library.
  • jQuery is platform-independent.
  • jQuery means "write less do more".
  • jQuery simplifies AJAX call and DOM manipulation.
jQuery features:
  • HTML manipulation
  • DOM manipulation
  • DOM element selection
  • CSS manipulation
  • Effects and Animations
  • Utilities
  • AJAX
  • HTML event methods
  • JSON Parsing
  • Extensibility through plug-in
To starts with,
  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)

jQuery Syntax:

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).

Basic syntax is: $(selector).action()

Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".


Tuesday, 22 November 2016

Initializing a blank final variable in Java


How to initialize a blank final variable in Java?


Example Java Program to demonstrate the initialization of blank final variable using Constructor

                  
                  A field can be declared as final. Doing so prevents its contents from being modified, A final variable that is not initialized at the time of declaration is known as blank final variable. The blank final variable can be only initialized using its constructor method.

                   
                  As per the coding convention, it is common to use all upper case letters to represent a final variable. 


Example: 

  
                    final in REGNO = 15480;

Progam:


//Java Program to demonstrate the initialization of blank final variable using Constructor
class FinalInitialize
{
     final int VALUE;
     FinalInitialize(){       // Constructor
          VALUE=10;           // Initialized final variable inside constructor
          System.out.println("Final Value is : "+VALUE);
     }
}
public class InitializeFinal {
     public static void main(String[] args) {
          new FinalInitialize();
     }
}

               In the above program, The FinalInitialize() constructor initiate the value of the final variable VALUE.

Sunday, 13 November 2016

Java Program to find the Volume of a Box

Volume of a Box in Java


                  The below program demonstrates simple class creation and perform volume calculation of a box.


Program:


class Box {
double width;
double height;
double depth;
}
public class BoxJavaProgram {
    public static void main(String[] args){
        Box mybox = new Box();
        double vol;
        mybox.width = 20;
        mybox.height = 30;
        mybox.depth = 10;
        vol = mybox.width * mybox.height * mybox.depth;
        System.out.println("Volume is " + vol);
    }
}

Output:


Volume is 6000.0