Sunday, December 26, 2010

Lap Around the Windows Azure Platform

Get Microsoft Silverlight

Cloud Computing – A Crash Course for Architects

Get Microsoft Silverlight

Friday, December 24, 2010

import java.util.*;

public class OddEvenThread{
 
 public static void main(String []str){
 
  long no; 
  System.out.println("Enter a no:");
  Scanner sc = new Scanner(System.in);
  no = sc.nextLong();
  OddEven oe = new OddEven(no);
 }
 
}

class OddEven implements Runnable{
 private Thread t=null;
 private long _no;
 
 long getNo(){
  return this._no;
 }
 
 OddEven(long no){
  t = new Thread(this);
  this._no=no;
  t.start();
 }
 
 public void run(){
  if(_no%2==0){
   System.out.println("No is Even");
  }
  else{
   System.out.println("No is Odd");
  }
 }
}

Thursday, December 16, 2010

Difference between Recursion and Iteration

1) Recursive function – is a function that is partially defined by itself whereas Iterative functions – are loop based imperative repetitions of a process

2)
Recursion Uses selection structure whereas Iteration uses repitation structure

3)
An infinite loop occurs with iteration if the loop-continuation test never becomes false whereas infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on the base case.

4)
Iteration terminates when the loop-continuation condition fails whereas recursion terminates when a base case is recognized

5)
When using recursion multiple activation records are created on stack for each call when in iteration everything is done in one activation record

6) Recursion is usually slower then iteration due to overhead of maintaining stack whereas iteration does not use stack so it's faster than recursion

7) Recursion uses more memory than iteration

8) Infinite recursion can crash the system whereas infinite looping uses cpu
cycles repeatedly

9) Recursion makes code smaller and iteration makes code longer

Wednesday, December 8, 2010

How to remove navbar from blog

Step1. Log in to Blogger

Step2. Click on Design

Step3. Go to Edit HTML tab

Step4. Under Edit HTML section find following section of code

-----------------------------------------------
Blogger Template Style
Name: Rounders
Designer: Elinor Finder
URL: www.malhar2010.blogspot.com
Date: 27 Feb 2010
Updated by: Blogger Team
----------------------------------------------- */

Step5. Paste the following snippet
#navbar-iframe {
display: none !important;
}

Monday, December 6, 2010

Creating executable jar file in 3 easy steps

Jar stands for Java archive. It's nothing but a compressed zip file which contains all files and folders related to your java program whether it is image, package, class file or anything else.It helps programmer pack file in one file and reduce the size of project.A jar file can be executable.

Jar file can be created using a utility comes with jsdk called jar. You can find it in <Your Java sdk path>\bin folder as jar.exe in Windows.

Here is simple steps to create a jar file of your java project.

Suppose i have a source file called P3.java.

Now follow steps given below :

Step 1. Compile your java source into .class file. My class file is P3.class

Step 2. Now create a file called prg.MF known as manifest file that contains following entries using notepad.
    Created-By: 1.2 (Sun Microsystems Inc.)
    Manifest-Version: 1.0
    Main-Class: P3


    In above entries first line tells the version and the vendor of Java implementation.
    Second line indicates that our manifest file conforms to the specification version 1.0
    Third line describes a name of class file in which main function resides.

Step3.  Now the third and final step. Go to command prompt and execute jar utility as described below.
    jar cvfm Prog.jar prg.MF *
   
    Here c,v,f,m are different options of jar utility.
    c - Creates a new file
    v - Generates verbose output to screen (You can omit this option)
    f - Specifies archive file name
    m - Includes information from our own manifest file

    Prog.jar is our archive file name.You can specify any name.
    prog.MF is a manifest file created by us.
    * indicates that all file should be included in archive.
   
Check folder for generated Prog.jar and execute it.
   

Friday, December 3, 2010

Program that will demonstrate the use of object serialization with different write methods

/* Program : 1
   Create an application that will demonstrate the use of object serialization with different write methods
   Developed by : Malhar Vora
   Developed on :6-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
********************************************************************************/
import java.io.*;

public class P1 
{
 
 public static void main(String []str)
 {
  
  ReadWriteData rwdata = new ReadWriteData();
  rwdata.writeData("test1.txt");
  rwdata.readData("test1.txt"); 
 
 
 }

}

class ReadWriteData
{
 public void writeData(String fname)
 {
  FileOutputStream fos = null;
  ObjectOutputStream oos = null;
  
  try{
  
    fos = new FileOutputStream(new File(fname));
    oos = new ObjectOutputStream(fos);
    
    oos.writeInt(10);
    oos.writeUTF("Hello World");
  
  
  }
  catch(Exception e)
  {
   
  }
  finally
  {
   try
   {
    oos.close();
    fos.close();
   }
   catch(Exception e)
   {
    ;
   }
  }
  
 }
 
 public void readData(String fname)
 {
  FileInputStream fis = null;
  ObjectInputStream ois = null;
  
  try{
  
    fis = new FileInputStream(new File(fname));
    ois = new ObjectInputStream(fis);
    
    System.out.println("Integer " + ois.readInt());
    System.out.println("String " + ois.readUTF());
  
  
  }
  catch(Exception e)
  {
   ;
  }
  finally
  {
   try
   {
    ois.close();
    fis.close();
   }
   catch(Exception e)
   {
    ;
   }
  }
  
 }
 
 

}

Saturday, November 27, 2010

Microsoft Generation 4 Data Centerseo

You need Microsoft Silverlight Plugin to watch this video.If you don't have plugin installed then click on video to download and install plugin.


Get Microsoft Silverlight

Microsoft's Data Center ITPAC

You need Microsoft Silverlight Plugin to watch this video.If you don't have plugin installed then click on video to download and install plugin.


Get Microsoft Silverlight

Wednesday, November 24, 2010

Program to demonstrate different types of borders to use on different components


/* Program : 4
   Program to demonstrate different types of borders to use on different components
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
 *********************************************************************************/
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;

public class P4 extends JFrame
{
 //LineBorder
 JPanel paneLine = null;
 JLabel lblLine = null;
 JTextField txtLine = null;
 JButton btnLine = null;
 
 //BevelBorder
 JPanel paneBevel = null;
 JLabel lblBevel = null;
 JTextField txtBevel = null;
 JButton btnBevel = null;
 
 //EtchedBorder
 JPanel paneEtched = null;
 JLabel lblEtched = null;
 JTextField txtEtched = null;
 JButton btnEtched = null;
 
 //MatteBorder
 JPanel paneMatte = null;
 JLabel lblMatte = null;
 JTextField txtMatte = null;
 JButton btnMatte = null;
 
 //SoftBevelBorder
 JPanel paneSoftBevel = null;
 JLabel lblSoftBevel = null;
 JTextField txtSoftBevel = null;
 JButton btnSoftBevel = null;
 
 //TitledBorder
 JPanel paneTitled = null;
 JLabel lblTitled = null;
 JTextField txtTitled = null;
 JButton btnTitled = null;
 
 
 
 JTabbedPane tabMain = null;
 
 P4()
 { 
  tabMain = new JTabbedPane();
  
  //LineBorder
  paneLine = new JPanel();
  lblLine = new JLabel("Line Border");
  txtLine = new JTextField("Line Border");
  btnLine = new JButton("Line Border");
  
  //BevelBorder
  paneBevel = new JPanel();
  lblBevel = new JLabel("Bevel Border");
  txtBevel = new JTextField("Bevel Border");
  btnBevel = new JButton("Bevel Border");
  
  //EtchedBorder
  paneEtched = new JPanel();
  lblEtched = new JLabel("Etched Border");
  txtEtched = new JTextField("Etched Border");
  btnEtched = new JButton("Etched Border");
  
  //MatteBorder
  paneMatte = new JPanel();
  lblMatte = new JLabel("Matte Border");
  txtMatte = new JTextField("Matte Border");
  btnMatte = new JButton("Matte Border");
  
  //SoftBevelBorder
  paneSoftBevel = new JPanel();
  lblSoftBevel = new JLabel("SoftBevel Border");
  txtSoftBevel = new JTextField("SoftBevel Border");
  btnSoftBevel = new JButton("SoftBevel Border");
  
  //TitledBorder
  paneTitled = new JPanel();
  lblTitled = new JLabel("Titled Border");
  txtTitled = new JTextField("Titled Border");
  btnTitled = new JButton("Titled Border");
  
  //===============================================================
  //LineBorder
  paneLine.setLayout(null);
  lblLine.setBorder(new LineBorder(Color.RED,3));
  txtLine.setBorder(new LineBorder(Color.RED,3));
  btnLine.setBorder(new LineBorder(Color.RED,3));
  lblLine.setBounds(10,10,100,30);
  txtLine.setBounds(10,50,100,30);
  btnLine.setBounds(10,90,100,30);
  paneLine.add(lblLine);  
  paneLine.add(txtLine);
  paneLine.add(btnLine);
  
  //BevelBorder
  paneBevel.setLayout(null);
  lblBevel.setBorder(new BevelBorder(BevelBorder.RAISED));
  txtBevel.setBorder(new BevelBorder(BevelBorder.RAISED));
  btnBevel.setBorder(new BevelBorder(BevelBorder.RAISED));
  lblBevel.setBounds(10,10,100,30);
  txtBevel.setBounds(10,50,100,30);
  btnBevel.setBounds(10,90,100,30);
  paneBevel.add(lblBevel);  
  paneBevel.add(txtBevel);
  paneBevel.add(btnBevel);
  
  //EtchedBorder
  paneEtched.setLayout(null);
  lblEtched.setBorder(new EtchedBorder(EtchedBorder.RAISED));
  txtEtched.setBorder(new EtchedBorder(EtchedBorder.RAISED));
  btnEtched.setBorder(new EtchedBorder(EtchedBorder.RAISED));
  lblEtched.setBounds(10,10,100,30);
  txtEtched.setBounds(10,50,100,30);
  btnEtched.setBounds(10,90,100,30);
  paneEtched.add(lblEtched);  
  paneEtched.add(txtEtched);
  paneEtched.add(btnEtched);
  
  //MatteBorder
  paneMatte.setLayout(null);
  lblMatte.setBorder(new MatteBorder(5, 10, 5, 10, Color.GREEN));
  txtMatte.setBorder(new MatteBorder(5, 10, 5, 10, Color.GREEN));
  btnMatte.setBorder(new MatteBorder(5, 10, 5, 10, Color.GREEN));
  lblMatte.setBounds(10,10,100,30);
  txtMatte.setBounds(10,50,100,30);
  btnMatte.setBounds(10,90,100,30);
  paneMatte.add(lblMatte);  
  paneMatte.add(txtMatte);
  paneMatte.add(btnMatte);
  
  //SoftBevelBorder
  paneSoftBevel.setLayout(null);
  lblSoftBevel.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
  txtSoftBevel.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
  btnSoftBevel.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
  lblSoftBevel.setBounds(10,10,100,30);
  txtSoftBevel.setBounds(10,50,100,30);
  btnSoftBevel.setBounds(10,90,100,30);
  paneSoftBevel.add(lblSoftBevel);  
  paneSoftBevel.add(txtSoftBevel);
  paneSoftBevel.add(btnSoftBevel);
  
  //TitledBorder
  paneTitled.setLayout(null);
  lblTitled.setBorder(new TitledBorder("Label with Titled Border"));
  txtTitled.setBorder(new TitledBorder("TextField with  Border"));
  btnTitled.setBorder(new TitledBorder("Button with Titled Border"));
  lblTitled.setBounds(10,10,150,60);
  txtTitled.setBounds(10,80,150,60);
  btnTitled.setBounds(10,160,150,60);
  paneTitled.add(lblTitled);  
  paneTitled.add(txtTitled);
  paneTitled.add(btnTitled);
  
  //===============================================================================
  
  tabMain.addTab("Line Border",paneLine);
  tabMain.addTab("Bevel Border",paneBevel);
  tabMain.addTab("Etched Border",paneEtched);
  tabMain.addTab("Matte Border",paneMatte);
  tabMain.addTab("SoftBevel Border",paneSoftBevel);
  tabMain.addTab("Titled Border",paneTitled);
  
  //===============================================================================
  getContentPane().add(tabMain); 
  setTitle("Program 4 - Developed by Malhar Vora");
  setSize(400,500);
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  
 } 
 
 public static void main(String []str)
 {
   P4 p = new P4();
 }

}


Tuesday, November 23, 2010

Program to perform numerical operations like calculator using Swing components

/* Program : 15
   Program to perform numerical operations like calculator using Swing components
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite  : www.malhar2010.blogspot.com
 *****************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class P15 extends JFrame implements ActionListener
{

 
 JLabel lblFirst = null;
 JLabel lblSecond = null;
 JLabel lblResult=null;
 JTextField txtFirst =null;
 JTextField txtSecond =null;
 JTextField txtResult=null;
 JButton btnAdd=null;
 JButton btnSub=null;
 JButton btnMul=null;
 JButton btnDiv=null; 
 
 
 P15()
 {
 
  lblFirst = new JLabel("First Value");
  lblSecond = new JLabel("Second Value");
  lblResult = new JLabel("Result");
  txtFirst = new JTextField();
  txtSecond = new JTextField();
  txtResult = new JTextField();
  btnAdd = new JButton("+");
  btnSub = new JButton("--");
  btnMul = new JButton("X");
  btnDiv = new JButton("/");
  
  
  setTitle("Program 15 - Developed by Malhar Vora");
  setSize(280,250);
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setLayout(null);
  
  lblFirst.setBounds(20,10,100,50);
  txtFirst.setBounds(110,20,100,30);
  lblSecond.setBounds(20,50,100,50);
  txtSecond.setBounds(110,60,100,30);
  lblResult.setBounds(20,90,100,50);
  txtResult.setBounds(110,100,100,30);
  btnAdd.setBounds(20,150,50,50);
  btnSub.setBounds(80,150,50,50);
  btnMul.setBounds(140,150,50,50);
  btnDiv.setBounds(200,150,50,50);
  txtResult.setEditable(false);
  
  
  
  getContentPane().add(lblFirst);
  getContentPane().add(txtFirst);
  getContentPane().add(lblSecond);
  getContentPane().add(txtSecond);
  getContentPane().add(lblResult);
  getContentPane().add(txtResult);
  getContentPane().add(btnAdd);
  getContentPane().add(btnSub);
  getContentPane().add(btnMul);
  getContentPane().add(btnDiv);
  
  
  btnAdd.addActionListener(this);
  btnSub.addActionListener(this);
  btnMul.addActionListener(this);
  btnDiv.addActionListener(this);
  
  
      
 }
 
 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  
  if(cmd.equals("+"))
  {
    int a,b,c;
    a = Integer.parseInt(txtFirst.getText());
    b = Integer.parseInt(txtSecond.getText());
    c = a+b;
    txtResult.setText("" + c);    
  }
  else if(cmd.equals("--"))
  {
    int a,b,c;
    a = Integer.parseInt(txtFirst.getText());
    b = Integer.parseInt(txtSecond.getText());
    c = a-b;
    txtResult.setText("" + c);  
  }
  else if(cmd.equals("X"))
  {
    int a,b,c;
    a = Integer.parseInt(txtFirst.getText());
    b = Integer.parseInt(txtSecond.getText());
    c = a*b;
    txtResult.setText("" + c);  
  }
  else if(cmd.equals("/"))
  {
    int a,b,c;
    try
    {
      a = Integer.parseInt(txtFirst.getText());
      b = Integer.parseInt(txtSecond.getText());
      c = a/b;
      txtResult.setText("" + c);  
    }
    catch(Exception e)
    {
      txtResult.setText("Error in division");
    }
  }
 }
 
 
 
 public static void main(String []str)
 {
  P15 p = new P15();
 }
}

Saturday, November 20, 2010

Program to implement the concept of creating Treeview



/* Program : 13
   Program to implement the concept of creating Treeview according to your marks of each subject of each semester under Gujarat Technological University,Ahmedabad
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite  : www.malhar2010.blogspot.com
 ***********************************************************************************************************************************************/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;

public class P13 extends JFrame 
{
 
 
 JTree mainTree = null;
 
 //GTU Node
 DefaultMutableTreeNode rootNode=null;
 
 //Semester Nodes
 DefaultMutableTreeNode nodeSem1=null;
 DefaultMutableTreeNode nodeSem2=null;
 DefaultMutableTreeNode nodeSem3=null;
 
 //First Sem Subjects
 DefaultMutableTreeNode nodePlSql=null;
 DefaultMutableTreeNode nodeAccount=null;
 DefaultMutableTreeNode nodeCPractical=null;
 DefaultMutableTreeNode nodeFop=null;
 DefaultMutableTreeNode nodeFco=null;
 DefaultMutableTreeNode nodeDm=null;
 DefaultMutableTreeNode nodeDbms=null;
 
 //Second Sem Subjects
 DefaultMutableTreeNode nodeToc=null;
 DefaultMutableTreeNode nodeConm=null;
 DefaultMutableTreeNode nodeCpp=null;
 DefaultMutableTreeNode nodeCppPractical=null;
 DefaultMutableTreeNode nodeDBMS2=null;
 DefaultMutableTreeNode nodeDs=null;
 DefaultMutableTreeNode nodeDsPractical=null;
 
 //Third Sem Subjects
 DefaultMutableTreeNode nodeJava=null;
 DefaultMutableTreeNode nodeJavaPractical=null;
 DefaultMutableTreeNode nodeConsm=null;
 DefaultMutableTreeNode nodeSs=null;
 DefaultMutableTreeNode nodeOs=null;
 DefaultMutableTreeNode nodeOsPractical=null;
 DefaultMutableTreeNode nodeSoodam=null;
 
 
 
 P13()
 {
 
  rootNode = new DefaultMutableTreeNode ("Gujarat Technological University");
  
  nodeSem1 = new DefaultMutableTreeNode ("Semester 1");
  nodeSem2 = new DefaultMutableTreeNode ("Semester 2");
  nodeSem3 = new DefaultMutableTreeNode ("Semester 3");
  
  //First Sem Nodes
  nodePlSql = new DefaultMutableTreeNode ("PLSQL");
  nodeAccount = new DefaultMutableTreeNode ("Account and ERP");
  nodeCPractical = new DefaultMutableTreeNode ("C Practical");
  nodeFop = new DefaultMutableTreeNode ("FOP");
  nodeFco = new DefaultMutableTreeNode ("FCO");
  nodeDm = new DefaultMutableTreeNode ("Discrete Mathematics");
  nodeDbms = new DefaultMutableTreeNode ("DBMS");
  
  
  //Second Sem Nodes
  nodeToc = new DefaultMutableTreeNode ("TOC");
  nodeConm = new DefaultMutableTreeNode ("CONM");
  nodeCpp= new DefaultMutableTreeNode ("C++");
  nodeCppPractical = new DefaultMutableTreeNode ("CPP Practical");
  nodeDBMS2 = new DefaultMutableTreeNode ("DBMS");
  nodeDs = new DefaultMutableTreeNode ("Data Structures");
  nodeDsPractical= new DefaultMutableTreeNode ("Data Structures Practical");
  
  //Third Sem Nodes
  nodeJava = new DefaultMutableTreeNode ("Java");
  nodeJavaPractical= new DefaultMutableTreeNode ("Java Practical");
  nodeConsm= new DefaultMutableTreeNode ("CONSM");
  nodeSs = new DefaultMutableTreeNode ("System Software");
  nodeOs = new DefaultMutableTreeNode ("Operating System");
  nodeOsPractical = new DefaultMutableTreeNode ("OS Practical");
  nodeSoodam = new DefaultMutableTreeNode ("SOODAM");
  
  
  //Adding first sem nodes to 1st sem main node
  nodePlSql.add(new DefaultMutableTreeNode("40"));
  nodeSem1.add(nodePlSql);
  
  nodeAccount.add(new DefaultMutableTreeNode("40"));
  nodeSem1.add(nodeAccount);
  
  nodeCPractical.add(new DefaultMutableTreeNode("70"));
  nodeSem1.add(nodeCPractical);
  
  nodeFop.add(new DefaultMutableTreeNode("45"));
  nodeSem1.add(nodeFop);
  
  nodeFco.add(new DefaultMutableTreeNode("50"));
  nodeSem1.add(nodeFco);
  
  nodeDm.add(new DefaultMutableTreeNode("30"));
  nodeSem1.add(nodeDm );
  
  nodeDbms.add(new DefaultMutableTreeNode("20"));
  nodeSem1.add(nodeDbms);
  
  
  
  //Adding second sem nodes to 2nd sem main node
  nodeToc.add(new DefaultMutableTreeNode("20"));
  nodeSem2.add(nodeToc);
  
  nodeConm.add(new DefaultMutableTreeNode("50"));
  nodeSem2.add(nodeConm );
  
  nodeCpp.add(new DefaultMutableTreeNode("57"));
  nodeSem2.add(nodeCpp);
  
  nodeCppPractical.add(new DefaultMutableTreeNode("37"));
  nodeSem2.add(nodeCppPractical);
  
  nodeDBMS2.add(new DefaultMutableTreeNode("35"));
  nodeSem2.add(nodeDBMS2);
  
  nodeDs.add(new DefaultMutableTreeNode("10"));
  nodeSem2.add(nodeDs);
  
  nodeDsPractical.add(new DefaultMutableTreeNode("20"));
  nodeSem2.add(nodeDsPractical);
  
  
  
  //Adding third sem nodes to 3rd sem main node
  nodeJava.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeJava);
  
  nodeJavaPractical.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeJavaPractical);
  
  nodeConsm.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeConsm);
  
  nodeSs.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeSs);
  
  nodeOs.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeOs);
  
  nodeOsPractical.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeOsPractical);
  
  nodeSoodam.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeSoodam);
  
  
  
  rootNode.add(nodeSem1);
  rootNode.add(nodeSem2);
  rootNode.add(nodeSem3);
  
  mainTree = new JTree(rootNode);
  
  setSize(400,500);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setTitle("Program 13 - Developed by Malhar Vora");
  setVisible(true);
  
  this.getContentPane().add(mainTree);
    
 }
 
 
 public static void main(String []str)
 {
  P13 p = new P13(); 
 }

 
}



Program to demonstrate the concept of ListBox and ComboBox

/* Program : 11
   Program to demonstrate the concept of ListBox and ComboBox
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite  : www.malhar2010.blogspot.com
 *****************************************************************/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class P11 extends JFrame implements ListSelectionListener
{
 
 JList lstCountry = null;
 JComboBox cboCity = null;
 JScrollPane listPane=null;
 String[] strCountry={ "India","USA","UK"};

 String[] strIndia={"Bombay","Ahmedabad"};
 String[] strUsa={"Chikago","Washington DC"};
 String[] strUk={"London","Manchester"};
    
 DefaultListModel model = null;
 DefaultComboBoxModel modelIndia = null;
 DefaultComboBoxModel modelUsa = null;
 DefaultComboBoxModel modelUk = null;
 
 P11()
 {
  
  
  lstCountry = new JList();
  cboCity  = new JComboBox();
  listPane = new JScrollPane(lstCountry);
  model = new DefaultListModel();
  
  modelIndia = new DefaultComboBoxModel(strIndia);
  modelUsa = new DefaultComboBoxModel(strUsa);
  modelUk = new DefaultComboBoxModel(strUk);
  
    
  setTitle("Program 11 - Developed by Malhar Vora");
  setSize(250,300);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);
  setLayout(null);
  
  listPane.setBounds(10,50,200,100);
  cboCity.setBounds(10,170,200,30);
    
  this.getContentPane().add(listPane);
  this.getContentPane().add(cboCity);
    
  model.addElement("India");
  model.addElement("USA");
  model.addElement("UK");
    
  lstCountry.setModel(model);
  lstCountry.setSelectionMode(0);
  lstCountry.addListSelectionListener(this);
  
     
 }
 
 public void valueChanged(ListSelectionEvent e)
 {
  String selectedCountry = (String)lstCountry.getSelectedValue();
  
  if(selectedCountry.equals("India"))
  {
   cboCity.setModel(modelIndia);
  }
  else if(selectedCountry.equals("USA"))
  {
   cboCity.setModel(modelUsa);
  }
  else if(selectedCountry.equals("UK"))
  {
   cboCity.setModel(modelUk);
  }
  else
  {
   cboCity.setModel(null);
  }
 }
 
 public static void main(String []str)
 {
  P11 p = new P11();    
 }


}



Thursday, November 18, 2010

Develop a Java application to demonstrate the use of adapter classes


/* Program : 22 
   Develop a Java application to demonstrate the use of adapter classes  
   Developed by : Malhar Vora
   Developed on : 11-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.event.*;

public class P22 extends JFrame
{
 
 JLabel lblMsg=null;
 P22()
 {
  setSize(400,300);
  setTitle("Prorgam 22 - Developed by Malhar Vora");
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);
  setLayout(null);
  
  lblMsg = new JLabel("Message will be displayed here");
  
  lblMsg.setBounds(10,10,300,100);
  
  this.getContentPane().add(lblMsg); 
  
  MouseHandler mHandle = new MouseHandler();
  addMouseListener(mHandle);
  
 }
 
 class MouseHandler extends MouseAdapter
 {
  public void mousePressed(MouseEvent me)
  {
   lblMsg.setText("Mouse Pressed");
  }
  
  public void mouseReleased(MouseEvent me)
  {
   lblMsg.setText("Mouse Released");
  }
 }
 
 public static void main(String []str)
 {
  P23 p = new P23();
 }

}


Wednesday, November 17, 2010

Develop a Java application to demonstrate the use WindowEvent class


/* Program : 21 
   Develop a Java application to demonstrate the use WindowEvent class  
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P21 extends JFrame implements WindowListener
{
 
  JLabel lblStatus=null;
 
  P21()
  {
   
   lblStatus = new JLabel("Message will be printed here");
   
   setSize(400,500);
   setVisible(true);
   setLayout(null);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   
   lblStatus.setBounds(50,50,200,50);
   this.getContentPane().add(lblStatus);
   
   addWindowListener(this);
  }
  
  public void windowActivated(WindowEvent we)
  {
   lblStatus.setText("Window Activated");
  }
  
  public void windowDeactivated(WindowEvent we)
  {
   lblStatus.setText("Window Deactivated");
  }
  
  public void windowOpened(WindowEvent we)
  {
   lblStatus.setText("Window Opened");
  }
  
  public void windowClosed(WindowEvent we)
  {
   lblStatus.setText("Window Closed");
  }
  
  public void windowIconified(WindowEvent we)
  {
   lblStatus.setText("Window Iconified");
  }
  
  public void windowDeiconified(WindowEvent we)
  {
   lblStatus.setText("Window Deiconified");
  }
  
  public void windowClosing(WindowEvent we)
  {
   lblStatus.setText("Window Closing");
  }
  public static void main(String []str)
  {
   P21 p = new P21();
  }
   
}

Monday, November 15, 2010

A Java application to display a moving banner "Wel-Come to SVICS"

/* Program : 14 
   Develop a Java application to display a moving banner "Wel-Come to SVICS"
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class P14 extends JFrame 
{
 
 JLabel lblMsg=null;
    
 P14()
 {
   lblMsg = new JLabel("Wel-Come to SVICS");
   setSize(1000,150);
   setVisible(true);
   setTitle("Program 14 - Developed by Malhar Vora");
   setResizable(false);
   setLayout(null);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   
   lblMsg.setBounds(5,10,400,100); 
   lblMsg.setFont(new Font("Arial",Font.BOLD,30));
   lblMsg.setForeground(Color.RED);
      
   this.getContentPane().add(lblMsg);
   blink();
   
 }
   
 void blink()
 {
   
   while(true)
   {
    if(lblMsg.getLocation().getX()==1000)
    {
     lblMsg.setLocation(-260,(int)lblMsg.getLocation().getY());
    }
    lblMsg.setLocation((int)lblMsg.getLocation().getX()+5,(int)lblMsg.getLocation().getY());
    try{
       Thread.currentThread().sleep(100);
    }
    catch(Exception e)
    {
     ;
    }
   }
  
 }
    
 
 public static void main(String []str)
 {
  P14 p = new P14();
  p.setTitle("Program 14 - Developed by Malhar Vora");
 }
}

Write a program to read an alphanumeric from user and check whether entered alphanumeric is (1) Capital Alphabet (2) Small Alphabet (3) Number

/* Write a program to read an alphanumeric from user and check whether entered alphanumeric is (1) Capital Alphabet (2) Small Alphabet (3) Number
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
**************************************************************************/
void main()
{

 char c;
 printf("Enter any alphanumeric character :");
 scanf("%c",&c);

 if(c>=48 && c<=57)
 {
        printf("Number");
        return;
 }
 else if(c>=65 && c<=91)
 {
        printf("Capital alphabet");
        return;
 }
 else if(c>=97 && c<=123)
 {
        printf("Small Alphabet");
        return;
 }
 else
 {
        printf("Unknown symbol");
        return;
 }

}

A program to read an integer no recursively until the user enters negative numbers

/* Write a program to read an integer no recursively until the user enters negative numbers
   and find the sum of nos entered by the user
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
********************************************************************************************/
int a=0,sum=0;

void main()
{
   printf("Enter no :");
   scanf("%d",&a);

   if(a<0)
   {
 printf("Sum is : %d",sum);
 return;
   }
   else
   {
 sum = sum + a;
   }
   main();

}

A program to accept nos from user till their sum exceeds 50


/* Write a program to accept nos from user till their sum exceeds 50
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
********************************************************************************************/

void main()
{

    int a=0,sum=0;

    test:
   if(sum>=50)
   {
  printf("Sum exceeds 50");
  return;
   }
   printf("Enter no:");
   scanf("%d",&a);

   sum=sum + a;
   goto test;

}

A program to get a no from user and find the sum of its odd digits

/* Write a program to get a no from user  and find the sum of its odd digits
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
**********************************************************************************/   
void main()
{

 int a=0,temp=0,sum=0;
 printf("Enter no :");
 scanf("%d",&a);
 if(a==0)
 {
     printf("No can't be 0");
     return;
 }

 //Label test
 test:
  if(a==0)
  {
       printf("Sum is :%d",sum);
       return;
  }

  temp=a%10;
  if(temp%2!=0)
  {
       sum=sum+temp;
  }
  a=a/10;
  goto test;

}

Sunday, November 14, 2010

Calling conventions demystified

Calling conventions is important concepts in computer languages. It defines a way in which parameters are transferred between one functions when one function calls another. There are the major types of parameter passing.

1) Call by Value:-
In this mechanism, a copy of each actual parameter is passed to a called function and stored into a corresponding formal parameter. So if a called function modifies the formal parameter, it does not affect the actual parameter or say the originally passed values. Here since the mechanism only copies data from the caller, the actual parameter can be any expression or variable.


void increment(int a)
{
      a++;
}

main()
{
 int p=10;
 increment (p);
 printf(“%d”,p);
}


In above C program value of variable p will remain 10 because when we call function increment(), copy of value of variable p will be copied to local variable a of function increment(). So value of p will not be affected. In Java it is default mechanism.

2) Call by reference:-
In this mechanism, a caller passes the reference of each actual parameter. So the caller function and called function both works on same copy of data. When a called function modifies the value of formal parameter, originally passed actual parameter is also affected because both working on same data. This mechanism performs better compared to Call by value .In C pointers can be used to use this mechanism. It can be used when large object has to be passed as function argument to save memory. When using this mechanism only variable can be passed and expression can’t be passed. In C++ a const keyword can be used to use this mechanism with constraint that value should not be modified.

void print(int const& x)
{
      x = 2; // This is not allowed.
      cout << x ;
}



Example C function

void increment(int *a)
{
     (*a)++;
}

main()
{
    int b=10;
    increment (&b);
    printf("%d",b);
}


In above program, a value of variable b will be 11 because we have passed reference of b and so in turn function increment() works on same copy.

3) Call by value-result:-
This mechanism can be said as a combination of both Call by value and Call by reference. In this mechanism same like Call by value copy of actual parameter is passed to a corresponding formal parameter. If called function modifies a formal parameter, actual parameter is not affected but when function returns, the value of formal parameter is copied back to actual parameter. Here also like Call by reference, the called function copies data to called function parameter, the passed value can only be variable and not any expression. This mechanism is available in Ada.



Other mechanisms like call by copy-restore, call by need , call by name are also available but they are not widely used.

A Program to enter a 4 digit integer from user and display it in characters without using loop and functions ( e.g 1654 = One Six Five Four )

/*Program to get 4 digit integer rom user and display each digit in character ( e.g 1545 should be displayed as One Five Four Five )
  Developed by : Malhar Vora
  Development Status : Completed and Tested
  Developed on : 14/11/2010
  Email : vbmade2000@gmail.com
  Web Site : www.malhar2010.blogspot.com
***********************************************************************************/  
void main()
{

 int a=0,temp=0,divisor=1000,temp1=0;

 printf("Enter no:");
 scanf("%d",&a);

 test:
  if(divisor==0)
  {
      return;
  }

  temp=a/divisor;
  divisor=divisor/10;
  temp1=temp%10;

  switch(temp1)
  {
   case 1:
    printf("One");
    break;
   case 2:
    printf("Two");
    break;
   case 3:
    printf("Three");
    break;
   case 4:
    printf("Four");
    break;
   case 5:
    printf("Five");
    break;
   case 6:
    printf("Six");
    break;
   case 7:
    printf("Seven");
    break;
   case 8:
    printf("Eight");
    break;
   case 9:
    printf("Nine");
   case 0:
    printf("Zero");
    break;
  }
  goto test;

}

Create an application which will implement the concept of JRadioButton to change the text into TextArea according to the selected Radio options.


/* Program : 10 
   Create an application which will implement the concept of JRadioButton to change the text into TextArea according to the selected Radio options.
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;

public class P10 extends JFrame implements ActionListener
{

 ButtonGroup rdoGroup=null;
 JRadioButton rdoSenCase=null;
 JRadioButton rdoLowerCase=null;
 JRadioButton rdoUpperCase=null;
 JRadioButton rdoTitleCase=null;
 JRadioButton rdoToggleCase=null;
 JTextField txtData=null;
 
    P10()
 {
   
   rdoSenCase = new JRadioButton("Sentence case");
   rdoLowerCase = new JRadioButton("lowercase");
   rdoUpperCase = new JRadioButton("UPPERCASE");
   rdoTitleCase = new JRadioButton("Title Case");
   rdoToggleCase = new JRadioButton("tOOGLE cASE");
   rdoGroup = new ButtonGroup();
   txtData = new JTextField("Enter your text here");
   
   rdoGroup.add(rdoSenCase);
   rdoGroup.add(rdoLowerCase );
   rdoGroup.add(rdoUpperCase);
   rdoGroup.add(rdoTitleCase);
   rdoGroup.add(rdoToggleCase);
   
   
   rdoSenCase.addActionListener(this); 
   rdoLowerCase.addActionListener(this);
   rdoUpperCase.addActionListener(this);
   rdoTitleCase .addActionListener(this);
   rdoToggleCase.addActionListener(this);
   
   setLayout(null);
   txtData.setBounds(50,50,300,30);
   rdoSenCase.setBounds(50,90,200,30);
   rdoLowerCase.setBounds(50,120,200,30);
   rdoUpperCase.setBounds(50,150,200,30);
   rdoTitleCase.setBounds(50,180,200,30);
   rdoToggleCase.setBounds(50,210,200,30);

   this.getContentPane().add(txtData); 
   this.getContentPane().add(rdoSenCase); 
   this.getContentPane().add(rdoLowerCase); 
   this.getContentPane().add(rdoUpperCase); 
   this.getContentPane().add(rdoTitleCase); 
   this.getContentPane().add(rdoToggleCase); 
      
   setTitle("Program 10 - Developed by Malhar Vora");
   setSize(380,300);
   setVisible(true);
   setDefaultCloseOperation(EXIT_ON_CLOSE);      
 }
  
  
 public void actionPerformed(ActionEvent ae)
 {
   String cmd=ae.getActionCommand();
   if(txtData.getText().equals(""))
   {
    JOptionPane.showMessageDialog(this,"Please enter some text","Error",JOptionPane.ERROR_MESSAGE);
    return;
   }
   
   if(cmd.equals("lowercase"))
   {
    txtData.setText(txtData.getText().toLowerCase());
   }
   else if(cmd.equals("UPPERCASE"))
   {
    txtData.setText(txtData.getText().toUpperCase());
   }
   else if(cmd.equals("Sentence case"))
   {
    String temp="";
    temp = temp + Character.toUpperCase(txtData.getText().charAt(0));
    
    for(int i=1;i<txtData.getText().length();i++)
    {
     temp = temp + Character.toLowerCase(txtData.getText().charAt(i));
    } 
    
    txtData.setText(temp);   
         
   }
   else if(cmd.equals("tOOGLE cASE"))
   {
    String temp="";
        
    for(int i=0;i<txtData.getText().length();i++)
    {
     if(Character.isUpperCase(txtData.getText().charAt(i)))
     {
      temp = temp + Character.toLowerCase(txtData.getText().charAt(i));
     }
     else
     {
      temp = temp + Character.toUpperCase(txtData.getText().charAt(i));
     }
    } 
    txtData.setText(temp); 
   }
   else if(cmd.equals("Title Case"))
   {
     
    StringTokenizer st = new StringTokenizer(txtData.getText()," ");
    String tempToken="";
    txtData.setText("");
    while(st.hasMoreTokens())
    {
      tempToken = st.nextToken(); 
      txtData.setText(txtData.getText() + titleCase(tempToken) + " ");             
    }
     
    
   }
   
   
   
 } 
 
 String titleCase(String str)
 {
    
    String temp="";
    temp = temp + Character.toUpperCase(str.charAt(0));
    
    for(int i=1;i<str.length();i++)
    {
     temp = temp + Character.toLowerCase(str.charAt(i));
    } 
    return temp;
    
 }
 public static void main(String []str)
 {
   P10 p = new P10();
 }  


}




  

Friday, November 12, 2010

Create an application that will demonstrate the concept of ProgressBar.

/* Program : 8
   Create an application that will demonstrate the concept of ProgressBar.
   Developed by : Malhar Vora
   Developed on : 9-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P8 extends JFrame implements ActionListener
{
 
 JProgressBar pBar=null;
 JButton btnStart=null;
 JButton btnStop=null;
 MakeProgress mp=null;
 
 boolean stop=false;
 
 P8()
 {
   //Setting properties of Frame
   setSize(400,200);
   setResizable(false);
   setTitle("Progressbar Demo");
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setVisible(true);
   this.getContentPane().setLayout(null);
   
   pBar = new JProgressBar(0,100);
   pBar.setBounds(10,10,360,40);
   pBar.setStringPainted(true);
   
   btnStart = new JButton("Start");
   btnStop = new JButton("Stop");
   
   btnStart.setBounds(10,80,100,50);
   btnStop.setBounds(120,80,100,50);
   
   this.getContentPane().add(pBar);
   this.getContentPane().add(btnStart);
   this.getContentPane().add(btnStop);
   
   btnStart.addActionListener(this);
   btnStop.addActionListener(this);
      
   //makeProgress();
   mp = new MakeProgress();
 }
 
 public void  actionPerformed(ActionEvent ae)
 {
   String cmd = ae.getActionCommand();
   if(cmd.equals("Start"))
   {
     stop=false; 
     
   }
   else if(cmd.equals("Stop"))
   {
     stop=true;           
   }
 }
  
 class MakeProgress extends Thread
 {
  
  
  MakeProgress()
  {
   start();
  }  
  public void run()
  {
   while(true)
   {
    if(stop==true)
    {
    
     try{
       wait();
     }
     catch(Exception e)
     {
       ;
     }
    }
    else
    {
     if(pBar.getValue()==100)
     {
      pBar.setValue(0);
     }
     pBar.setValue(pBar.getValue()+1);
     pBar.setString("" + pBar.getValue());
    
     try{
       sleep(2000);
     }
     catch(InterruptedException ie){
       ;
     } 
    }
   }
  
  }
 
 }
 
 public static void main(String []str)
 {
  P8 p = new P8();
 }
 

}


Thursday, November 11, 2010

Create an application that shows the usage of SliderBar to imlpement the RGBcolored label

/* Program : 7
   Create an application that shows the usage of SliderBar to imlpement the RGBcolored label
   Developed by : Malhar Vora
   Developed on : 9-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;

public class P7 extends JFrame implements ChangeListener
{

 JSlider sliderRed=null;
 JSlider sliderGreen=null;
 JSlider sliderBlue=null;
 JLabel lblRed=null;
 JLabel lblGreen=null;
 JLabel lblBlue=null;
 JLabel lblColor=null;
 Color colorFrame=null;
 
 P7()
 {
  
 
  sliderRed = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
  sliderGreen = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
  sliderBlue = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
  
  lblRed = new JLabel("Red");
  lblGreen = new JLabel("Green");
  lblBlue = new JLabel("Blue");
  lblColor = new JLabel("My color changes");
  
  //Setting properties of JFrame
  setTitle("Program 7 - Developed by Malhar Vora");
  setSize(400,500);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true); 
  setResizable(false);
  this.getContentPane().setLayout(new GridLayout(7,1));
  
  
  //Adding controls to JFrame
  this.getContentPane().add(lblColor);
  this.getContentPane().add(lblRed);
  this.getContentPane().add(sliderRed);
  this.getContentPane().add(lblGreen);
  this.getContentPane().add(sliderGreen);
  this.getContentPane().add(lblBlue);
  this.getContentPane().add(sliderBlue);
  
  
  //Setting properties of JSliders
  sliderRed.setMajorTickSpacing(25); //For sliderRed
  sliderRed.setPaintLabels(true);
  sliderRed.setPaintTicks(true);
  sliderRed.setPaintTrack(true);
  sliderGreen.setMajorTickSpacing(25);  //For sliderGreen
  sliderGreen.setPaintLabels(true);
  sliderGreen.setPaintTicks(true);
  sliderGreen.setPaintTrack(true);
  sliderBlue.setMajorTickSpacing(25);  //For sliderBlue
  sliderBlue.setPaintLabels(true);
  sliderBlue.setPaintTicks(true);
  sliderBlue.setPaintTrack(true);
  
  sliderRed.addChangeListener(this);
  sliderGreen.addChangeListener(this);
  sliderBlue.addChangeListener(this);
   
 }
 
 public void stateChanged(ChangeEvent ce)
 {
   colorFrame = new Color(sliderRed.getValue(),sliderGreen.getValue(),sliderBlue.getValue());   
   lblColor.setForeground(colorFrame); 
 }
 
 public static void main(String []str)
 {
  P7 p =new P7();
 }

}
 

Write an application which will create a popup menu with different menuitems and set the label according to menutem

/* Program : 6 
   Write an application which will create a popup menu with different menuitems and set the label according to menutem
   Developed by : Malhar Vora
   Developed on : 8-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P6 extends JFrame implements ActionListener
{


 JPopupMenu mnuContext = null;
 JMenuItem mnu1 = null;
 JMenuItem mnu2 = null;
 JMenuItem mnu3 = null;
 JMenuItem mnu4 = null;
 
 P6()
 {
  
  setTitle("Program 6 - Developed by Malhar Vora");
  setSize(400,300);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);
  
  mnu1 = new JMenuItem("Abc");
  mnu2 = new JMenuItem("bbc");
  mnu3 = new JMenuItem("pqr");
  mnu4 = new JMenuItem("xyz");
  
  mnuContext = new JPopupMenu();
  mnuContext.add(mnu1);
  mnuContext.add(mnu2);
  mnuContext.add(mnu3);
  mnuContext.add(mnu4);
  
  PopupListener pl = new PopupListener();
  addMouseListener(pl);
  
  mnu1.addActionListener(this);
  mnu2.addActionListener(this);
  mnu3.addActionListener(this);
  mnu4.addActionListener(this);
   
 }
 
 
 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  setTitle(cmd);
 }
 
 class PopupListener extends MouseAdapter
 {
  public void mousePressed(MouseEvent me)
  {
   if (me.isPopupTrigger())
   { 
    mnuContext.show(me.getComponent(), me.getX(), me.getY()); 
   } 
  }
 
  public void mouseReleased(MouseEvent me)
  {
   if (me.isPopupTrigger())
   { 
    mnuContext.show(me.getComponent(), me.getX(), me.getY()); 
   } 
  }
}
 
 public static void main(String []str)
 {
  P6 p = new P6();
 }

}




Tuesday, November 9, 2010

Write an application which will demonsrate the use of JTabbePane class to create a GUI with TabbedPanes.

/* Program : 5 
   Write an application which will demonsrate the use of JTabbePane class to create a GUI with TabbedPanes.
   Developed by : Malhar Vora
   Developed on : 8-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P5 extends JFrame
{
 
 JLabel lblPage1 = null;
 JLabel lblPage2 = null;
 JTabbedPane mainTab = null;
 JPanel page1 = null;
 JPanel page2 = null;
 
 
 P5()
 {
  
  setSize(400,500);
  setTitle("Program 4 - Developed by Malhar Vora");
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  
  lblPage1 = new JLabel("This is first Page - 1");
  lblPage2 = new JLabel("This is first Page - 2");
  page1 = new JPanel();
  page2 = new JPanel();
    
  page1.setLayout(new BorderLayout());  
  page2.setLayout(new BorderLayout());  
  
  page1.add(lblPage1);
  page2.add(lblPage2);
  
  mainTab = new JTabbedPane();
  
  mainTab.addTab("Page 1",page1);
  mainTab.addTab("Page 2",page2);
  
  this.getContentPane().add(mainTab);
   
  
 }
 
 
 public static void main(String []str)
 {
  P5 p = new P5();
 }

}
 

 
 

Sunday, November 7, 2010

Create a program that will write and read the same object from a file and display the content on the screen

/* Program : 2 
   Create a program that will write and read the same object from a file and display the content on the screen
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Student implements Serializable
{
 private int id;
 private String name;
 private String course;
  
 Student()
 {
   id=0;
   name="";
   course="";
 }
 
 Student(int sid,String sname,String scourse)
 {
   this.id=sid;
   this.name=sname;
   this.course=scourse;
 }
 
 int getId()
 {
   return this.id;
 }
 
 void setId(int sid)
 {
   this.id=sid;
 }
 
 String getName()
 {
   return this.name;
 }
 
 void setName(String sname)
 {
   this.name=sname;
 }
 
 String getCourse()
 {
   return this.course;
 }
 
 void setCourse(String scourse)
 {
   this.course=scourse;
 }
 
  
}


public class P2 extends JFrame implements ActionListener
{
 
 JLabel lblId=null;
 JLabel lblName=null;
 JLabel lblCourse=null;
 JTextField txtId=null;
 JTextField txtName=null;
 JTextField txtCourse=null;
 JButton btnSave=null;
 JButton btnClear=null;
 JButton btnLoad=null;
 
 
 P2()
 {
   
   lblId = new JLabel("Student ID");
   lblName = new JLabel("Student Name");
   lblCourse = new JLabel("Course");
   txtId = new JTextField(5);
   txtName = new JTextField(20);
   txtCourse = new JTextField(40);
   btnSave  = new JButton("Save");
   btnClear  = new JButton("Clear");
   btnLoad  = new JButton("Load");  
   
   
   
   setTitle("Program 2 - Developed by Malhar Vora");
   setSize(400,500);
   setVisible(true);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setLayout(null);
   
   
   lblId.setBounds(50,50,100,50);
   lblName.setBounds(50,90,100,50);
   lblCourse.setBounds(50,130,100,50);
   txtId.setBounds(150,60,60,30);
   txtName.setBounds(150,100,200,30);
   txtCourse.setBounds(150,140,100,30);
   btnSave.setBounds(50,200,80,30);  
   btnClear.setBounds(150,200,80,30);  
   btnLoad.setBounds(250,200,80,30);
   
   btnSave.setMnemonic(KeyEvent.VK_S);  
   btnClear.setMnemonic(KeyEvent.VK_C);  
   btnLoad.setMnemonic(KeyEvent.VK_L);  
   
   this.getContentPane().add(lblId);
   this.getContentPane().add(lblName);
   this.getContentPane().add(lblCourse);
   this.getContentPane().add(txtId);
   this.getContentPane().add(txtName);
   this.getContentPane().add(txtCourse);
   this.getContentPane().add(btnSave);
   this.getContentPane().add(btnClear);
   this.getContentPane().add(btnLoad);
   
   txtId.requestFocus();
   
   btnSave.addActionListener(this); 
   btnClear.addActionListener(this); 
   btnLoad.addActionListener(this); 
   
 }
 
 void saveStudent(Student s)
 {
   FileOutputStream fos=null;
   ObjectOutputStream oos=null;
   try{

     fos = new FileOutputStream("Student.dat");
     oos = new ObjectOutputStream(fos);
     oos.writeObject(s);     
     
   }
   catch(Exception e)
   {
    JOptionPane.showMessageDialog(this,"Error in writing data to file","Error",JOptionPane.ERROR_MESSAGE);
   }
   finally
   {
    try{
      oos.close();
      fos.close();
    }
    catch(Exception e)
    {
     ;
    }
   }
 
 }
 
 Student loadStudent()
 {
  FileInputStream fis=null;
  ObjectInputStream ois=null;
  Student s=null;
  
  try{
   
    fis = new FileInputStream("Student.dat");
    ois = new ObjectInputStream(fis);
    s=(Student)ois.readObject();    
  
  }
  catch(Exception e)
  {
    JOptionPane.showMessageDialog(this,"Error in reading data","Error",JOptionPane.ERROR_MESSAGE);
  }
  finally
  {
    try{
     ois.close();
     fis.close();
    }
    catch(Exception e)
    {
     ;
    }
  }
  return s;
 
 }
 
 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  Student s=null;
  
  if(cmd.equals("Save"))
  {
 
   s = new Student();
   s.setId(Integer.parseInt(txtId.getText()));
   s.setName(txtName.getText());
   s.setCourse(txtCourse.getText());
   
   saveStudent(s);
  }
  else if(cmd.equals("Clear"))
  {
   txtId.setText("");
   txtName.setText("");
   txtCourse.setText("");   
  }
  else if(cmd.equals("Load"))
  {
   s=null;
   s=loadStudent();
   txtId.setText("");
   txtName.setText("");
   txtCourse.setText(""); 
   if(s!=null)
   {
    txtId.setText("" + s.getId());   
    txtName.setText(s.getName());
    txtCourse.setText(s.getCourse());
   }
  }
 }
 
 public static void main(String []str)
 {
   P2 p = new P2();
 }

 

}
  
 

Friday, November 5, 2010

Create an application which demonstrates the use of JLabel, JButton and JTextField classes of the Swing to perform binary operation. Also implement the concepts of Icon,ToolTipText and shortCutKey within the same program.

/* Program : 3 
   Create an application which demonstrates the use of JLabel, JButton and JTextField classes of the Swing to perform binary operation. Also implement the concepts of Icon,ToolTipText and shortCutKey within the same program.
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


class P3 extends JFrame implements ActionListener
{ 


 JLabel lblval1 = null;
 JLabel lblval2 = null;
 JLabel lblresult = null;
 JTextField txtFirst =null;
 JTextField txtSecond = null;
 JTextField txtSum = null;
 JButton btnSum = null;
 Icon icn = null;
 
 
 P3()
 {
   lblval1 = new JLabel("First Value");
   lblval2 = new JLabel("Second Value");
   lblresult = new JLabel("Result");
   
   txtFirst = new JTextField(5);
   txtSecond = new JTextField(5);
   txtSum = new JTextField(5);
   
   icn = new ImageIcon("icon.png");
   btnSum = new JButton("Sum",icn);
   
   setLayout(null);
   setTitle("Program 3 - Developed by Malhar Vora");
   setVisible(true);
   setSize(400,250);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
 
  lblval1.setBounds(80,50,100,10);
  txtFirst.setBounds(160,40,100,30);
    
  lblval2.setBounds(60,90,100,10);
  txtSecond.setBounds(160,80,100,30);
    
  lblresult.setBounds(80,120,100,30);
  txtSum.setBounds(160,120,100,30);
  txtSum.setEditable(false);
    
  btnSum.setBounds(160,160,120,30); 
  btnSum.setToolTipText("Click to make summation");
  btnSum.setMnemonic(KeyEvent.VK_S);
  
   
   this.getContentPane().add(lblval1);
   this.getContentPane().add(lblval2);
   this.getContentPane().add(txtFirst);
   this.getContentPane().add(txtSecond);
   this.getContentPane().add(lblresult);
   this.getContentPane().add(txtSum);
   this.getContentPane().add(btnSum);   

  btnSum.addActionListener(this); 
  
  txtFirst.requestFocus();
  
 }

 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  
  if(cmd.equals("Sum"))
  {
   
   if(txtFirst.getText().equals(""))
   {
    JOptionPane.showMessageDialog(this,"Please enter first value","Error in summation",JOptionPane.ERROR_MESSAGE);
    txtFirst.requestFocus();
   }
   else if(txtSecond.getText().equals(""))
   {
    JOptionPane.showMessageDialog(this,"Please enter second value","Error in summation",JOptionPane.ERROR_MESSAGE);
    txtSecond.requestFocus();
   }
   else
   {
    try{
     int a,b,c;
     a = Integer.parseInt(txtFirst.getText());
     b = Integer.parseInt(txtSecond.getText());
     c = a+b;
     txtSum.setText("" + c);
    }
    catch(Exception e)
    {
     txtSum.setText("Error in summation");
    }
    
   }
  }
  
 }

 public static void main(String []str)
 {
  P3 p = new P3(); 
 }

}

Thursday, November 4, 2010

C++ Programming Tutorial - 29 - Array Ranges in Functions

C++ Programming Tutorial - 28 - Changing Array Values with Functions

C++ Programming Tutorial - 27 - Protecting Arrays with const

C++ Programming Tutorial - 26 - Populating an Array with Functions

C++ Programming Tutorial - 25 - Passing Arrays into Functions

C++ Programming Tutorial - 24 - Reading From a File

C++ Programming Tutorial - 21 - Switch Statement

C++ Programming Tutorial - 23 - Writing on Files

C++ Programming Tutorial - 22 - Structures

C++ Programming Tutorial - 20 - Logical OR Operator

C++ Programming Tutorial - 18 - The if else Statement

C++ Programming Tutorial - 19 - The if else if else Statement

C++ Programming Tutorial - 17 - The if Statement

C++ Programming Tutorial - 16 - Creating a Pointer

C++ Programming Tutorial - 15 - Address Operator

C++ Programming Tutorial - 14 - string Class

C++ Programming Tutorial - 13 - Store Text in an Array

C++ Programming Tutorial - 12 - char Array

C++ Programming Tutorial - 11 - More on Building Arrays

C++ Programming Tutorial - 10 - Introduction to Arrays

C++ Programming Tutorial - 9 - using namespace std; Trick

C++ Programming Tutorial - 8 - Dating Young Girls

C++ Programming Tutorial - 7 - Finally Creating Our Own Function!

C++ Programming Tutorial - 6 - Functions with Multiple or No Parameters

C++ Programming Tutorial - 5 - Fantastic Functions

C++ Programming Tutorial - 4 - Come Get Sum!

C++ Programming Tutorial - 3 - Introduction to Variables

C++ Programming Tutorial - 2 - Building and Running a Basic Program

C++ Programming Tutorial - 1 - Installing Dev C++

How to share an internet connection using CCProxy

CCProxy is software which can be used to share Internet connection on a network. It is very easy to use.

Steps for main system from which you want to share Internet connection

1) Download CCProxy sotfware from here

2) Create a simple workgroup network of systems.

3) Install CCProxy

4) Start your local area network connection

5) Start CCProxy from Start Menu->All Programs->CCProxy

6) Click on Start button from toolbar.


Steps for systems in which you want to use use shared Internet connection


1) Set proxy address in Internet Explorer

    -> Open Toosl menu

    -> Click on Internet Options

    -> Click on Connections tab

    -> Click on LAN Settings button located at botton

    -> Check use a proxy server for your LAN checkbox given under "Proxy Server" section

    -> Enter IP address of your main system in address box and port no in port box (Default port is 808)

    -> [ Optional ] Click on Advanced button and enter IP and corresponding port no in all boxes.


2) Set proxy address in Mozilla Firefox

    -> Open Toosl menu

    -> Click on Options

    -> Click on Advanced button in toolbar

    -> Click on Network tab

    -> Click on Settings button

    -> Click on Manual proxy configuration option button

    -> Enter IP address of your main system in HTTP proxy box and port no in port box (Default port is 808)

    -> [ Optional ] Check Use this proxy server for all protocols checkbox to apply same IP for all      protocols



You can also create users accounts to allow access only to registered users and monitor bandwidth usage.



             

             

Tuesday, November 2, 2010

Types of kernel

The kernel is a program that constitutes the central core of a operating system. It has complete control over everything that occurs in the system. 

The kernel is the first part of the operating system to load into memory during booting and it remains there for the entire duration of the computer session because its services are required continuously. Thus it is important for it to be as small as possible while still providing all the essential services needed by the other parts of the operating system and by the various application programs.

Because the service provided by kernel is critical in nature, the kernel is usually loaded into a protected area of memory so no other programs are able to interfere with kernel. 

The kernel provides basic services for all other parts of the operating system, typically including memory management, process management, file management and I/O (input/output) management.  Application programs can reuse these services using specified set of functions called System Calls.

Most of the kernels are designed for a specific operating system. For example Microsoft Windows XP kernel is only for Microsoft Windows XP. A few kernels have been designed for being suitable to use with any operating system. A best example of it is Mach kernel developed at Carnegie Mellon University and is used in Macintosh OS X operating system.


Categories of kernel :

Kernels can be classified in following major categories.

Monolithic kernel:

The word “monolithic” means everything in a single piece. So as the name implies, these kernels have been used by UNIX – like operating systems. It contains all the core operating system functions and device drivers. These functions do not run in separate process. Context switching is very less so it s faster.

Architecture of monolithic kernel

Since every function in the kernel has all privileges, a bug in one function can corrupt data structures of other. The whole kernel is less modular.

Pros

    * Speed
    * Simplicity of design

Cons

    * Potential stability issues
    * Can become huge - Linux 2.6 has 7.0 million lines of code
    * Potentially difficult to maintain

Examples

    * Traditional Unix kernels (For example  BSDs and Solaris)
    * Linux
    * MS-DOS, Windows 9x
    * Windows CE ( Embedded monolithic kernel)
    * Embedded Linux (Embedded monolithic kernel)



Microkernel:

In the Microkernel, only the most fundamental of tasks are performed. It usually provides only minimal services, such as defining memory address spaces, interprocess communication (IPC) and process management. All other functions, such as hardware management, are implemented as processes running independently of the kernel. Most Microkernels use a message passing system of some sort to handle requests from one server to another.

Architecture of Microkernel

Pros

    * Stability
    * Security
    * Potentially more responsive (though often not in practice)
    * Benefits for SMP machines

Cons

    * Additional context switches are usually required
    * Slow Inter Process Communication can result in poor performance

Examples of Microkernels and OSs based on Microkernels:

    * AIX
    * AmigaOS
    * Amoeba
    * Chorus Microkernel
    * EROS
    * K42
    * Minix
    * MorphOS
    * QNX
    * RadiOS
    * Spring Microkernel


Hybrid kernel:

As the word “Hybrid” in category implies, Hybrid kernels combine concepts of both monolithic kernels and Microkernels. When properly implemented it is hoped that this will result in the performance benefits of a monolithic kernel, with the stability of a Microkernel. Most modern operating system kernels today fall in this category.
Architecture of Hybrid kernel


Examples

    * NT kernel (used in Windows NT, 2000, XP, Vista and Windows 7)
    * Dragonfly BSD
    * Mac OS
    * BeOS
    * Plan 9

Friday, August 27, 2010

Executing Java program without main() function

The title of post seems strange but it is fact. You can develop a Java program without main() function.
Try to execute following program.

class MainMethodNot
{
    static
    {
        System.out.println("This java program have run without the run method");
        System.exit(0);
        
    }
}

The reason that this program executes because static block is executed as soon as the class is loaded. However JVM throws an exception because it doesn't find main() method which can be avoided by using System.exit() function.

Immutable strings in Java

Strings are said to be immutable in Java.Immutability refers to ability toprevent change in value.
It means whenever you change the value of String, you create a new object and make that variable refer to new object.Appending a string is also a same kind of operation internally.

Each time you use "+" operator or ( String.concat() ) , a new string is created, old data is copied and new data is appended. Old string will be garbage collected.

When to use "+":

1). Multiline Strings

  
String text=
    "line a\n"+
    "line l\n"+
    "line b";
 
2) Short messages
System.out.println("x:"+x+" y:"+y); 


When you have multiple string blocks to concat use StringBuilder or 
StringBuffer( if multithreading is used ) class.
 

Saturday, August 21, 2010

Program to print 1 to 10 using while loop ( GTU Sem I Program No : 8)

/*Program to print 1 to 10 using while loop 
  Program No         :- 8 of GTU Practice Programs SEM I 
  Developed by       :- Malhar Vora 
  Developed on       :- 21/07/2010 
  Email              :- vbmade2000@gmail.com 
  Web Site           :- http://malhar2010.blogspot.com 
  Development Status :- Completed
**************************************************/  
void main()
{
     int n=1;

     while(n<=10){
 printf("%d\n",n);//Prints n
 n++; //Incrementing n
     }
}

Execute function after completion of main() function in C using #pragma directive

/*This Program demonstrates the use of #pragma directive.#pragma exit can be used to call a function after main.The function must not returning anything other than void and must not contain any arguments.
  Syntax : #pragma exit function-name [priority]
  Here function-name is the name of a function and priority is optional.
  priority can be from 64 to 255.Do not use priority from 0 to 63 because they are used by C libraries.
  100 is a Default priority
  255 is a lowest priority
  Developed on       :- 28/03/2009
  Developed by       :- Malhar Vora
  Email              :- vbmade2000@gmail.com         
  WebSite            :- http://malhar2010.blogspot.com
  Development Status :- Completed
  
*************************************************************/


 #include 

void PrintChar1()
{
   printf("Hello after main1\n");
   getch();
}



#pragma exit PrintChar1


void main()
{

   printf("Hello from Main");

}

Execute function before execution of main() function in C using #pragma directive

/*This Program demonstrates the use of #pragma directive.
  #pragma startup can be used to call a function before main.The function
  must not returning anything other than void and must not contain any
  arguments.
  
  Syntax : #pragma startup function-name [priority]
  Here function-name is the name of a function and priority is optional.
  priority can be from 64 to 255.Do not use priority from 0 to 63 because
  they are used by C libraries.
  100 is a Default priority
  255 is a lowest priority
  Developed on       :- 28/03/2009
  Developed by       :- Malhar Vora 
  Email              :- vbmade2000@gmail.com         
  WebSite            :- http://malhar2010.blogspot.com
  Development Status :- Completed
  
******************************************************************/


 #include 

void PrintChar1()
{
   printf("Hello before main1\n");
}

void PrintChar2()
{

   printf("Hello before main2\n");
}


#pragma startup PrintChar1 64
#pragma startup PrintChar2 65

void main()
{

   printf("Hello from Main");

}

Friday, August 20, 2010

Classsification of programming languages

Classification according to level

#. Low level languages
  • Machine Language
  • Assembly Language

#. High level languages
  • Imperative Language (FORTRAN,COBOL,ALGOL-60,JAVA)
  • Functional Language (F#,Haskel,Scala,Erlang)
  • Logic Language (Prolog)
Classification according to features
  • Sequential(LOGO)
  • Concurrent(Erlang,Eiffel)
  • Modular(Python,Runy)
  • Parallel(Haskel,Erlang)
  • Distributed
  • Object Oriented(JAVA,C#,C++)

Sunday, August 8, 2010

C Program to print square of first and last nos of inputted no

/*Program to print square of first and last no of inputted no
  Created by : Malhar Vora
  Created on : 8-8-2010
  Email          : vbmade2000@gmail.com
  WebSite    :  http://malhar2010.blogspot.com
******************************************************************************************************/
#include

void main()
{
      int i=358,a=0,first=0,last=0,flgfirst=0;

    while(i>0)
   {

       a = i%10;

       if(flgfirst==0)
       {
              last=a;
              flgfirst=1;
       }

       first=a;

       i=i/10;
   }

   printf("Square of First no : %d",(first*first));
   printf("\nSquare of Second no : %d",(last*last));

} 

Sunday, July 25, 2010

Types of JIT Compiler

JIT (Just In Time) compiler converts non executable (MSIL) code to executable (native) code.This process is also called Dynamic Translation.
Following are the types of JIT compiler.

(1) PRE JIT Compiler
(2) ECONO JIT Compiler
(3) NORMAL JIT compiler

(1) PRE JIT Compiler

Pre-JIt compiler compiles complete source(MSIL)code to Native code in a single Compilation.

(2) ECONO JIT Compiler :

This compiler compiles only MSIL code of those methods that are called at Runtime.

(3) NORMAL JIT compiler:

This compiler compiles only MSIL code of those methods that are called at runtime and that converted (native) code is stored in cache.This happens because,when these methods called again it will retrieve code from cache itself without sending request to CLR.Thus,in turn saves much of executiom time

Saturday, July 24, 2010

Program to get data from user and store in STUDENT file, again read it from STUDENT file and write to DATA file and display same on screen ( GTU Sem I Program No : 41)

/*Program to get student data from user,
  write it to STUDENT file , read it again in
  store in DATA file and display same on screen
  Program No   : 41 of GTU Practice Programs SEM I
  Developed by : Malhar Vora
  Developed on : 21/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
**************************************************/


struct studata
{
   int rollno;
   char name[20];
};

typedef struct studata student;
student s;

//Get Student data from user
void readData()
{
    short temp;
    printf("Enter Roll No of Student :");
    scanf("%d",&temp);
    s.rollno=temp;

    fflush(stdin);
    printf("\nEnter Name of Student :");
    gets(s.name);

}

//Write inputted data to STUDENT file
void writeStudentFile()
{
   FILE *stufile;
   stufile=fopen("STUDENT","wt");
   if(stufile==NULL)
   {
      printf("\nError in writing STUDENT file");
      return;
   }
   fwrite(&s,sizeof(s),1,stufile);
   fclose(stufile);
}

//Clear structure s to hold new data
void clearData()
{
   s.rollno=0;
   strcpy(s.name,"");
}

//Read data from STUDENT file
void readStudentFile()
{
   FILE *stufile;
   stufile=fopen("STUDENT","rt");
   if(stufile==NULL)
   {
      printf("\nError in reading STUDENT file");
      return;
   }
   fread(&s,sizeof(s),1,stufile);
   fclose(stufile);
}

//Write data to DATA file
void writeDataFile()
{
   FILE *datafile;
   datafile=fopen("STUDENT","wt");
   if(datafile==NULL)
   {
      printf("\nError in writing DATA file");
      return;
   }

   fwrite(&s,sizeof(s),1,datafile);
   fclose(datafile);
}

//Display data fetched from STUDENT file
void displayData()
{
   printf("\nData from STUDENT file");
   printf("\nRoll No : %d",s.rollno);
   printf("\nName    : %s",s.name);
}

void main()
{
  clrscr();
  readData();
  writeStudentFile();
  clearData();
  readStudentFile();
  writeDataFile();
  displayData();
}


Thursday, July 22, 2010

Program to display size of int,float and double variables ( GTU Sem I Program No : 24)

/*Program to print the size of int,float and double variables
  Program No   : 24 of GTU Practice Programs
  Developed by : Malhar Vora
  Developed on : 20/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
****************************************************************************/


#include

void main()
{
   int i=1;
   float f=2.5;
   double d=2.60;
 
   printf("Size of int is %d",sizeof(i));
   printf("\nSize of int is %d",sizeof(f));
   printf("\nSize of int is %d",sizeof(d));

} 


Program to create linear linked list and print contents and total items( GTU Sem I Program No : 42)

/*Program to create a linear linked list interactively and print its
  content and total no of items in list
  Program No   : 42 of GTU Practice Programs SEM I
  Developed by : Malhar Vora
  Developed on : 20/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
****************************************************************************/


#include

#define LIMIT 5

//structure to hold data and link to next node
struct node
{
   int data;
   struct node *next;
};


short count=0; //Gloab lcounter to count no of items in list
typedef struct node *listnode;

listnode root=NULL;

void insert(int newdata)
{
    listnode newnode,temp;
    newnode=(listnode)malloc(sizeof(listnode));
    newnode->data=newdata;
    temp=root;
    while(temp->next!=NULL)
    {
       temp=temp->next;
    }
    temp->next=newnode;
    newnode->next=NULL;
    count++;
}

void print()
{
   listnode temp;
   temp=root;
   printf("\nPrinting items");
   while(temp->next!=NULL)
   {
       temp = temp->next;
       printf("\n%d",temp->data);
   }
}

void printcount()
{
   printf("\nTotal %d items are stored in linked list",count);
}

void main()
{
   clrscr();
   insert(1);
   insert(2);
   insert(3);
   insert(4);

   print();

   printcount();

}

Program to find maximum element from 1D array ( GTU Sem I Program No : 19)

/*Program to find maximum element from 1D array
  Program No   : 19 of GTU Practice Programs SEM I
  Developed by : Malhar Vora
  Developed on : 20/07/2010
  Email        : vbmade2000@gmail.com
  Web Site     : http://malhar2010.blogspot.com
****************************************************************************/


#include

#define LIMIT 5

int getMax(int *arr,int n)
{
   int i,max;
   max=arr[i];
   for(i=0;i
   {
      if(arr[i]>max)
     max=arr[i];
   }
   return max;
}

void main()
{
   int arr[LIMIT],i,max=0;
   clrscr();

   printf("Enter elements in array :");
   for(i=0;i
   {
      scanf("%d",&arr[i]);
   }


   printf("Max is : %d",getMax(arr,LIMIT));

}