Thursday 28 March 2013

Program to find maximum and minimum number for a n*n matrix

import java.io.*;
 class test
 {
 public static void main(String[] asd)throws IOException
 {
 BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
 System.out.println("Enter the values of Rows and Columns of Matrix.");
 String num=obj.readLine();
 int r=Integer.parseInt(num);
 num=obj.readLine();
 int c=Integer.parseInt(num);
 int m[][]= new int[r][c];
 int max=0, min=0;
 System.out.println("Enter the values of the matrix not more then "+(r*c)+".");
 for(int i=0;i<r;i++)
 for(int j=0;j<c;j++)
 {
 num=obj.readLine();
 m[i][j]=Integer.parseInt(num);
 }
 System.out.println("Original matrix::");
 for(int i=0;i<r;i++)
 {
 for(int j=0;j<c;j++)
 {
 System.out.print(m[i][j]+" ");
 }
 System.out.println();
 }
 // MAXIMUM element of the matrix max=m[0][0];
 for(int i=0;i<r;i++)
 {
 for(int j=0;j<c;j++)
 {
 if(m[i][j]>max) max=m[i][j];
 }
 }
System.out.println("Maximum of the matrix is "+max+".");
//MINIMUM element of the matrix min=m[0][0];
 for(int i=0;i<r;i++)
 {
 for(int j=0;j<c;j++)
 {
 if(m[i][j]<min) min=m[i][j];
 }
 }
 System.out.println("Minimum of the matrix is "+min+".");
 }
 }

Wednesday 27 March 2013

Four different ways to create an object in java


1. Using new keyword
This is the most common way to create an object in java. I read somewhere that almost 99% of objects are created in this way.
MyObject object = new MyObject();
2. Using Class.forName()
If we know the name of the class & if it has a public default constructor we can create an object in this way.
MyObject object = (MyObject) Class.forName("subin.rnd.MyObject").newInstance();
3. Using clone()
The clone() can be used to create a copy of an existing object.
MyObject anotherObject = new MyObject();
MyObject object = anotherObject.clone();
4. Using object deserialization
Object deserialization is nothing but creating an object from its serialized form.
ObjectInputStream inStream = new ObjectInputStream(anInputStream );
MyObject object = (MyObject) inStream.readObject();

Tuesday 19 March 2013

How To Create A War File In Netbeans




  1. Right click on your project name in the Explorer
  2. Select Properties
  3. In the Build | Packaging section, check "Compress War file" option.
  4. Select file/folder and select your project then u can see war file in dist folder