17 December 2014

Project Jigsaw, Changes for use java development kit (JDK)

In Moving toward a modular java, It have impacts on both developers and users. The changes made for modular run-time images to java and now in JDK 9.Moving toward a modular Java, Oracle is ushering in changes that have "significant impact" on both developers and users, including breaking IDEs, a high-ranking Oracle Java official said.

Project Jigsaw modularity improvements had been intended for inclusion in Java 8, which was released in March. But Jigsaw has been deferred until the release of Java 9. With modularization, applications can use just the modules they need, offering performance improvements as well secure boundaries between components. The effort also is intended to make Java more scalable to smaller devices

Other changes in modularization include JRE (Java SE Runtime Environment) and JDK images having identical structures. Previously, a JDK image embedded the JRE in a jre subdirectory; now a JDK image is simply a runtime image that set of development tools and other items found in the JDK.User-editable configuration files that were located in the lib directory now are in the new conf directory. Also, internal file rt.jar, tools.jar and dt.jar have been removed, with the content stored in a more efficient format in implementation-private files in the lib directory.


A new built-in NIO file system provider can be used to access class and resource files stored in a run-time image. Tools previously reading rt.jar and other files directly need to be updated to this file system. 

9 December 2014

Google is building new Android compilers Jack and Jill

new compilers jack and jill could be due to the ongoing dispute with Oracle over the use of Java.

new compilers jack and Jill could be due to the ongoing dispute with Oracle over the use of Java.
What changes for developers yet defined, but part of an ongoing process to cut-down on compile times and optimize Android development process.


The internal process would be Jill adds a new pre-processing and caching step which "shields" Jack from standard .class Java bytecode, where needed, and convert it into .jayce intermediate bytecode instead. Jack then takes the Java source code, and the .jayce bytecode, and converts it into Dalvik bytecode. Removing Java bytecode means would have less of an argument. 

Ubuntu 15.04 Release Dates

Mark Shuttleworth posted a blog in which he announced the codename for the next version of Ubuntu, which will follow ubuntu 14.10 (Utopic).

Original Blog Post

"In my favourite places, the smartest thing around is a particular kind of monkey. Vexatious at times, volant and vogie at others, a vervet gets in anywhere and delights in teasing cats and dogs alike. As the upstart monkey in this business. I can think of no better mascot. And so let’s launch our vicenary cycle, our verist varlet, the Vivid Vervet!"

23-apr-2015 is the tentative release date being given for Ubuntu 15.04 ‘Vivid Vervet’. Ubuntu’s 14.04 LTS went live on 17-apr-2014. The starting alpha release will shortly available from 18th December.

How to install PHP in Ubuntu 14.10?

Step 1 : Install Apache

sudo apt-get update
sudo apt-get install apache2

Step 2: install MYSQL

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

Step 3: install php


sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Step 4: Restart Apache

sudo service apache2 restart

you can find your web-server files in /var/www/html Directory

to check installation add index.php file with code

phpinfo();
?>

Check with Firefox http://localhost or http://127.0.01. 


31 August 2014

How to show a dialog to confirm that the user wishes to exit an Android Activity?

private Toast toast;
private long lastBackPressTime = 0;

@Override
public void onBackPressed() {
  if (this.lastBackPressTime < System.currentTimeMillis() - 4000) {
    toast = Toast.makeText(this, "Press back again to close this app", 4000);
    toast.show();
    this.lastBackPressTime = System.currentTimeMillis();
  } else {
    if (toast != null) {
    toast.cancel();
  }
  super.onBackPressed();
 }
}

3 May 2013

Solution Microsoft Acess ODBC 64-bit Driver


It's likely the shortcut for setting ODBC data sources is pointing to the 32bit data sources instead of 64bit.
Go to control panel -> administrative tools --> select data sources(ODBC) --> then right click on that file --> go to properties --> in the shortcut tab -> change the path from %windir%\System32\odbcad32.exe to
%windir%\SysWOW64\odbcad32.exeand make your connection. the driver for MS Access will work fine now.

23 March 2013

JAVA SERVLET CODE TO DOWNLOAD A .txt file

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import javax.servlet.ServletException;  
 import javax.servlet.http.HttpServlet;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpServletResponse;  
 /**  
  *  
  * @author Niraj Chauhan  
  */  
 public class DownloadFile extends HttpServlet {  
   protected synchronized void processRequest(  
       HttpServletRequest request,  
       HttpServletResponse response)  
   throws ServletException, IOException {  
     String filePath=request.getParameter("filePath");  
     System.out.println("filePath = "+filePath);  
     String fileName="file1";  
     if(filePath == null)return;  
     if(filePath.contains("/")){  
       String[] b = filePath.split("/");  
       fileName=b[b.length-1];  
     }          
     response.setHeader("Content-Length", String.valueOf(new File(filePath).length()));      
     response.setContentType( "application/octet-stream" );  
     //response.setContentType("application/vnd.ms-excel");  
         // System.out.println(".......response.getContentType() = "+response.getContentType());  
         response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");  
     FileInputStream inputStream = null;  
     try  
     {  
     inputStream = new FileInputStream(filePath);  
     System.out.println(" INPUTSTREAM CREATED");  
     byte[] buffer = new byte[1024];  
     int bytesRead = 0;  
     do{  
         bytesRead = inputStream.read(buffer, 0, buffer.length);  
         response.getOutputStream().write(buffer);  
     }while (bytesRead == buffer.length);  
     System.out.println(" END OF WHILE");  
     response.getOutputStream().flush();  
     System.out.println(" FLUSHING DONE");  
     }catch(Exception e){  
        System.out.println("Exception in DownloadFile.java ="+e);  
     }finally{  
     if(inputStream != null)  
         inputStream.close();  
     System.out.println(" INPUT STREAM CLOSED");  
     }  
   }  
   //   
   /**  
    * Handles the HTTP GET method.  
    * @param request servlet request  
    * @param response servlet response  
    * @throws ServletException if a servlet-specific error occurs  
    * @throws IOException if an I/O error occurs  
    */  
   @Override  
   protected void doGet(HttpServletRequest request, HttpServletResponse response)  
   throws ServletException, IOException {  
     processRequest(request, response);  
   }  
   /**  
    * Handles the HTTP POST method.  
    * @param request servlet request  
    * @param response servlet response  
    * @throws ServletException if a servlet-specific error occurs  
    * @throws IOException if an I/O error occurs  
    */  
   @Override  
   protected void doPost(HttpServletRequest request, HttpServletResponse response)  
   throws ServletException, IOException {  
     processRequest(request, response);  
   }  
   /**  
    * Returns a short description of the servlet.  
    * @return a String containing servlet description  
    */  
   @Override  
   public String getServletInfo() {  
     return "Short description";  
   }//   
 }  

19 March 2013

Convert JAVA DATE to MS SQL datetime format

 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
 Date javaDate=new Date();  
 System.out.println("Java Date : "+javaDate);  
 String msSqlDate=sdf.format(javaDate).trim();  
 System.out.println("Ms Sql Date : "+msSqlDate.replace(" ","T"));  
 insert into DATA (CREATED) values (convert(datetime,'"+msSqlDate+"'));  

JAVA CODE FOR LEFT SHIFT AND RIGHT SHIFT AND BITWISE OPERATOR

 public class Main {  
   /**  
    * @param args the command line arguments  
    */  
   public static void main(String[] rk) {  
     // range of int -2,147,483,648 to 2,147,483,647  
     // int is 32bit so below i have taken 32bits  
     int a=10; // a= 00000000 00000000 00000000 00001010 = 10 [ten]  
     a=a<<2; // left shift operator  
     //now a=00000000 00000000 00000000 00101000 = 40 [fourty]  
     System.out.println("a="+a);  
     // same way right shift operator  
     int b=2; // ..... 00000010  
     int c=2; // ..... 00000010  
     int d= c& b; //...00000010     
     System.out.println("[logican AND] c ="+c);  
     d=c|b;  
     System.out.println("[logical OR] c ="+c);  
     // same way change value of b=1 and c=2 then you could uderstand how it works bit by bit.  
   }  
 }  

java interfeces

JAVA :READ SOMETHING IMPORTANT ABOUT INTERFACE

i) All interface methods are implicitly public and abstract. In other words,
you do not need to actually type the public or abstract modifiers in the
method declaration, but the method is still always public and abstract.

ii) All variables defined in an interface must be public, static, and final—
in other words, interfaces can declare only constants, not instance variables

iii) Interface methods must not be static.

iv) Because interface methods are abstract, they cannot be marked final,
strictfp, or native.

v) An interface can extend one or more other interfaces.

vi) An interface cannot extend anything but another interface.

vii) An interface cannot implement another interface or class.

viii) An interface must be declared with the keyword interface.

ix) Interface types can be used polymorphically

Set CSS Using JavaScript

 function setSCC(){  
         var element=document.getElementById("add");        element.className='btn_disable';   
         element.style.height="100px";  
         element.style.width="200px";  
         element.disable=true;  
 }  
 Note : Above function can get the element having id="add". and it will set its css class to "btn_disable" and will set it height and width as specified , as well as it will disable the button.  
 u should have the css included in your page.  
 common.css  
 --------------------  
 .btn_disable  
 {  
    font-family: Arial;  
  font-size:10pt;  
  height:30px;  
     background-color:gray;  
    color:red;  
 }  

JAVA SCRIPT TO VALIDATE TIME IN "dd-mm-yyyy hh:mm:ss" FORMAT

 function validateStartTime() {  
  //This function will validte the datetimes of this format : dd-mm-yyyy hh:mm:ss  
  var date  = document.getElementById("startTime").value.trim();  
   var valid  = true;  
   var spaceIndex = date.indexOf(" ");  
   var onlyDate = date.substring(0,spaceIndex);  
   var dateData = onlyDate.split("-");   
   var onlyTime = date.substring(spaceIndex);   
   var timeData = onlyTime.split(":");    
   var day  = (dateData[0]);     
   var month  = (dateData[1]);    
   var year  = (dateData[2]);    
   var hour  = (timeData[0]);    
   var min  = (timeData[1]);    
   var sec  = (timeData[2]);      
   var regForDate = new RegExp("\\d{1,2}-\\d{1,2}-\\d{4}$");  
   var regForTime = new RegExp("\\d{1,2}:\\d{1,2}:\\d{1,2}$");  
   if(!regForDate.test(onlyDate)) valid =false;  
   else if(!regForTime.test(onlyTime)) valid =false;  
   else if((month < 1) || (month > 12)) valid = false;  
   else if((day < 1) || (day > 31)) valid = false;  
   else if(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && (day > 30)) valid = false;  
   else if((month == 2) && (((year % 400) == 0) || ((year % 4) == 0)) && ((year % 100) != 0) && (day > 29)) valid = false;  
   else if((month == 2) && ((year % 100) == 0) && (day > 29)) valid = false;  
   else if((hour < 0) || (hour > 24)) valid = false;  
   else if((min < 0) || (min > 59)) valid = false;  
   else if((sec < 0) || (sec > 59)) valid = false;       
  return valid;  
 }  

JAVA SCRIPT TO ALLOW ONE SPACE BETWEEN WORDS

 function removeExtraSpaces(){  
       var searchName = document.getElementById(“name”).value;  
       searchName = searchName.trim();  
       var words = searchName.split(” “);  
       var updatedName=”";  
       if(words.length>1){  
            for(var i=0; i                     if(words[i]!=”"){  
                                 updatedName += words[i]+” “;  
                      }  
            }  
            document.getElementById(“name”).value=updatedName;  
       }  
 }  

Java code to generate unique random key

 import java.util.Random;  
 public class RandomKeyGenerator {  
    public static String generateRandomKey() {   
 String allChars = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@$%^*()_”;   
     Random random = new Random();   
     int length = random.nextInt(5);   
     length+=7;  
     char[] chars = new char[length];   
     for (int i=0; i      chars[i] = allChars.charAt(random.nextInt(allChars.length()));   
      }   
     return new String(chars);   
   }   
 }  

9 March 2013

FAT DOG 64-bit Operating System.



Fatdog64 is a small yet versatile 64-bit multi-user Linux distribution. Originally created as a "fatter" (=more built-in applications) derivative of Puppy Linux, Fatdog has grown to become a completely separate, mature 64-bit distribution. Fatdog64 still embodies the Puppy Linux spirit, fast and efficient.
At around 200MB, Fatdog boots up to a complete desktop environment ready for use; most everyday application is already included.
  • Web browser (Seamonkey browser - which uses identical code base as Firefox)
  • Universal email client (Seamonkey Mail)
  • Versatile media player (VLC)
  • Bit torrent client (Transmission)
  • Word processing (Abiword)
  • Spreadsheet (Gnumeric)
  • PDF/PS/Djvu reader (Evince)
  • PDF annotation (Xournal)
  • Graphics editor (GIMP)
  • Scanning system (Xsane, Peasyscan)
  • Printing system (CUPS)
  • Video editor (avidemux)
  • Photo retouch (Fotoxx)
  • CD/DVD/Bluray burner (PBurn)
  • Remote connection clients (RDP, VNC, SSH)
  • File sharing servers (Samba, FTP, HTTP) 
  • Text editor - IDE (Geany)
  • HTML editor (Seamonkey Composer)
And many more included, with more in its package repositories.Fatdog is versatile: Use is at a Live CD (or Live USB), or install it. Installation requires *no* re-partitioning. Fatdog can store its settings in your existing partition: FAT, Ext2/3/4, NTFS partitions are supported, as well as CIFS shares and LVM and mdadm partitions; on your harddisk, USB flash drive, or DVD+RW. PXE-booting Fatdog is easy - only two files are required.
Fatdog ISO is a dual-isohybrid ISO:
  • burn it to CD/DVD to make a bootable CD, or
  • "dd" it to a USB flash drive to make a bootable flash drive
In either case, the resulting CD/DVD or USB flash drive will boot on standard systems, UEFI systems, and systems with Secure Boot enabled (Windows 8).Note: x86-64 CPU is required. Most Intel and AMD CPUs produced after 2008 supports 64-bit (including many Intel Atoms ).
Fatdog is created by kirk; and is currently maintained by kirk and james.


Site Link

Cyanogen Mod for Android phones

CyanogenMod is an aftermarket firmware for a number of cell phones based on the open-source Android operating system. It offers features not found in the official Android based firmwares of vendors of these cell phones.

Suppose your phone requirement does not met with the newer android os such as 4.0 or greater than this mod allows you to run the newer android os with the oldest minimal hardware requirements.

you must have to root your phone before installing this mod such as Open Recovery to install this cyanogen mod.

For mode details can be found on the website here.

14 December 2012

GTA SA PERSIDENT ESCORT MOD FOR CLEO3 CLEO4

GTA San Andreas Protection Mode 
FOR 
CLEO3 & CLEO 4

STEP 1: Before Using This MOD Please Install CLEO Library.
STEP 2: Download escort.cs File and ADD it to CLEO Folder Of your GTA San Andreas GAME.
STEP 3: Just Press 9 to start President convoy Protection Mod When you are in CAR/Bike.
STEP 4: After Completion of your work just again Press 9 and the Protection will be Turned off.

(FOR SECURITY PROTOCOL PRESIDENT(YOU) THE TRAFFIC WILL BE DISABLE TILL YOU ARE IN ESCORT VEHICLE PROTECTION. )

10 December 2012

GTU CORE JAVA file handling programs


Simple Program to print text to a file

 //print text to a file  
 import java.io.*;  
 import static java.lang.System.out;  
 class file1  
 {  
 public static void main(String args[])  
 {  
 FileOutputStream o;  
 PrintStream p;  
 try  
 {  
 o=new FileOutputStream("file1.txt");  
 p=new PrintStream(o);  
 p.println("hello world..!");  
 p.println("From Niraj Chauhan");  
 p.close();  
 }  
 catch(Exception e)  
 {  
 out.print("error Writing a file to Hdisk");  
 }  
 }  
 }  
Print Data variables to a file
 //print data to a file  
 import java.io.*;  
 import static java.lang.System.out;  
 class file2  
 {  
 public static void main(String args[])  
 {  
 FileOutputStream o;  
 PrintStream p;  
 try  
 {  
 o=new FileOutputStream("file2.txt");  
 p=new PrintStream(o);  
 int a=10;  
 float b=123.23F;  
 p.println("a="+a+"\nb="+b);  
 p.close();  
 }  
 catch(Exception e)  
 {  
 out.print("error Writing a file to Hdisk");  
 }  
 }  
 }  
/copy one file to another file ( PLEASE PASS FILE NAME AS ARGUMENTS)
 //copy one file to another file  
 import java.io.*;  
 class file4  
 {  
 public static void main(String args[])throws Exception  
 {  
 int n=args.length;  
 if(n==0)  
 System.out.print("PLEASE ADD CMD LINE ARGUMENT AS FILE NAME");  
 else  
 {  
 FileOutputStream out=new FileOutputStream("filecopy.txt");  
 for(int i=0;i<n;i++)  
 {  
 try  
 {  
 InputStream in = new FileInputStream(args[i]);  
 byte buf[]=new byte[1024];  
 int len;  
 while ((len = in.read(buf)) > 0)  
 {  
  out.write(buf, 0, len);  
 }  
 in.close();  
 }  
 catch(Exception e)  
 {  
 }  
 }  
 }  
 }  
 }  
Create a Directory from core java program
 //create a directory  
 import java.io.*;  
 class file6  
 {  
 public static void main(String args[])throws Exception  
 {  
 int n=args.length;  
 if(n==0)  
 System.out.print("PLEASE ADD CMD LINE ARGUMENT AS DIR NAME");  
 else  
 {  
 for(int i=0;i<n;i++)  
 {  
 try  
 {  
 boolean success = (new File(args[i])).mkdir();  
 if(success)  
 System.out.println("Dir "+args[i]+" Successfully Created..!");  
 else  
 System.out.println("Dir "+args[i]+" NOT Successfully Created..!");  
 }  
 catch(Exception e)  
 {  
 }  
 }  
 }  
 }  
 }  
Make a file name data.txt and save following data
0001Niraj Chauhan 010020030
0002Pratik G patel 010020030
0003Ankur Shah 010020030
0004Amit Parekh 010020030
0005Chetan Chawda 010020030

 //Read file & print after Calculations  
 import java.io.*;  
 import static java.lang.System.out;  
 class student  
 {  
 int rollno,sub1,sub2,sub3,total;  
 String name;  
 float per;  
 student()  
 {  
 System.out.print("ih");  
 }  
 student(int rollno,String name,int sub1,int sub2,int sub3)  
 {  
 this.rollno=rollno;  
 this.sub1=sub1;  
 this.name=name;  
 this.sub2=sub2;  
 this.sub3=sub3;  
 }  
 public void showdata()  
 {  
 out.println("\n\n==================================");  
 System.out.println("No:"+rollno+"\tname:"+name);  
 out.println("==================================");  
 System.out.println("Sub1:"+sub1);  
 System.out.println("Sub1:"+sub2);  
 System.out.println("Sub1:"+sub3);  
 out.println("==================================");  
 out.println("Total:"+(sub1+sub2+sub3));  
 out.println("per:"+((sub1+sub2+sub3)/3)+"%");  
 }  
 }  
 class file8  
 {  
 public static void main(String args[])throws Exception  
 {  
 int count=0;  
 try  
 {  
 FileReader fr=new FileReader("data.txt");  
 BufferedReader br=new BufferedReader(fr);  
 String n1;  
 count=0;int i=0;  
 count=line("data.txt");  
 student s[]=new student[count];  
 while((n1=br.readLine())!=null)  
 {  
 int no=Integer.parseInt(n1.substring(0,4));  
 String name=n1.substring(4,26);  
 int no1=Integer.parseInt(n1.substring(26,29));  
 int no2=Integer.parseInt(n1.substring(29,32));  
 int no3=Integer.parseInt(n1.substring(32,35));       
 s[i]=new student(no,name,no1,no2,no3);  
 s[i].showdata();  
 i++;  
 }  
 System.out.println("\nTotal No Of Records Inserted:"+count);  
 }  
 catch(Exception e)  
 {  
 out.println("\nInput File Damaged..of total line "+count);  
 }  
 }  
 static int line(String fn)throws Exception  
 {  
 FileReader fr=new FileReader("data.txt");  
 BufferedReader br=new BufferedReader(fr);  
 String n1;int x=0;  
 while((n1=br.readLine())!=null)  
 {  
 x++;  
 }  
 return x;  
 }  
 }  
Read a file Line By line
 //Read file line by line  
 import java.io.*;  
 class file5  
 {  
 public static void main(String args[])throws Exception  
 {  
 int n=args.length;  
 if(n==0)  
 System.out.print("PLEASE ADD CMD LINE ARGUMENT AS FILE NAME");  
 else  
 {  
 for(int i=0;i<n;i++)  
 {  
 try  
 {  
 boolean success = (new File(args[i])).mkdir();  
 FileReader fr=new FileReader(args[i]);  
 BufferedReader br=new BufferedReader(fr);  
 String n1;  
 while((n1=br.readLine())!=null)  
 {  
 System.out.println(n1);  
 }  
 }  
 catch(Exception e)  
 {  
 }  
 }  
 }  
 }  
 }  


print content of a file by passing file name arguments
 //print content of a file by passing file name arguments  
 import java.io.*;  
 import static java.lang.System.out;  
 class file3  
 {  
 public static void main(String args[])throws Exception  
 {  
 int n=args.length;  
 if(n==0)  
 out.print("PLEASE ADD CMD LINE ARGUMENT AS FILE NAME");  
 else  
 {  
 for(int i=0;i<n;i++)  
 {  
 try  
 {  
 out.println("\n\nthe contents of "+args[i]+" is :\n\n");  
 InputStream in = new FileInputStream(args[i]);  
 byte buf[]=new byte[1024];  
 int len;  
 while ((len = in.read(buf)) > 0)  
 {  
  out.write(buf, 0, len);  
 }  
 in.close();  
 }  
 catch(Exception e)  
 {  
 }  
 }  
 }  
 }  
 }  

29 August 2012

Data Structure Programs

0) Program of singly linked list
1) Program on Linked list, New node insert at begining position.
2)Program on Linked list, New node insert at begining position.
3)Program on Linked list, New node insert so that information field and store in ascending order.
4)Program: To delete a node whose value is given by x from singly Linked list.
 #include<iostream.h>  
 #include<conio.h>  
 #include<stdlib.h>  
 struct list  
 {  
 int info;  
 struct list *link;  
 }*node1,*temp,*first;  
 int ch,x;  
 void menu()  
 {  
 cout<<endl<<"singly linked list";  
 cout<<endl<<"=======================";  
 cout<<endl<<"1.insert a nod";  
 cout<<endl<<"2.display a nod";  
 cout<<endl<<"3.display in reverse";  
 cout<<endl<<"0.Exit";  
 cout<<endl<<"=======================";  
 cout<<endl<<"enter your choice:";  
 cin>>ch;  
 }  
 void insert()  
 {  
 cout<<"Enter x:";  
 cin>>x;  
 node1=(struct list *)malloc(10);  
 node1->info=x;  
 node1->link=NULL;  
 if(first==NULL)  
 first=node1;  
 else  
 {  
 node1->link=first;  
 first=node1;  
 }  
 }  
 void rev()  
 {  
 temp=first;  
 int i=0;  
 while(temp!=NULL)  
 {  
 i++;  
 temp=temp->link;  
 }  
      for(;i>0;i--)  
      {  
           temp=first;  
           for(int j=1;j<i;j++)  
           temp=temp->link;  
           cout<<temp->info<<" ";  
      }  
 }  
 void display()  
 {  
 temp=first;  
 while(temp!=NULL)  
 {  
 cout<<temp->info<<" ";  
 temp=temp->link;  
 }  
 }  
 void del()  
  {  
   int x;  
     if (first==NULL)  
       cout<<endl<<"Underflow...";  
     else  
     {  
        cout<<"Enter value of x :";  
        cin>>x;  
        temp=first;  
        while(temp->link!=NULL && temp->info!=x)  
        {  
           pred=temp;  
           temp=temp->link;  
        }  
        if(temp->info != x)  
           cout<<"Node not found.";  
        else  
           if( first->info==x)  
            first=first->link;  
           else  
            pred->link=temp->link;  
     }  
  }  
 void main()  
 {  
 first=(struct list *)malloc(10);  
 first=NULL;  
 clrscr();  
 do  
 {  
 clrscr();  
 menu();  
 if(ch==1) insert();  
 if(ch==2) display();  
 if(ch==3) rev();  
 if(ch==4) del();  
  getch();  
 }  
 while(ch!=0);  
 }  
  //Program on Linked list, New node insert at begining position.  
  #include<iostream.h>  
  #include<conio.h>  
  #include<stdlib.h>  
  struct list  
  {  
    int  info;  
    struct list *link;  
  };  
 struct list *node1,*first,*temp;  
 int ch,x;  
  void menu()  
  {  
      cout<<endl<<"Linked List ";  
      cout<<endl<<"=========";  
      cout<<endl<<"1. Insert ";  
      cout<<endl<<"2. Display ";  
      cout<<endl<<"3. Exit ";  
      cout<<endl<<"Enter your choice...";  
      cin>>ch;  
  }  
  void insert()  
  {  
      cout<<"Enter element...";  
      cin>>x;  
      node1 = (struct list *)malloc(10);  
      node1->info = x;  
      node1->link = NULL;  
      if ( first == NULL )  
      {  
         first = node1;  
      }  
      else  
      {  
           node1->link = first;  
           first = node1;  
      }  
  }  
  void display()  
  {  
      cout<<endl<<"Linked List Elements are...";  
      temp = first;  
      while (temp != NULL)  
      {  
           cout<<temp->info<<",";  
           temp = temp->link;  
      }  
  }  
  void main()  
  {  
    first = ( struct list *)malloc(10);  
    first = NULL ;  
    do  
    {  
      clrscr();  
      menu();  
      if (ch==1) insert();  
      if (ch==2) display();  
      getch();  
    }  
    while ( ch != 3 );  
  }  
  //Program on Linked list, New node insert at end.  
  #include<iostream.h>  
  #include<conio.h>  
  #include<stdlib.h>  
  struct list  
  {  
    int  info;  
    struct list *link;  
  };  
 struct list *node1,*first,*temp;  
 int ch,x;  
  void menu()  
  {  
      cout<<endl<<"Linked List ";  
      cout<<endl<<"=========";  
      cout<<endl<<"1. Insert ";  
      cout<<endl<<"2. Display ";  
      cout<<endl<<"3. Exit ";  
      cout<<endl<<"Enter your choice...";  
      cin>>ch;  
  }  
  void insert()  
  {  
      cout<<"Enter element...";  
      cin>>x;  
      node1 = (struct list *)malloc(10);  
      node1->info = x;  
      node1->link = NULL;  
      if ( first == NULL )  
      {  
         first = node1;  
      }  
      else  
      {  
           temp = first;  
           while ( temp->link != NULL )  
                temp = temp->link;  
           temp->link = node1;  
      }  
  }  
  void display()  
  {  
      cout<<endl<<"Linked List Elements are...";  
      temp = first;  
      while (temp != NULL)  
      {  
           cout<<temp->info<<",";  
           temp = temp->link;  
      }  
  }  
  void main()  
  {  
    first = ( struct list *)malloc(10);  
    first = NULL ;  
    do  
    {  
      clrscr();  
      menu();  
      if (ch==1) insert();  
      if (ch==2) display();  
      getch();  
    }  
    while ( ch != 3 );  
  }  
  //Program on Linked list, New node insert so that information field  
  //store in ascending order.  
  #include<iostream.h>  
  #include<conio.h>  
  #include<stdlib.h>  
  struct list  
  {  
    int  info;  
    struct list *link;  
  };  
 struct list *node1,*first,*temp,*succ;  
 int ch,x;  
  void menu()  
  {  
      cout<<endl<<"Linked List ";  
      cout<<endl<<"=========";  
      cout<<endl<<"1. Insert ";  
      cout<<endl<<"2. Display ";  
      cout<<endl<<"3. Exit ";  
      cout<<endl<<"Enter your choice...";  
      cin>>ch;  
  }  
  void insert()  
  {  
      cout<<"Enter element...";  
      cin>>x;  
      node1 = (struct list *)malloc(10);  
      node1->info = x;  
      node1->link = NULL;  
      if ( first == NULL )  
      {  
         first = node1;  
      }  
      else  
        if(node1->info<=first->info)  
        {  
           node1->link = first;  
           first = node1;  
        }  
        else  
        {  
           temp = first;  
           succ =temp->link;  
           while ( temp->link != NULL && succ->info <= node1->info )  
           {  
                temp=temp->link;  
                succ=temp->link;  
           }  
           node1->link=temp->link;  
           temp->link=node1;  
        }  
  }  
  void display()  
  {  
      cout<<endl<<"Linked List Elements are...";  
      temp = first;  
      while (temp != NULL)  
      {  
           cout<<temp->info<<",";  
           temp = temp->link;  
      }  
  }  
  void main()  
  {  
    first = ( struct list *)malloc(10);  
    first = NULL ;  
    do  
    {  
      clrscr();  
      menu();  
      if (ch==1) insert();  
      if (ch==2) display();  
      getch();  
    }  
    while ( ch != 3 );  
  }  
 //Program: To delete a node whose value is given by x from singly Linked list.  
  #include<iostream.h>  
  #include<conio.h>  
  #include<stdlib.h>  
  struct list  
  {  
    int  info;  
    struct list *link;  
  };  
 struct list *node1,*first,*temp,*pred;  
 int ch,x;  
  void menu()  
  {  
      cout<<endl<<"Linked List ";  
      cout<<endl<<"=========";  
      cout<<endl<<"1. Insert ";  
      cout<<endl<<"2. Delete ";  
      cout<<endl<<"3. Display";  
      cout<<endl<<"0. Exit ";  
      cout<<endl<<"Enter your choice...";  
      cin>>ch;  
  }  
  void insert()  
  {  
      cout<<"Enter element...";  
      cin>>x;  
      node1 = (struct list *)malloc(10);  
      node1->info = x;  
      node1->link = NULL;  
      if ( first == NULL )  
      {  
         first = node1;  
      }  
      else  
      {  //New node insert at end of a list.  
           temp=first;  
           while(temp->link!=NULL)  
                temp=temp->link;  
           temp->link = node1;  
      }  
  }  
  void del()  
  {  
   int x;  
     if (first==NULL)  
       cout<<endl<<"Underflow...";  
     else  
     {  
        cout<<"Enter value of x :";  
        cin>>x;  
        temp=first;  
        while(temp->link!=NULL && temp->info!=x)  
        {  
           pred=temp;  
           temp=temp->link;  
        }  
        if(temp->info != x)  
           cout<<"Node not found.";  
        else  
           if( first->info==x)  
            first=first->link;  
           else  
            pred->link=temp->link;  
     }  
  }  
  void display()  
  {  
    if(first==NULL)  
      cout<<endl<<"Linked list empty...";  
    else  
    {  
      cout<<endl<<"Linked List Elements are...";  
      temp = first;  
      while (temp != NULL)  
      {  
           cout<<temp->info<<",";  
           temp = temp->link;  
      }  
    }  
  }  
  void main()  
  {  
    first = ( struct list *)malloc(10);  
    first = NULL ;  
    do  
    {  
      clrscr();  
      menu();  
      if (ch==1) insert();  
      if(ch==2) del();  
      if (ch==3) display();  
      getch();  
    }  
    while ( ch != 0 );  
  }  

18 September 2010

Os Interview Questions

  1. What are the basic functions of an operating system? :- Operating system controls and coordinates the use of the hardware among the various applications programs for various uses. Operating system acts as resource allocator and manager. Since there are many possibly conflicting requests for resources the operating system must decide which requests are allocated resources to operating the computer system efficiently and fairly. Also operating system is control program which controls the user programs to prevent errors and improper use of the computer. It is especially concerned with the operation and control of I/O devices.
  2. Why paging is used? - Paging is solution to external fragmentation problem which is to permit the logical address space of a process to be noncontiguous, thus allowing a process to be allocating physical memory wherever the latter is available.
  3. While running DOS on a PC, which command would be used to duplicate the entire diskette? diskcopy
  4. What resources are used when a thread created? How do they differ from those when a process is created? - When a thread is created the threads does not require any new resources to execute the thread shares the resources like memory of the process to which they belong to. The benefit of code sharing is that it allows an application to have several different threads of activity all within the same address space. Whereas if a new process creation is very heavyweight because it always requires new address space to be created and even if they share the memory then the inter process communication is expensive when compared to the communication between the threads.
  5. What is virtual memory? - Virtual memory is hardware technique where the system appears to have more memory that it actually does. This is done by time-sharing, the physical memory and storage parts of the memory one disk when they are not actively being used.
  6. What is Throughput, Turnaround time, waiting time and Response time? - Throughput âۉ€Å“ number of processes that complete their execution per time unit. Turnaround time âۉ€Å“ amount of time to execute a particular process. Waiting time âۉ€Å“ amount of time a process has been waiting in the ready queue. Response time âۉ€Å“ amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment).
  7. What is the state of the processor, when a process is waiting for some event to occur? - Waiting state
  8. What is the important aspect of a real-time system or Mission Critical Systems? - A real time operating system has well defined fixed time constraints. Process must be done within the defined constraints or the system will fail. An example is the operating system for a flight control computer or an advanced jet airplane. Often used as a control device in a dedicated application such as controlling scientific experiments, medical imaging systems, industrial control systems, and some display systems. Real-Time systems may be either hard or soft real-time. Hard real-time: Secondary storage limited or absent, data stored in short term memory, or read-only memory (ROM), Conflicts with time-sharing systems, not supported by general-purpose operating systems. Soft real-time: Limited utility in industrial control of robotics, Useful in applications (multimedia, virtual reality) requiring advanced operating-system features.
  9. What is the difference between Hard and Soft real-time systems? - A hard real-time system guarantees that critical tasks complete on time. This goal requires that all delays in the system be bounded from the retrieval of the stored data to the time that it takes the operating system to finish any request made of it. A soft real time system where a critical real-time task gets priority over other tasks and retains that priority until it completes. As in hard real time systems kernel delays need to be bounded
  10. What is the cause of thrashing? How does the system detect thrashing? Once it detects thrashing, what can the system do to eliminate this problem? - Thrashing is caused by under allocation of the minimum number of pages required by a process, forcing it to continuously page fault. The system can detect thrashing by evaluating the level of CPU utilization as compared to the level of multiprogramming. It can be eliminated by reducing the level of multiprogramming.
  11. What is multi tasking, multi programming, multi threading? - Multi programming: Multiprogramming is the technique of running several programs at a time using timesharing. It allows a computer to do several things at the same time. Multiprogramming creates logical parallelism. The concept of multiprogramming is that the operating system keeps several jobs in memory simultaneously. The operating system selects a job from the job pool and starts executing a job, when that job needs to wait for any i/o operations the CPU is switched to another job. So the main idea here is that the CPU is never idle. Multi tasking: Multitasking is the logical extension of multiprogramming .The concept of multitasking is quite similar to multiprogramming but difference is that the switching between jobs occurs so frequently that the users can interact with each program while it is running. This concept is also known as time-sharing systems. A time-shared operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of time-shared system. Multi threading: An application typically is implemented as a separate process with several threads of control. In some situations a single application may be required to perform several similar tasks for example a web server accepts client requests for web pages, images, sound, and so forth. A busy web server may have several of clients concurrently accessing it. If the web server ran as a traditional single-threaded process, it would be able to service only one client at a time. The amount of time that a client might have to wait for its request to be serviced could be enormous. So it is efficient to have one process that contains multiple threads to serve the same purpose. This approach would multithread the web-server process, the server would create a separate thread that would listen for client requests when a request was made rather than creating another process it would create another thread to service the request. To get the advantages like responsiveness, Resource sharing economy and utilization of multiprocessor architectures multithreading concept can be used.
  12. What is hard disk and what is its purpose? - Hard disk is the secondary storage device, which holds the data in bulk, and it holds the data on the magnetic medium of the disk.Hard disks have a hard platter that holds the magnetic medium, the magnetic medium can be easily erased and rewritten, and a typical desktop machine will have a hard disk with a capacity of between 10 and 40 gigabytes. Data is stored onto the disk in the form of files.
  13. What is fragmentation? Different types of fragmentation? - Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too small to satisfy any request. External Fragmentation: External Fragmentation happens when a dynamic memory allocation algorithm allocates some memory and a small piece is left over that cannot be effectively used. If too much external fragmentation occurs, the amount of usable memory is drastically reduced. Total memory space exists to satisfy a request, but it is not contiguous. Internal Fragmentation: Internal fragmentation is the space wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated blocks. Allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used
  14. What is DRAM? In which form does it store data? - DRAM is not the best, but it’s cheap, does the job, and is available almost everywhere you look. DRAM data resides in a cell made of a capacitor and a transistor. The capacitor tends to lose data unless it’s recharged every couple of milliseconds, and this recharging tends to slow down the performance of DRAM compared to speedier RAM types.
  15. What is Dispatcher? - Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: Switching context, Switching to user mode, Jumping to the proper location in the user program to restart that program, dispatch latency âۉ€Å“ time it takes for the dispatcher to stop one process and start another running.
  16. What is CPU Scheduler? - Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. CPU scheduling decisions may take place when a process: 1.Switches from running to waiting state. 2.Switches from running to ready state. 3.Switches from waiting to ready. 4.Terminates. Scheduling under 1 and 4 is non-preemptive. All other scheduling is preemptive.
  17. What is Context Switch? - Switching the CPU to another process requires saving the state of the old process and loading the saved state for the new process. This task is known as a context switch. Context-switch time is pure overhead, because the system does no useful work while switching. Its speed varies from machine to machine, depending on the memory speed, the number of registers which must be copied, the existed of special instructions(such as a single instruction to load or store all registers).
  18. What is cache memory? - Cache memory is random access memory (RAM) that a computer microprocessor can access more quickly than it can access regular RAM. As the microprocessor processes data, it looks first in the cache memory and if it finds the data there (from a previous reading of data), it does not have to do the more time-consuming reading of data from larger memory.
  19. What is a Safe State and what is its use in deadlock avoidance? - When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in safe state if there exists a safe sequence of all processes. Deadlock Avoidance: ensure that a system will never enter an unsafe state.
  20. What is a Real-Time System? - A real time process is a process that must respond to the events within a certain time period. A real time operating system is an operating system that can run real time processes successfully

1 September 2010

Advantages and Dis-advantages of Demand paging in operating system

Advantage:

Demand paging, as opposed to loading all pages immediately:

    * Only loads pages that are demanded by the executing process.
    * As there is more space in main memory, more processes can be loaded reducing context switching time which utilizes large amounts of resources.
    * Less loading latency occurs at program startup, as less information is accessed from secondary storage and less information is brought into main memory.
    * Does not need extra hardware support than what paging needs, since protection fault can be used to get page fault.

Disadvantage:

    * Individual programs face extra latency when they access a page for the first time. So demand paging may have lower performance than anticipatory paging algorithms such as prepaging.
    * Programs running on low-cost, low-power embedded systems may not have a memory management unit that supports page replacement.
    * Memory management with page replacement algorithms becomes slightly more complex.
    * Possible security risks, including vulnerability to timing attacks



what is demand paging in operating system?

Virtual memory can be implemented by a technique called demanding paging. It is a technique in which a Page is brought into memory when it is actually needed.
A typical life cycle of a process is as follows:

1. When a process is initiated, the operating system must at least load one page in real memory. It is the page containing the execution part of the process.
2. Execution of the process commences and proceeds through subsequent instructions beyond the starting point.

3. This execution continues as long as memory references generated by this page are also within same page. The virtual address created may reference a page that is not in real memory. This is called a page fault. It generates an interrupt that asks for the referenced page to be loaded. This is called demanding page.

4. The operating system will try to load the referenced page into a free real memory frame. When this is achieved the execution can continue.
5. Finally when the process terminates, the operating system releases all the pages belonging to the process. The pages become available to other processes.
In general, the operating system
accommodates the new page by removing a currently loaded page that is not in use. This is called page replacement. It is important to remove a page that will not be accessed in a short time. It will reduce the number of page faults in the system.



demand paging definition

 A kind of virtual memory where a page of memory will be paged in if an attempt is made to access it and it is not already present in main memory. This normally involves a memory management unit which looks up the virtual address in a page map to see if it is paged in. If it is not then the operating system will page it in, update the page map and restart the failed access. This implies that the processor must be able to recover from and restart a failed memory access or must be suspended while some other mechanism is used to perform the paging.
Paging in a page may first require some other page to be moved from main memory to disk ("paged out") to make room. If this page has not been modified since it was paged in, it can simply be reused without writing it back to disk. This is determined from the "modified" or "dirty" flag bit in the page map. A replacement algorithm or policy is used to select the page to be paged out, often this is the least recently used (LRU) algorithm. Prepaging is generally more efficient than demand paging
-source(Dictionary)

19 January 2010

All things you Want to Know about SQL & Oracle

  • What is SQL?
    • SQL stands for structured query language and it is the standard language for dealing withRelational databases. SQL was originally developed at IBM in early 1970s or a prototype called system R.It was initially spelt and pronounced as ‘SEQUEL’ but now is popularly called SQL only. It has an ANSI as well as ISO standard.
  •  Which is the different version of SQL?
    • Sql got its first ANSI standard in 1986. After the next standardization was in 1989 and the one in 1992 became very popular. It was also called SQL2. The latest version is SQL3. Which is being implemented by oracle 8 onwards? It supports some object-oriented features.
  • Which is the different version of Sql?
    • SQL can be broadly classified as-
      • Data definition language (DDL)
      • Data manipulation Language (DML)
      • Data control language (DCL)
      • Transaction control
      • Data retrieval (queries)
    • Sometimes the DCL commands are also considered to be part of DDL commands
  • What do you understand by DDL?
    • The DDL commands stands for Data definition Language and it related to the structured of an object.
    • E.g.: Create, Alter, drop, rename, truncate
  • What do you understand by DML?
    • The DML commands are those related to the content of the table. They deal with insertion, updating and deletion of rows in a table.
    • E.g. insert, update, delete
  • What do you understand by DCL?
    •  The DCL commands are required to give or take back access rights on object.
    • E.g. GRANT, REVOKE
  • What is transaction control?
    • These commands are used to handle the unit of work. A transaction executes either as a whole or none of its statements execute.
  • What is data retrieval?
    • The main purpose of data retrieval is to display data (raw, column) in the required format.It is mainly used for querying and reporting purpose.
  • What is the difference between char and varchar2?
    • The CHAR and VARCHAR2 both are used to store data.
    • The CHAR type is used to store fixed-length character data. The default and minimum size is 1 and the maximum size is 2000 characters.
    • The Char data types uses all the space assigned to it as per the size mentioned and hence has more storage efficiency because of which it processes data faster than VARCHAR2
  • .What is the concept of DUAL table?
    • DUAL is the work table of oracle, which has only one raw and column.
    • The column name is DUMMY with data type CHAR (1). 
    • When you want to perform some temporary calculation using only literals (no variables) then this table is of great use. The actual dummy column is irrelevant.
    • You can do all your temporary work on this table.
  • What is the difference between the Where clause and the HAVING clause?
    • The where clause is used to restrict rows. 
    • It checks for the condition for each and every row of the table. The having clause is used to restrict groups.
    • It is used immediately after GROUP BY clause and it checks for the conditions considering each group as a whole. 
    • In syntax as well as during execution the WHERE clause is always evaluated before the HAVING clause.

9 January 2010

Need & Advantages of Computer Network

-->
Need of computer network
·         Resource sharing
·         High reliability
·         Saving money
·         Scalability

Advantages of computer network
·         Access to remote information
·         Person-to-person communication
·         Interactive entertainment
·         Program and file sharing
·         Network and resource sharing
·         Database sharing
·         Economical expansion
·         Ability to use network software
·         Creation of workgroup
·         Centralized management
·         Security
·         Access to more than one operation system
·         Manufacturing