Sunday, April 26, 2015

What jQuery? Why jQuery? Advantages ? Disadvantages ?

3 comments

Why jQuery? What is jQuery?

What is jQuery?


•  jQuery is a lightweight, "write less, do more",
   JavaScript library.
• The purpose of jQuery is to make it much easier
   to use JavaScript on your website.


Why jQuery?


  There are lots of other JavaScript frameworks out there, but       jQuery seems to be the most popular, and also the most               extendable.
Many of the biggest companies on the Web use jQuery, such as:
 Google
  Microsoft
  IBM
  Netflix



The jQuery library contains the following feature


• HTML/DOM manipulation
• CSS manipulation
• HTML event methods
• Effects and animations
• AJAX
• Utilities


jQuery Syntax

• Basic syntax is: $(selector).action()
• A $ sign to define/access jQuery

Examples:

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


Advantages of jQuery

• Ease of use
• jQuery uses a simple, clean, powerful syntax
• Makes a website look more professional
• Strong open source community
• Lots of plugins available.
• Large library
• jQuery is highly extensible
• Ajax support

Disadvantages  of jQuery

• Functionality maybe limited
• JQuery javascript file required



The Document Ready Event


    • $(document).ready(function(){
    
// jQuery methods go here...
});




• jQuery Selectors

–   jQuery selectors allow you to select and manipulate HTML element(s).

–   jQuery selectors are used to "find" (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.

• All selectors in jQuery start with the dollar sign and parentheses: $().

• The element Selector


– The jQuery element selector selects elements based on the element name.
– You can select all <p> elements on a page like this: $("p")



jQuery Effects - Hide and Show



Syntax:
$(selector).hide(speed);
hide()
$(selector).show(speed);
show()



jQuery Stop Methods

stop()

jQuery Fading Methods


• With jQuery you can fade an element in and out of visibility.
• jQuery has the following fade methods:

• fadeIn()
• fadeOut()
• fadeToggle()
• fadeTo()

jQuery Sliding Methods



• With jQuery you can create a sliding effect on elements.

• jQuery has the following slide methods:

• slideDown()
• slideUp()
• slideToggle()



Why jQuery? What is jQuery?


Read full post »

Sunday, April 19, 2015

INTRODUCTION TO JAVA PROGRAMMING

31 comments


INTRODUCTION TO JAVA PROGRAMMING


¨ Introduced by [James Gosling & team-mates] at Sun Micro-Systems.
¨ Was called Oak but then introduced as Java.

¨ Purpose:-
    à Platform Independence. 
    àNetworking & Internet
    àCan be used with electronic consumer devices.

¨ Java SE (standard edition)

¨ Java EE (Enterprise Edition)

¨ Java ME (Micro edition)



How JAVA is plat-form Independent


¨ Due to Java Architecture it is plat-form independent

¨ Main features of Java Architecture:-
à Java programming language (source program created).
à Java class files
à Java Application program Interface (java API)
à Java Virtual Machine (JVM).


JAVA Architecture


JAVA Architecture


¨ Java does not have its own editor so we can use [Notepad]   to write programs.
¨ Source program is compiled using “javac” compiler in JDK     & after compilation java class file is created.
¨  These class Files are in the form of “Byte-Codes”.

Java Platform


¨JVM+API = Java platform
¨Java platform is different for different machines.

¨i.e. for UNIX, Windows , Mac are different for one another.
¨The variation in hardware environment is taken care by JVM.

¨Which makes Java programming Platform Independent.
    [ Write Once Compile Once & Run On Any Platform]


Role of JVM [Java Virtual Machine]


¨Most important component of java programming.
üJVM executes Java class files & Java API files as required to get output.
üJava API files have native methods that interact with local operating system [Unix , Mac , Windows etc].

Before you run your programs, you must compile them.

¨ compiler: Translates a computer program written in one language into another language.

¤ Java Development Kit includes a Java compiler.
¤ byte code: The Java compiler converts your source code   into a format named byte code that can be executed on   many different kinds of computers.

Compile execute java program

Feature Of JAVA 

¨ Safe
¨ Robust
¨ Multi-threaded
¨ Architecture Neutral
¨ Internet Ready
¨ Simple

Types of Java Program


¨ Using Java language two types of programs can be written.

¨ Application Programs
¨ Applet

¨ Application Programs:-


  •     Used to run program in PC under control of O.S in that machine are called application programs.

¨ Applets:-

  •     Java applets are form of Byte-codes that run in web browser using JVM and executed without any control of O.S in that machine.

  •      Used to add interactive contents to web pages , giving animations etc.

Read full post »

Tuesday, April 7, 2015

What is THREAD in JAVA ?

2 comments

Thread Life Cycle


THREADS IN JAVA


Creating threads by constructor

class mythread implements Runnable //creates second thread
{  
     Thread t;
     int i;
     mythread()
     {
         t=new Thread(this,"mythread"); //creates new second thread
          t.start(); //start the thread       
     }    
     public void run()
     {                   
             for(i=0;i<5;i++)
             {
                 System.out.println("child thread " + i);                
             }                  
     }
}

public class Thread2 {     public static void main(String[] args)    {        new mythread();  //create new second thread          }}



EXAMPLE


class mythread implements Runnable
{
 int i ;
 public void run()
 {
   for(i=0;i<5;i++)
   {
     System.out.println("Child thread :" + i);
   }
 }
}

class createthread
{
 public static void main(String[ ] args)
 {
   mythread m1=new mythread();
   Thread th=new Thread(m1,"mythread");
  th.start();
 }
}


sleep() :-

makes currently executing thread to sleep for milliseconds.

Syntax:-

void sleep(long milliseconds);

 class mythread implements Runnable
{ 
     Thread t;     int i;     mythread()     {         t=new Thread(this,"mythread"); //creates new second thread                 t.start(); //start the thread      
     } }



public void run()     {         try         {          
             for(i=0;i<5;i++)             {                 System.out.println("child thread " + “hello world”);                 Thread.sleep(1000);             }         }         catch(Exception e)         {          
         }      
         System.out.println("Exitng child thread");     }  
  
}


public class Thread2 {
   
    public static void main(String[] args)
    {
        new mythread();  //create new second thread
        int i;
        try
         {            
             for(i=0;i<5;i++)
             {
                 System.out.println("Main thread " + i);
                 Thread.sleep(3000);
             }
         }
         catch(Exception e)
         {
            
         }
        
         System.out.println("Exitng Main thread");       
       
    }
}


Thread Life Cycle





isAlive() :-


Returns the value true or false depending on thread is terminated or not.

getname():-

Returns the name of the thread specified.

currentThread() :-

When a program is started thread is created automatically that is main thread and the main thread can be accessed using the current thread method of the main class.

class mythread implements Runnable //creates second thread{         Thread t;     int i;     mythread()     {         t=new Thread(this,"mythread"); //creates new second thread         System.out.println("  Child thread  :  " + t.getName() );System.out.println("Is Thread Alive ? " + t.isAlive());       
         t.start(); //start the threadSystem.out.println("Is Thread Alive ? " + t.isAlive());
              }  
     public void run()     {                 
             for(i=0;i<5;i++)             {                 System.out.println("child thread " + i);         
             }               
     }   
}



public class methods {
    public static void main(String[] args)
    {
       mythread m1= new mythread(); 
        System.out.println("The main thread is :" + Thread.currentThread().getName());
    }
}


Thread priorities

Threads can be assigned priorities.

 —Thread priorities are used by operating system to find out which runnable thread is to be given C.P.U time. — Priority is given from range 1-10.  The threads with high priority number will be given preference over threads with lower priority for execution.

Pre-defined priorities




MIN_PRIORITY =1

NORM_PRIORITY =5

MAX_PRIORITY =10

When thread is created default priority 5 is assigned to the thread.


Methods to get and set priority

int getPriority();

setPriority(int priority_number);



class thread1 implements Runnable{  int i; public void run(){    for(i=0;i<5;i++)    {        System.out.println("child-1 " + i);     
    }}}

class thread2 implements Runnable{  int i; public void run(){    for(i=0;i<5;i++)    {        System.out.println("child-2 " + "hello world");     }}}

class prioritythread{ public static void main(String[ ] args) {    thread1 m1=new thread1();    thread2 m2=new thread2();Thread t=new Thread(m1,"thread1");Thread t1=new Thread(m2,"thread2"); t.setPriority(Thread.NORM_PRIORITY - 2);t1.setPriority(Thread.NORM_PRIORITY + 2);t.start(); t1.start();
}}





Thread Life Cycle

THREAD-JOIN 

It may be required to wait for a particular thread to complete its task before

other process.

When join method of thread class is called on thread object , the control waits

for the thread to complete its task and becomes a dead thread.




class thread1 implements Runnable{  int i;
public void run(){   for(i=0;i<5;i++)    {        System.out.println("child-1 " + i); 
    }
   }
}

class jointhread{ public static void main(String[ ] args) { int i;    thread1 m1=new thread1();    thread2 m2=new thread2();    Thread t=new Thread(m1,"thread1");     t.start();try{t.join();for(i=0;i<5;i++){ System.out.println("hello world"); }}catch(Exception e){}}

}



Read full post »