Monday, March 13, 2017

how to download Virtual-box and setup Ubuntu

Virtual Box is cross platform visualization application, it installs on you personal computer, where you running your current operating system. Virtual Box extends capabilities of your current existing system, so it can run multiple operating system simultaneously on virtual machine,
Here is link to download
 then you can see such icon in download section .


By clicking this icon you can start install of virtual box. and follow next step all the way.
















After clicking next , button and completing installation step. you can open virtual box.















Now you can click on new button and you can name the system and select operating system for your virtual machine.



















This process will let you create a virtual machine of your desired Operating system and environment, then click next for other step.




















After creating virtual machine you need to allocate certain memory to it,



















In this step you need to create virtual hard disk for your environment. After create click on expert mode option so you can select fixed size, rather then dynamic.

















Click on create, so virtual box will start to create virtual hard disk. and you can see virtual box xyz  icon on virtual machine in next image .






















Thursday, February 16, 2017

Learning SQL from Basic


  1. Lets talk about SQL, Question arise in our mind what does SQL stand for? 
  • It is very simple Structure Query Language.
       2. Just think why it is called Structure Query Language ?
  • Because coding sequence and execution sequence in SQL differ from each other. 
           SQL is computer database language used to store  manipulate  and retrieve data from database in Relational database.SQL has various types of commands to execute on basis of it it is further classified in three types command:
  1. Data Definition Language 
  2. Data Manipulation Language
  3. Data Control Language
Data Definition Language 

CREATE: it is used t create a table,view or an object  in database.
DROP: Delete a entire table, view or a object in database.
ALTER: Modify an database object, mostly table. 

Data Manipulation Language  

INSERT: Insert a data 
DELETE : Delete a record.
UPDATE : To update a record 

Data Control Language

GRANT: It is used to give access to user.
REVOKE: To take back the grant from user.



Saturday, March 12, 2016

How to create LinkList in java

Linked list is data Structure which contain linear collection of data elements as Node in such way that every node refer to next node in List.Here in java let us create class node which contain integer data and reference to the next node in Link list.

This is class Node which is in file Node.java

public class Node
{
protected int data;
    protected Node link;

    //  Constructor to class Node with initially refer to null and set data to 0 by default
    public Node()
    {
        link = null;
        data = 0;
    }  
    //  Constructor to class Node which has both data and reference to next node
    public Node(int d,Node n)
    {
        data = d;
        link = n;
    }  
    //  Function that set link to next Node (which refer to next node
    public void setLink(Node n)
    {
        link = n;
    }  
    //  Function which assign integer  data to current Node
    public void setData(int d)
    {
        data = d;
    }  
    /*  Function to get link to next node  */
    public Node getLink()
    {
        return link;
    }  
    /*  Function to get data from current Node  */
    public int getData()
    {
        return data;
    }
}


Class LinkedList  in which  methods involved in it. Linkedlist.java file

import java.util.Scanner;

public class Linkedlist
{
protected Node start;
   protected Node end ;
   public int size ;
public Scanner sc;

   /*  Constructor  */
   public Linkedlist()
   {
       start = null;
       end = null;
       size = 0;
   }
   /*  Function to check if list is empty  */
   public boolean isEmpty()
   {
       return start == null;
   }
   /*  Function to get size of list  */
   public int getSize()
   {
       return size;
   }  
   /*  Function to insert an element at begining  */
   public void insertAtStart(int val)
   {
       Node nptr = new Node(val, null);  
       size++ ;  
       if(start == null)
       {
           start = nptr;
           end = start;
       }
       else
       {
           nptr.setLink(start);
           start = nptr;
       }
   }
   /*  Function to insert an element at end  */
   public void insertAtEnd(int val)
   {
       Node nptr = new Node(val,null);  
       size++ ;  
       if(start == null)
       {
           start = nptr;
           end = start;
       }
       else
       {
           end.setLink(nptr);
           end = nptr;
       }
   }
   /*  Function to insert an element at position  */
   public void insertAtPos(int val , int pos)
   {
       Node nptr = new Node(val, null);              
       Node ptr = start;
       pos = pos - 1 ;
       for (int i = 1; i < size; i++)
       {
           if (i == pos)
           {
               Node tmp = ptr.getLink() ;
               ptr.setLink(nptr);
               nptr.setLink(tmp);
               break;
           }
           ptr = ptr.getLink();
       }
       size++ ;
   }
   /*  Function to delete an element at position  */
   public void deleteAtPos(int pos)
   {      
       if (pos == 1)
       {
           start = start.getLink();
           size--;
           return ;
       }
       if (pos == size)
       {
           Node s = start;
           Node t = start;
           while (s != end)
           {
               t = s;
               s = s.getLink();
           }
           end = t;
           end.setLink(null);
           size --;
           return;
       }
       Node ptr = start;
       pos = pos - 1 ;
       for (int i = 1; i < size - 1; i++)
       {
           if (i == pos)
           {
               Node tmp = ptr.getLink();
               tmp = tmp.getLink();
               ptr.setLink(tmp);
               break;
           }
           ptr = ptr.getLink();
       }
       size-- ;
}
public void reverse(){

Linkedlist newList = new Linkedlist();
Node node = start;
for(int i=0; i newList.insertAtStart(node.getData());
node = node.getLink();
}
//Update the start and end of the original list
start = newList.start;
end = newList.end;
}

public void findelement(){

System.out.println("enter a element u wanted to know position");
Linkedlist l = new Linkedlist();
Node n = start;
sc = new Scanner(System.in);
int i = sc.nextInt();
int a=1;

while(i!=n.getData()){
a++;
if(n.getLink() == null)
{
System.out.println("Count not find element " + i + " in the list");
return;
}
n=n.getLink();
}
System.out.println("index is " +a);
}

public void display(){
System.out.println("single linked list is +  ");
if(size==0){
System.out.println("empty linklist");
}

if(start.getLink()==null){
System.out.println(start.getData() );
        return;
}
Node ptr = start;
    System.out.print(start.getData()+ "->");
    ptr = start.getLink();
    while (ptr.getLink() != null)
    {
        System.out.print(ptr.getData()+ "->");
        ptr = ptr.getLink();
    }
    System.out.print(ptr.getData()+ "\n");
}
}

This is a main program which involve  execution of main method and calls the method of Linkedlist class.

import java.util.Scanner;
public class singlelist {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Linkedlist list = new Linkedlist();
System.out.println("Single linkedlist display");
char ch;
do
       {
           System.out.println("\nSingly Linked List Operations\n");
           System.out.println("1. insert at begining");
           System.out.println("2. insert at end");
           System.out.println("3. insert at position");
           System.out.println("4. delete at position");
           System.out.println("5. check empty");
           System.out.println("6. get size");
           System.out.println("7. reverse list");
           System.out.println("8. tacke element");
           int choice = sc.nextInt();            
           switch (choice)
           {
           case 1 : 
               System.out.println("Enter integer element to insert");
               list.insertAtStart( sc.nextInt() );                     
               break;                          
           case 2 : 
               System.out.println("Enter integer element to insert");
               list.insertAtEnd( sc.nextInt() );                     
               break;                         
           case 3 : 
               System.out.println("Enter integer element to insert");
               int num = sc.nextInt() ;
               System.out.println("Enter position");
               int pos = sc.nextInt() ;
               if (pos <= 1 || pos > list.getSize() )
                   System.out.println("Invalid position\n");
               else
                   list.insertAtPos(num,pos);
               break;                                          
           case 4 : 
               System.out.println("Enter position");
               int p = sc.nextInt() ;
               if (p < 1 || p > list.getSize() )
                   System.out.println("Invalid position\n");
               else
                   list.deleteAtPos(p);
               break;
           case 5 : 
               System.out.println("Empty status = "+ list.isEmpty());
               break;                   
           case 6 : 
               System.out.println("Size = "+ list.getSize() +" \n");
               break;                         
           case 7 :
            list.reverse();
            System.out.println("reverse linked list = " + list);
            break;
           case 8:
            list.findelement();
            break;
           default : 
               System.out.println("Wrong Entry \n ");
               break;   
           }
           /*  Display List  */ 
           list.display();
           System.out.println("\nDo you want to continue (Type y or n) \n");
           ch = sc.next().charAt(0);                        
       } while (ch == 'Y'|| ch == 'y'); 
}







Sorting an array with N2 (insertion sort Algorithm)

Here is program which allow you to sort an array with  complexity of (n square) in ascending order Here is the program: here it uses 2 for loop to compare
Example:- Program

import java.util.Scanner;
public class inertsort {

public static void main(String[] args) {
int i;
Scanner sc = new Scanner(System.in);
System.out.println("enter how much element u want in array ");
i=sc.nextInt();
int intsort[] = new int[i];
System.out.println("enter element s");
for(int a=0;a intsort[a]=sc.nextInt();
}
System.out.println("Elements in array are ");
for(int a=0;a System.out.print(" "+intsort[a]);
}

for(int m =1;m int temp;
for(int n=m;n>0;n--){
{
if(intsort[n] temp=intsort[n];
intsort[n]=intsort[n-1];
intsort[n-1]=temp;
}
}
}
}
System.out.println("Elements in array are ");
for(int a=0;a System.out.print(" "+intsort[a]);
}

}
}

Output:
enter how much element u want in array 
5
enter element s
100
77
55
85
91
Elements in array are 
 100 77 55 85 91Elements in array are 
 55 77 85 91 100

how to define class and object in Ruby

        Hello friends as Ruby is pure object oriented language , How to define class in ruby and how to access the attributes is very import to learn.
Example lets consider Car class in ruby and speed, color and model as its attributes:
Example : code

irb(main):001:0> class Car
irb(main):002:1> attr_accessor :model,:color,:speed
irb(main):003:1> end

Here you can see using class keyword in ruby we can make class and all contain of class lies between class and end key word.
Car is name of class, and you can notice it nil  keyword shown by ruby interpreter. when class do not return anything nil is returned by it.








How to create object of class in ruby and how to use inheritance with ruby is very simple 
Example :code

irb(main):001:0> class Car
irb(main):002:1> attr_accessor :model,:company,:color
irb(main):003:1> end
=> nil
irb(main):004:0> c1=Car.new
=> #
irb(main):005:0> c1.model="swift"
=> "swift"
irb(main):006:0> c1.color="red"
=> "red"
irb(main):007:0> c1.company="maruti"
=> "maruti"
irb(main):008:0>
Object in ruby

here you can notice that c1 is object of class Car, so new keyword after class keyword with use of .(dot) 
c1 is object of Car class here is how we access the attributes of class.
attr_accessor is keyword used to declare the access to the attributes of class.







     Let see if we inherit property of Car class in Sport_car class: code

irb(main):008:0> class Sport_car < Car
irb(main):009:1> attr_accessor :topspeed
irb(main):010:1> end
=> nil
irb(main):011:0> s1=Sport_car.new
=> #
irb(main):012:0> s1.color="black"
=> "black"
irb(main):013:0> s1.topspeed=500
=> 500
irb(main):014:0>
OOps concept in Ruby

Here we can see with just use "<" and parent class Car we can inherit attributes of Car class in Sport_car class, and also we can add new attributes such as topspeed in sport_car class

Basics Operation with Ruby

Hello friends Ruby is very easy and  intelligent language when you do all operation easily. All thing in Ruby is considered as Class and object. Ruby is pure object oriented language. As you write addition operation in ruby it gives you result directly.
 Example:
write 1+100 you will get 101 on next line

irb(main):001:0> 1+100
=> 101

Here in above example 1 and 100 are treated as object and + is a method which is used to deal with this two objects.
1 and 100 are treated as an object of class Fixnum in ruby. there is a .class method in ruby which return class of an object so you can see it. 
Interactive Ruby

As you can see this example in Interactive Ruby tutorial.and find out class of ruby.













         Now do you know how ruby deals with string and how it is responding when you put +  between two  strings.Example

irb(main):001:0> "shree" + "ram"
=> "shreeram"
String concatenation in ruby
Here you can see adding two sting "shree" and "ram"  you get concatenation of this two strings. but when you add a string and number ruby interpreter gives you error for implicit conversion.
        This clearly state that you can either add two numbers or concatenate  2 strings.








Friday, March 11, 2016

Downloading Ruby and Install

http://www.ruby-lang.org/en/downloads/  just click here and you will be directed to page then download version of ruby you wanted to install.
Install Ruby











Click this to Download
Install ruby


















Click here to Install and give CMD of Ruby 


















This is interactive ruby where you get way to program