Saturday, September 12, 2015

Check Disk space in Linux

To check disk space in linux operating system through command line use the following command.

df -h //show all the media and the total amount of space available and total space used.

du -h --max-depth=1 //foldername (for eg var, html, data)

This command shows you the space occupied by the folder till level 1.
If you want to see more deep than you can replace the depth=1 by any number for nth level.

Destroy a session in PHP

Suppose a session have started and you want to destroy the whole all data of session.
You can use the following inbuilt function of php.

session_start();
session_destroy();

This will destroy all the session and all the data associated with it.

Session ID in PHP

If a session is already started or if you want to check if a session have started or is active/valid then you can check in the following way.

session_start();
$session_id = session_id();

if($session_id){
echo "Session is Vaild and ID is: ".$session_id;
}
else{
echo "No Session have started";
}

Sunday, May 26, 2013

Change Background Color In Java

/*Program for background color changing using scrollbar*/

import java.awt.*;
import java.awt.event.*;

class sroll extends Frame implements AdjustmentListener,ActionListener
   {
        Button b;
        Scrollbar sr,sg,sb;
        Label lr,lg,lb;

public sroll()
  {
           b=new Button("EXIT:");
                       lr=new Label("RED:");
          lg=new Label("GREEN:");
          lb=new Label("BLUE:");

                       sr=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
          sg=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);
          sb=new Scrollbar(Scrollbar.HORIZONTAL,0,1,1,255);

           b.addActionListener(this);
           sr.addAdjustmentListener(this);
          sg.addAdjustmentListener(this);
          sb.addAdjustmentListener(this);

                      setLayout(new FlowLayout());

          add(lr);  add(sr);  add(lg);  add(sg);  add(lb);  add(sb);
add(b);

}


    public void actionPerformed(ActionEvent a1)
      {

System.exit(0);

       }



                 public void adjustmentValueChanged(AdjustmentEvent ae)
      {

 int r=sr.getValue();
 int g=sg.getValue();
 int b=sb.getValue();

Color c=new Color(r,g,b);

   setBackground(c);
   }

public static void main(String args[])
 {


sroll a=new sroll();

a.setSize(200,200);

a.setVisible(true);
}

    }

Convert Checkbox To Radio Button In Java

/*Program to convert checkboxes into radio buttons*/

import java.awt.*;

class elec extends Frame
  {
     Label l1,l2;
     Checkbox a,b,c,d,e,f;
     CheckboxGroup x,y;

        public elec()
{
  setTitle("UNIVERSITY FORM:");
               l1=new Label("OPTION 1:");
  l2=new Label("OPTION 2:");
               x=new CheckboxGroup();
               y=new CheckboxGroup();
              a=new Checkbox("maths",false,x);
              b=new Checkbox("chem",false,x);
              c=new Checkbox("physics",false,x);
              d=new Checkbox("biology",false,y);
              e=new Checkbox("english",false,y);
              f=new Checkbox("hindi",false,y);

          setLayout(new FlowLayout());

          add(l1); add(a);  add(b);  add(c);
          add(l2); add(d);  add(e);  add(f);
  }

    public static void main(String args[])throws Exception
       {
 
           elec r=new elec();

           
            r.setSize(200,300);
            r.setVisible(true);
       }
 
 } 

File Writing In Java

/*Program For File Writing In Java*/

import java.io.*;


class simple
  {
      public static void main(String args[])throws Exception
        {
                File f=new File("F:\\YOGESH (COLLEGE PROJECTS)\\sybsc");
            String fnames[]=f.list();
             

    System.out.println("NAME"+"  "+"LENGTH"+"  "+"STATUS"+"  "+"TYPE");

            for(int i=0;i<fnames.length;i++)
{
  File f1=new File("F:\\YOGESH (COLLEGE PROJECTS)\\sybsc",fnames[i]);
       
               System.out.print(" "+f1.getName());
   System.out.print(" "+f1.length());
if(f1.canRead()==true)
{
  System.out.print(" "+"R");
}
if(f1.canWrite()==true)
 {
   System.out.print(" "+"w");
 }
if(f1.isFile()==true)
{
  System.out.print(" "+"FILE");
}
if(f1.isDirectory()==true)
{
 System.out.print(" "+"DIR");
}
                        System.out.println("");
       }
      }
 }

Number Conversion in Java

/*Program for conversion of a decimal no into binary,octal,hexadecimal*/

import java.string.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;


class dec extends Frame implements ActionListener
 {
     int n,d,a,no,i;
     int ans[]=new int[20];
     String s;
      String d="";
     Button b1,b2,b3,b4,b5,b6;
     TextField t1,t2,t3,t4;
 
         public dec()
              {
        b1=new Button("ENTER NUMBER:");
        b2=new Button("BINARY NUMBER:");
        b3=new Button("OCTAL NUMBER:");
        b4=new Button("HEXADECIMAL NUMBER:");
        b5=new Button("RESET:");
        b6=new Button("EXIT:");
        t1=new TextField(20);
        t2=new TextField(20);
        t3=new TextField(20);
        t4=new TextField(20);

                  setLayout(new FlowLayout());

                  add(b1); add(t1);  add(b2);  add(t2);  add(b3);  add(t3);  add(b4);  add(t4);
      add(b5);  add(b6);

                    b1.addActionListener(this);
       b2.addActionListener(this);
       b3.addActionListener(this);
       b4.addActionListener(this);
       b5.addActionListener(this);
       b6.addActionListener(this);
  }

    public void actionPerformed(ActionEvent ae)
{
 
  if(ae.getSource()==b2)
     {
       s=t1.getText();
         a=Integer.parseInt(s);

                         no=a;                      
                     for(i=1;no!=0;i++,no/=2)
                           ans[i]=no%2;
                       for(i--;i>0;i--)
                            d+=ans[i];  
                       if(t2.getText().equals(""))
                             t2.setText(d);
     }

if(ae.getSource()==b3)
     {
       s=t1.getText();

no=a;
for(d="",no=a,i=1;no!=0;i++,no/=8)  
                        ans[i]=no%8;
                       for(i--;i>0;i--)
                            d+=ans[i];
                         if(t3.getText().equals(""))
                             t3.setText(d);
   }


if(ae.getSource()==b3)
     {
       s=t1.getText();

no=a;
for(d="",no=a,i=1;no!=0;i++,no/=16)
                           ans[i]=no%16;
                     for(i--;i>0;i--)
                          {
                              switch(ans[i])
                                  {
                                       case 10:d+="A";  break;
                                       case 11:d+="B";  break;
                                       case 12:d+="C";  break;
                                       case 13:d+="D";  break;
                                        case 14:d+="E";  break;
                                      case 15:d+="F";  break;
                                      default:d+=ans[i];
                                  }
                        }
                              if(t4.getText().equals(""))
                                    t4.setText(d);
                  }

if(ae.getSource()==b5)
     {
            t1.setText("");
     }

if(ae.getSource()==b6)
     {

System.exit(0);
     }
}

      public static void main(String args[])throws Exception
{
    dec de=new dec();

     de.setSize(200,400);
     de.setVisible(true);
}
    }




Pattern in Java

/**Program For Design pattern in java**/

import java.io.*;

class loop
  {
       int i,j,n;

      public void getdata()throws Exception
         {
             BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
               System.out.println("ENTER THE NUMBER OF LINES TO BE PRINTED:");
                 n=Integer.parseInt(br.readLine());
         }
     public void display()
         {
              for(i=0;i<n;i++)
                {
                  for(j=i;j<n;j++)
                    {
                        System.out.print("*");
                    }
                        System.out.println(" ");        
                 }
                           
                   
          }
                   
             
        public static void main(String args[])throws Exception
         {
            loop l=new loop();
   
             l.getdata();
             l.display();
         }
  }
 

Graphics in Java

/**Graphics In Java Example **/

import java.awt.*;
import java.awt.event.*;

class line extends Frame implements MouseListener,ActionListener
 {

     int x1,x2,y1,y2;
     Button b;
   
public line()
 {
 
    addMouseListener(this);
                 b=new Button("EXIT");

     setLayout(new FlowLayout());
                    add(b);
                       b.addActionListener(this);
 }

public void actionPerformed(ActionEvent ae)
 {

     System.exit(0);
 }


public void mousePressed(MouseEvent me)
 {
    x1=me.getX();
    y1=me.getY();
 }

public void mouseReleased(MouseEvent me)
 {
    x2=me.getX();
    y2=me.getY();
 
    Graphics g=getGraphics();

   g.drawLine(x1,y1,x2,y2);
}

public void mouseClicked(MouseEvent me)
 {
 }

public void mouseEntered(MouseEvent me)
 {
 }

public void mouseExited(MouseEvent me)
 {
 }

public static void main(String args[])throws Exception
 {

     line l=new line();

    l.setSize(600,600);
    l.setVisible(true);
}

    }

Inheritance in Java

/**Program For Inheritance in Java**/


import java.lang.*;

class xyz
  {
       int x;
     
public void getdata()
  {
    x=5;
  }
public void putdata()
 {
   System.out.println(x);
 }
  }

class abc extends xyz
  {
       int a;

public void getdata()
{
  a=7;
}
public void putdata()
{
  System.out.println(a);
}

public static void main(String args[])throws Exception
    {  
abc a=new abc();
xyz x=new xyz();

         

x.getdata();
a.getdata();
x.putdata();
a.putdata();
 }
  }

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...