Hi to all!!!! I Am Arpit Vijay Vergiya.
On this Blog i tried to share about Java.
I hope this blog will help you to learn many new things in java.
Keep visiting!!!
Keep sharing

by · No comments:

Matrix multiplication


import java.util.Scanner;
class MatrixMul{
		public static void main(String args[])
		{
				int a[][]= new int[3][3];
				int b[][]= new int[3][3];
				int c[][]=new int[3][3];
				int i,j,k;
				
				Scanner sc = new Scanner(System.in);
				System.out.println("enter Element 9 of 1st String");
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								a[i][j]=sc.nextInt();
						}
				}
				
				System.out.println("enter Element 9 of 2nd String");
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								b[i][j]=sc.nextInt();
						}
				}
				
				System.out.println("Matrix A\tMatrix B");
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								System.out.print(a[i][j]+" ");
						}
						
						System.out.print("\t\t");
						
						for(k=0;k<3;k++)
						{
								System.out.print(b[i][k]+" ");
						}
						System.out.println();
				}
				
				//logic for multiply
				
				int mul=0;
				for(i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								
								for(k=0;k<3;k++)
								{
										mul+= a[i][j]*b[j][k];
								}
								
								c[i][j]=mul;
								mul=0;
						}
			
				}
				
				System.out.println("Result is:");
				for( i=0;i<3;i++)
				{
						for(j=0;j<3;j++)
						{
								System.out.print(c[i][j]+" ");
						}
						
						System.out.println(" ");
				}
				
		}
}

Read More
by · No comments:

Arrange String character wise

import java.util.Scanner;
class StringCharSort{
		
		public static void main(String args[])
		{
				Scanner sc = new Scanner(System.in);
				System.out.println("Enter a String:");
				String str = sc.nextLine();
				char ch[] = str.toCharArray();
				for(int i=0;i	for(int j=1;j
						{
								if(ch[j-1]>ch[j])
								{
										char temp = ch[j-1];
										ch[j-1]=ch[j];
										ch[j]=temp;
								}
						
						}
						
				}
				for(char c :ch)
							{
									System.out.print(c);
							}
				
		}
		
}


Read More
by · No comments:

How to check given String is palindrom or not in java

String is palindrom or not


import java.util.Scanner;
class StringPalindrom{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter a line");
    String str = sc.nextLine();
    String str1="";
    char ch[] = str.toCharArray();
    for(int i=ch.length-1;i>=0;i--)
    {
      str1+=ch[i];
    }
     if(str.equals(str1))
      System.out.println("Palindrom");
     else
      System.out.println("Not palindrom");
    
    
  }
}






Read More
by · No comments:

Differences Between C , C++, and Java

Differences Between C , C++, and Java

Table Comparing C, C++ and Java:

This table is a summary of the differences found in the article.
Feature
C
C++
Java
Programming Approach
Procedural Programming Language
Procedural, OOP, Generic Programming languages
OOP, Generic Programming languages.
Compiled Source Code
Executable in  Native Code
Executable in Native Code
Compiled into Java byte code
Memory management
Manual Done,
Manual Done,
Managed, using a garbage collector
Pointers
Yes, very commonly used.
Yes, very commonly used, but some form of references available too.
No pointers; references are used instead.
Preprocessor
Yes
Yes
No
String Type
Character arrays
Character arrays, objects
Objects
Complex Data Types
Structures, unions
Structures, unions, classes
Classes
Inheritance
N/A
Multiple class inheritance
Single class inheritance, multiple interface implementation
Operator Overloading
N/A
Yes
No
Automatic coercions
(Conversion)
Yes, with warnings if loss could occur
Yes, with warnings if loss could occur
Not at all if loss could occur; must cast explicitly
Variadic Parameters
Yes
Yes
No
Goto Statement
Yes
Yes
No

 

Read More
by · No comments:

Age Calculater in java

Hiii Guys i was reading Date and Calendar class in java. With these two classes we can perform on date.Like we can get Date of system.
And we can calculate difference in two Dates.
We can get the year month and date of user given date.
so i got an idea why can not i write source code in which we can calculate age of a person by given his birth date or current date of system.

Here the source code for Age Calculator:-




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.event.*;
public class AgeCal1 extends JFrame implements ActionListener
{
    JList jdate,jmonth,jyear;
    JPanel jp,jp1,jp2;
    JScrollPane jsp1,jsp2,jsp3;
    JButton jb;
    JMenuBar jmb;
    JMenu file,help;
    JMenuItem exit,aboutUs;   
    public AgeCal1()
    {
      
    setTitle("Age Calculator");
        setSize(400,450);
        setLayout(null);
    getContentPane().setBackground(Color.PINK);
   
        jmb = new JMenuBar();
        file = new JMenu("File");
        file.setMnemonic(KeyEvent.VK_F);
        help = new JMenu("Help");
        help.setMnemonic(KeyEvent.VK_H);
        exit = new JMenuItem("Exit");
        exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MASK));
        exit.addActionListener(this);
        file.add(exit);
        aboutUs = new JMenuItem("About Us");
        aboutUs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,ActionEvent.CTRL_MASK));
        aboutUs.addActionListener(this);
        help.add(aboutUs);
        jmb.add(file);
        jmb.add(help);
        setJMenuBar(jmb);
    addWindowListener(new MyWindowListener(this));
        Vector<Integer>date=new Vector<Integer>();
        {
            for(int i=1;i<=31;i++)
            {
                date.add(i);
            }
        }
        jdate = new JList(date);
        jdate.setVisibleRowCount(5);
        jdate.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Vector<Integer> mon = new Vector<Integer>();
       
            for(int i=1;i<=12;i++)
            {
            mon.add(i);   
            }
       
        jmonth = new JList(mon);
        jmonth.setVisibleRowCount(4);
        jmonth.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        Vector<Integer>year = new Vector<Integer>();
        for(int i=1950;i<2050;i++)
        {
            year.add(i);
        }
        jyear = new JList(year);
       
        jyear.setVisibleRowCount(10);
        jyear.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jp = new JPanel();
        jp.setBorder(BorderFactory.createTitledBorder("Select date"));
       
        jp1=new JPanel();
        jp1.setBorder(BorderFactory.createTitledBorder("Select Month"));
       
        jp2 = new JPanel();
        jp2.setBorder(BorderFactory.createTitledBorder("Select Year"));
        jsp1 = new JScrollPane(jdate);
        jsp2 = new JScrollPane(jmonth);
        jsp3 = new JScrollPane(jyear);
       
        jp.add(jsp1);
        jp.setBackground(Color.orange);
        jp1.add(jsp2);
        jp2.add(jsp3);
        jp.setBounds(10,100,100,200);
        jp1.setBounds(130,100,100,150);
        jp2.setBounds(250,100,100,220);
        add(jp);
        add(jp1);
        add(jp2);
        jb = new JButton("Calculate");
        jb.setBounds(100,350,100,40);
        add(jb);
        jb.addActionListener(this);
        setVisible(true);
       
    }
    @Override
    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource()==jb)
        {
        try
        {

    int userDate = (Integer)jdate.getSelectedValue();
   
    int userMonth = (Integer)jmonth.getSelectedValue();
   
    int userYear = (Integer)jyear.getSelectedValue();

    Calendar bday = Calendar.getInstance();
    bday.set(userYear,userMonth,userDate);
    Calendar today = Calendar.getInstance();
   
    if((today.after(bday)))
    {
        int curDate = today.get(Calendar.DATE);
        int curMonth = today.get(Calendar.MONTH);
        int curYear = today.get(Calendar.YEAR);
        int day = userDate-curDate;
        if(day>0)
        {
            day=day;
        }
        else
        {
            day=day+(2*(-day));
        }
   
        int month = userMonth-curMonth;
        if(month>0){
        month=month;
        }
        else
        {
            month= month+(2*(-month));
        }
       
        int year = userYear-curYear;
        if(year>0)
        {
            year=year;
        }
        else
        {
            year =year+(2*(-year));
        }
       
        JOptionPane.showMessageDialog(this,"You Are:"+year+" Year"+" "+month+
            "Month"+day+" "+"Days Old..","AgeCal by Arpit",JOptionPane.INFORMATION_MESSAGE);
    }
    else
    {
        JOptionPane.showMessageDialog(this,"Bawali pooch tu to paida nhi hua","AgeCal",JOptionPane.ERROR_MESSAGE);
    }
       
        }
        catch(Exception e)
        {
            if(jdate.getSelectedValue()==null)
    {
        JOptionPane.showMessageDialog(this,"Please select Your Birth Date???","AgeCal v1.0",JOptionPane.ERROR_MESSAGE);
    }
    else if(jmonth.getSelectedValue()==null)
    {
    JOptionPane.showMessageDialog(this,"Please select Your Birth Month???","AgeCal v1.0",JOptionPane.ERROR_MESSAGE);
    }
   
    else    if(jyear.getSelectedValue()==null)
    {
        JOptionPane.showMessageDialog(this,"Please select Your Birth Year????","AgeCal v1.0",JOptionPane.ERROR_MESSAGE);
    }
   
   
        }
       
        }
        if(ae.getSource()==exit)
        {
            Sysetm.exit(0);
        }
        if(ae.getSource()==aboutUs)
        {
            JOptionPane.showMessageDialog(this,"Developed By Arpit Vijay"+"\n"+"Contact:-Vijayarpit.vijay@gmail.com","Agecal v1.0",JOptionPane.INFORMATION_MESSAGE);
        }
    }
   
    public static void main(String...s)
    {
        new AgeCal1();
    }
}


 class MyWindowListener extends WindowAdapter
 {
     AgeCal1 close;
     public MyWindowListener(AgeCal1 ac)
     {
         close =ac;
     }
     @Override
     public void windowClosing(WindowEvent we)
     {
         int x = JOptionPane.showConfirmDialog(close,"Really do you Want to exit???","AgeCal v1.0",JOptionPane.YES_NO_OPTION);
         if(x==JOptionPane.YES_OPTION)
         {
             close.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         }
         if(x==JOptionPane.NO_OPTION)
         {
             close.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
         }
     }
 }





Thanx Guys Dont forget to share and like.
Soon i am going to upload its .Exe so you can easily Run it on windows
Read More