Monday, 9 April 2018



jQuery - Selectors


jQuery Selectors are used to select one or more HTML elements and once the element is selected then we can perform various operation on that. jQuery Selectors are used to select and manipulate HTML elements as part of jQuery library.

All jQuery selectors start with a dollor sign and parenthesis e.g. $(). It is known as the factory function.

The jQuery element selector selects elements based on the element name.

You can select all <p> elements on a page like this:

$("p")

When a user clicks on a button, all <p> elements will be hidden:

Example

$(document).ready(function(){
    $("button").click(function(){
        $("p").hide();
    });
});

Usage of Selectors:

Name:  It selects all elements that match with the given element name.

#ID: It selects a single element that matches with the given id.

.Class: It selects all elements that match with the given class.

Universal(*): It selects all elements available in a DOM.

Examples of jQuery selectors

$("*") Selects all elements

$(this) Selects the current HTML element

$("p.intro") Selects all <p> elements with class="intro"

$("p:first") Selects the first <p> element

$("ul li:first") Selects the first <li> element of the first <ul>

$("ul li:first-child") Selects the first <li> element of every <ul>

$("[href]") Selects all elements with an href attribute

$("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank"

$("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank"

$(":button") Selects all <button> elements and <input> elements of type="button"

$("tr:even") Selects all even <tr> elements

$("tr:odd") Selects all odd <tr> elements




Monday, 12 March 2018

Java Naming Convention

Java naming convention is a simple rule to follow as a developer to decide what to name your identifiers such as class, package, variable, constant, method etc.

Here are rules to follow in Java regarding Naming Convention

Class name: It should start with an uppercase letter and be a noun e.g. Name, String, System, Thread etc.
Interface name: It should start with an uppercase letter and be an adjective e.g. Runnable, Remote, ActionListener etc.
Method name : It should start with lowercase letter and be a verb e.g. actionExecute(), run(), print(), println() etc.
Variable name: It should start with lowercase letter e.g. lastName, messageNumber etc.
Package name: It should be in lowercase letter e.g. impl, lang, sql, util etc.
Constants name: It should be in the uppercase letter. e.g. GREEN, YELLOW, MIN_PRIORITY etc.

Examples

Interface  Furnitures
Class Chair implements Furnitures
void changeName(Strung newValue);
void employeeNo(int value);
com.impl.programs.examples

Java strictly follows the camelcase syntax for naming the class, interface, method and variable.
Camelcase syntax: If name is combined with two words, second word will start with uppercase letter always e.g. actionExecute(), lastName, ActionEvent, ActionListener etc.

Wednesday, 7 February 2018

Simple Java program to print current date and time.


Java program to display current date.

Date function in Java Programming code.



/*
Java Date example.
This Java Date example program describes how Java Date function from utility is being used in Java language.
*/

import java.util.*;

public class JavaDateProgram{

          public static void main(String args[]){
            /*
              Create date object with current date and time.
            */
 Date dateandtime = new Date();
  System.out.println("Current Time is " + dateandtime);

  }
}

Output:


Current Time is Sat Feb 08 16:10:21 IST 2018

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.