Wednesday 31 December 2014

SUICIDE IS INHERITABLE

A  study says that children whose parents attempted suicide are 5 times more likely to attempt suicide than another children which means suicide is also inherited.
 “In this high-risk longitudinal study, we found that parental suicide attempt conveyed a nearly 5-fold increased risk of offspring attempt, even controlling for the familial transmission of mood disorder,” explains lead study author David A Brent MD, of the University of Pittsburgh Medical Centre.
But the study not only confirmed suicidal behaviour can in fact run in families, but that these pathways for suicidal behaviour can be transmitted through families, almost pathologically.
Impulsive aggression played an important role in increasing the likelihood of an offspring suicide attempt, but it did so by increasing the risk of the subsequent development of a mood disorder, which in turn increased the risk of an attempt.

In this study, the researchers looked at 701 children (between the ages of 10 and 50) of 334 parents who had documented mood disorders. 191 of these parents had attempted suicide, and 44 percent of the offspring had followed suit before the study; 29 percent attempted suicide after during the study follow-up.

Tuesday 30 December 2014

Write a C++ program to check whether a number is even or odd


#include
using namespace std;
int main()
{
int a;
cout<<"enter no";
cin>>a;
if(a%2==0)
{
cout<<"no is even"< }
else
{ cout<<"no is odd"< }
}

Write a C++ to find greatest of three numbers.


#include<iostream>
using namespace std;
int sum(int x,int y,int z)
{
if(x>y)
{ if(y>z)
{
return x;
}}
if(y>z)
{
return y;
}

else{ return z;
}
}
int main()
{ int a=0,b=0,c=0;
cout<<"enter first no";
cin>>a;
cout<<"enter second no";
cin>>b;
cout<<"enter third no";
cin>>c;
int d= sum(a,b,c);
cout<<"greatest is "< }

Sunday 28 December 2014

Write a c++ program to find Simple Interest and Compound Interest.



#include<cmath>
#include<iostream>
using namespace std;
double simple(int p,float r,int t)
{
return (p*r*t)/100;
}
double amount(int p,float x,int y,float z)
{ x= 1+z/100;
return p*pow(x,y);
}
double compound(int c,int d) {
return c-d;
}
int main()
{ int p=0,t=0;
float r;
double s = simple(200,1.2,2);
double d = amount(200,1.2,2,2.4);
double ci = compound(d,p);
}


Things to learn :

include<cmath> is used in place of include<math.h>
include<cmath>h is used in gcc compiler (in linux)

pow() is an inbuilt function in c++ with syntax :
double pow (double base, double exponent);

Write a c++ program to find the sum of two numbers using function.


#include<iostream>
using namespace std;
int sum(int a,int b)
{ return a+b;
}
int main()
{
int a=0,b=0;
cout<<"enter 1st no";
cin>>a;
cout<<"enter 2nd no";
cin>>b;
int c = sum(a,b);
}

Things to learn from this program :

Defining a Function:

function definition :

return_type function_name( parameter list )
{
body of the function
}

Declaring a Function:

return_type function_name(parameter list);

Calling a function :

function_name( [arg1, ... ] );

Function is to be defined outside main() function.
a and b are to be initialized to zero so that all previous values are deleted.


Another way of doing the program (if you want to do sum of known values):



#include<iostream>
using namespace std;
int sum(int a,int b){
return a+b;
}
int main()
{
int c= sum(10,20);
}

Friday 3 October 2014

Cloud Computing !!





Have you ever thought how we take advantage of Google Drive and Gmail or how we are using Facebook.How is our data stored on Google ?






The force behind this is CLOUD COMPUTING
Cloud Computing is all about different computers interlinked to data-processing tasks, centralized data storage, sharing of resources and data and also online access to computer services or resources.
In cloud computing one does not need to buy the required resources, you only need to use a shared cloud infrastructure and pay for it.
Internet is also a type of cloud computing.

n a cloud computing system, there's a significant workload shift. Local computers no longer have to do all the heavy lifting when it comes to running applications. The network of computers that make up the cloud handles them instead. Hardware and software demands on the user's side decrease. The only thing the user's computer needs to be able to run is the cloud computing system's interface software, which can be as simple as a Web browser, and the cloud's network takes care of the rest.

Service Models in Cloud Computing :


1. SaaS: In the business model using software as a service (SaaS), users are provided access to application software and databases. Cloud providers manage the infrastructure and platforms that run the applications. SaaS is sometimes referred to as "on-demand software" and is usually priced on a pay-per-use basis.Software-as-a-Service provides complete applications to a cloud’s end user.
2. Platform as a service (PaaS) : In the PaaS models, cloud providers deliver a computing platform, typically including operating system, programming language execution environment, database, and web server. Application developers can develop and run their software solutions on a cloud platform without the cost and complexity of buying and managing the underlying hardware and software layers. With some PaaS offers like Microsoft Azure and Google App Engine, the underlying computer and storage resources scale automatically to match application demand so that the cloud user does not have to allocate resources manually.
3. Infrastructure as a service (IaaS) : The services on the infrastructure layer are used to access essential IT resources that are combined under the heading Infrastructure-as-a-Service (IaaS). These essential IT resources include services linked to computing resources, data storage resources, and the communications channel. They enable existing applications to be provisioned on cloud resources and new services implemented on the higher layers.
4. Data as a service : comprises data delivered as a service rather than being stored locally. The data may be consumed by tradional on-premises software, smart clients, websites or SaaS solutions.Typically the data is prepared and formatted ready for use by the client software.


Deployment models :

Public Cloud
 The deployment of a public cloud computing system is characterized on the one hand by the public availability of the cloud service offering and on the other hand by the public network that is used to communicate with the cloud service. The cloud services and cloud resources are procured from very large resource pools that are shared by all end users.

Private Cloud
Private cloud computing systems emulate public cloud service offerings within an organization’s boundaries to make services accessible for one designated organization. Private cloud computing systems make use of virtualization solutions and focus on consolidating distributed IT services often within data centers belonging to the company.

Hybrid Cloud
A hybrid cloud service deployment model implements the required processes by combining the cloud services of different cloud computing systems, e.g. private and public cloud services. The hybrid model is also suitable for enterprises in which the transition to full outsourcing has already been completed, for instance, to combine community cloud services with public cloud services.

Sunday 27 July 2014

if adt doesn't start??? ADT error !!! Solve it now :)

what to do if your adt bundle suddenly stops working? it happened with me... when i started the adt eclipse, it just appeared for a flash of time and the adt startup screen disappeared.. so i have a solution for this...
if this happens with you all you have to do is

  1. go to the folder where you have saved all the adt files
  2. then delete the metadata  folder
  3. reopen the eclipse
  4. it will work as it was working previously
  5. if you are facing some other problem you can comment below... we will solve your problem 

Monday 21 July 2014

program to play music in JFrame

import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;
import javax.swing.*;
 
// To play sound using Clip, the process need to be alive.
// Hence, we use a Swing application.
public class sounds extends JFrame {
 
   // Constructor
   public sounds() {
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      this.setTitle("Test Sound Clip");
      this.setSize(300, 200);
      this.setVisible(true);
   
      try {
   
         // Open an audio input stream.
         URL url = this.getClass().getClassLoader().getResource("mus.wav");
         //
          AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
         // Get a sound clip resource.
          for(int i=0; i<10; i++){   Clip clip = AudioSystem.getClip();
         // Open audio clip and load samples from the audio input stream.
         clip.open(audioIn);
         clip.start();}
      } catch (UnsupportedAudioFileException e) {
     JOptionPane.showMessageDialog(this, e.getMessage());
         e.printStackTrace();
      } catch (IOException e) { JOptionPane.showMessageDialog(this, e.getMessage());
         e.printStackTrace();
      } catch (LineUnavailableException e) { JOptionPane.showMessageDialog(this, e.getMessage());
         e.printStackTrace();
      }
   }
 
   public static void main(String[] args) {
      new sounds();
   }
}

Wednesday 16 July 2014

Program to play and stop music on your choice in java applet

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

public class mus3 extends Applet
implements ActionListener{
   Button play,stop;
   AudioClip audioClip;
   public void init(){
      play = new Button("  Play ");
      add(play);
      play.addActionListener(this);
      stop = new Button("  Stop  ");
      add(stop);
      stop.addActionListener(this);
      audioClip = getAudioClip(getCodeBase(), "mus.wav");
   }
   public void actionPerformed(ActionEvent ae){
      Button source = (Button)ae.getSource();
      if (source.getLabel() == "  Play  "){
         audioClip.play();
      }
      else if(source.getLabel() == "  Stop  "){
         audioClip.stop();
      }
   }
}

Tuesday 15 July 2014

Program to play music in java Applet

import java.applet.*;
import java.awt.*;

public class music1 extends Applet {
   Button play,stop;
   AudioClip audioClip;
   public void init(){
   
      audioClip = getAudioClip(getCodeBase(), "mus.wav");
      audioClip.play();
   }
 
}

Saturday 28 June 2014

Program to show the example of radio buttons

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class Radio extends Applet implements ActionListener
{
Checkbox ch1,ch2;
CheckboxGroup cbg;
Button b1;

public void init()
{
cbg=new CheckboxGroup();
b1=new Button("check");
ch1= new Checkbox("male",cbg,true);
ch2= new Checkbox("female", cbg,true);
add(ch1);
add(ch2);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String a=" ", b=" ", c=" ";
if(e.getSource()==b1)
{
if(ch1.getState()==true)
{a="male";}
else if(ch2.getState()==true)
{b="female";}

JOptionPane.showMessageDialog(this, "u have selected "+a+b);

}
}}

output:


Program to show two listed choices and print their table

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Mullist extends Applet implements ItemListener{
Choice ch1,ch2;
List l1;
int c,d;
public void init()
{
ch1=new Choice();
ch2=new Choice();
l1=new List(10);
for(int i=1; i<=100; i++)
{
ch1.add(String.valueOf(i));
ch2.add(String.valueOf(i));
}
add(ch1);
add(ch2);
add(l1);
ch1.addItemListener(this);
ch2.addItemListener(this);

}
public void itemStateChanged(ItemEvent e) {
if(e.getSource()==ch1)
{
c=Integer.parseInt(ch1.getSelectedItem());
}
if(e.getSource()==ch2)
{
d=Integer.parseInt(ch2.getSelectedItem());
}

for(int i=1; i<=d; i++)
{
l1.add(""+c+"x"+i+"="+c*i+"\n");
}
}

}

output:




Friday 27 June 2014

Make your own KBC(kaun banega crorepati) game

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class Kbc extends Applet implements ActionListener{
Label l1,l2,l3;
Panel p1,p2,p3,p4;
CheckboxGroup c1,c2,c3;
Checkbox  ch1,ch2,ch3,ch4,ch5,ch6,ch7,ch8,ch9,ch10,ch11,ch12;
Button b1,b2,b3,b4;


public void init()
{
setLayout(null);
p1=new Panel();
p1.setBounds(100,10,800,500);
add(p1);
c1=new CheckboxGroup();
c2=new CheckboxGroup();
c3=new CheckboxGroup();
b1= new Button("lock the answer");
l1 = new Label();
l1.setText("Q1: what is the capital of india?");
p1.add(l1);
ch1= new Checkbox("delhi",c1,false);
ch2= new Checkbox("chandigarh", c1,false);
ch3= new Checkbox("manipur", c1,false);
ch4= new Checkbox("mumbai", c1,false);
p1.add(ch1);
p1.add(ch2);
p1.add(ch3);
p1.add(ch4);
p1.add(b1);
b1.addActionListener(this);
p2=new Panel();
p2.setBounds(100,10,800,500);
add(p2);
b2= new Button("lock the answer");
l2 = new Label();
l2.setText("Q2: who is the founder of facebook");
p2.add(l2);
ch5= new Checkbox("mark zukerberg",c2,false);
ch6= new Checkbox("james wat", c2,false);
ch7= new Checkbox("sherlock", c2,false);
ch8= new Checkbox("orkut", c2,false);
p2.add(ch5);
p2.add(ch6);
p2.add(ch7);
p2.add(ch8);
p2.add(b2);
b2.addActionListener(this);
p3=new Panel();
p3.setBounds(100,10,800,500);
add(p3);
b3= new Button("lock the answer");
l3 = new Label();
l3.setText("Q2: what is the capital of punjab?");
p3.add(l3);
ch9= new Checkbox("iraq",c3,false);
ch10= new Checkbox("chandigarh", c3,false);
ch11= new Checkbox("crap", c3,false);
ch12= new Checkbox("mumbai", c3,false);
p3.add(ch9);
p3.add(ch10);
p3.add(ch11);
p3.add(ch12);
p3.add(b3);
b3.addActionListener(this);

p1.setBackground(Color.blue);
p2.setBackground(Color.cyan);
p3.setBackground(Color.pink);


p4=new Panel();
p4.setBounds(100,10,800,500);
add(p4);
p4.setBackground(Color.gray);
b4=new Button("done");
p4.add(b4);
b4.addActionListener(this);
p1.setVisible(true);
p2.setVisible(false);
p3.setVisible(false);
p4.setVisible(false);
}
public void actionPerformed(ActionEvent e) {
String a=" ", b=" ";

if(e.getSource()==b1)
{
if(ch1.getState()==true)
a="right";
else if(ch2.getState()==true)
b="wrong";
else if(ch3.getState()==true)
b="wrong";
else if(ch4.getState()==true)
b="wrong";

JOptionPane.showMessageDialog(this, "u have selected "+a+b);
p1.setVisible(false);
p2.setVisible(true);
p3.setVisible(false);
p4.setVisible(false);
}
if(e.getSource()==b2)
{
if(ch5.getState()==true)
a="right";
else if(ch6.getState()==true)
b="wrong";
else if(ch7.getState()==true)
b="wrong";
else if(ch8.getState()==true)
b="wrong";
JOptionPane.showMessageDialog(this, "u have selected "+a+b);
p1.setVisible(false);
p2.setVisible(false);
p3.setVisible(true);
p4.setVisible(false);
}
if(e.getSource()==b3)
{
if(ch9.getState()==true)
b="wrong";
else if(ch10.getState()==true)
a="right";
else if(ch11.getState()==true)
b="wrong";
else if(ch12.getState()==true)
b="wrong";
JOptionPane.showMessageDialog(this,"u have selected "+a+b);
p1.setVisible(false);
p2.setVisible(false);
p3.setVisible(false);
p4.setVisible(true);
}
if(e.getSource()==b4)
System.exit(0);
}}

Wednesday 25 June 2014

Program to print delayed output using multithreading


public class loading implements Runnable{


public void run() {
// TODO Auto-generated method stub
int i;

for(i=0; i<=5; i++)
{
try
{

Thread.sleep(1000);

}
catch(Exception e){}
System.out.println("i="+i);
}

}
public static void main(String[] args)
{
loading l=new loading();
Thread t=new Thread(l);
t.start();

}}

output:
i=0
i=1
i=2
i=3
i=4
i=5

Program to print delayed output

import javax.swing.*;

public class delayed {

public static void main(String[] args)
{
int i;

for(i=0; i<=5; i++)
{
try
{

Thread.sleep(1000);

}
catch(Exception e){}
System.out.println("i="+i);
}

}}

output:
i=0
i=1
i=2
i=3
i=4
i=5

Tuesday 24 June 2014

Program to show Panels and Buttons

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class addingpanelonpanel extends Applet implements ActionListener{
Panel p1,p2;
Button b1,b2;

public void init()
{
setLayout(null);
b1= new Button("open panel 2");
b2= new Button("open panel 1");
b1.setBounds(130,130,160,20);
b2.setBounds(450,130,160,20);
p1=new Panel();
p2=new Panel();
p1.setBounds(120,120,220,120);
p2.setBounds(420,120,220,120);
p1.setBackground(Color.red);
p2.setBackground(Color.PINK);
b1.addActionListener(this);
b2.addActionListener(this);
p1.setVisible(true);
p2.setVisible(false);
add(p1);
add(p2);
p1.add(b1);
p2.add(b2);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b1)
{
p2.setVisible(true);
p1.setVisible(false);
}
else
{
p1.setVisible(true);
p2.setVisible(false);
}
}

}

output:

Creating a frame having menu

import java.awt.Frame;
import java.awt.Menu;
import java.awt.*;
import java.awt.event.*;
public class Menucreation extends Frame implements WindowListener{
Menucreation()
{
MenuBar mb;

Menu f,e,w;
MenuItem n,c,cpy,pst,h;
mb= new MenuBar();
f=new Menu("file");
e=new Menu("edit");
w=new Menu("window");
n=new MenuItem("new");
c=new MenuItem("cut");
cpy=new MenuItem("copy");
pst=new MenuItem("paste");
h=new MenuItem("help");

this.setMenuBar(mb);
mb.add(f);
mb.add(e);
mb.add(w);
f.add(n);
e.add(c);
e.add(cpy);
e.add(pst);
w.add(h);
this.setVisible(true);
this.setSize(1000, 600);
this.setTitle("mine");
this.addWindowListener(this);
}

public static void main(String[] args) {
new Menucreation();

}

public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
System.exit(0);
}

public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub

}

}

output:

Creating a new frame

import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class Framecreation extends Frame implements WindowListener{
Framecreation()
{
this.setVisible(true);
this.setSize(200, 200);
this.setTitle("mine");
this.addWindowListener(this);
}

public static void main(String[] args) {
new Framecreation();

}

public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
System.exit(0);
}

public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}

public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub

}

}

output:


Monday 23 June 2014

Program to show the example of choice

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class  choic extends Applet implements ItemListener
{
Choice ch1;
public void init()
{
ch1=new Choice();
ch1.add("green");
ch1.add("red");
ch1.add("blue");
add(ch1);
ch1.addItemListener(this);
}
public void itemStateChanged(ItemEvent e) {
if(e.getSource()==ch1)
{
int c =ch1.getSelectedIndex();
switch(c)
{
case 0:
this.setBackground(Color.green);
break;
case 1:
this.setBackground(Color.red);
break;
case 2:
this.setBackground(Color.blue);
break;
default:
this.setBackground(Color.black);


}

}}}

output:


Program to show the example of LIST and add items to it

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

import javax.swing.JOptionPane;
public class  liss extends Applet implements ItemListener, ActionListener
{
List ch1;
Button b1,b2,b3;
TextField t;
public void init()
{
ch1=new List(6);
ch1.add("green");
ch1.add("red");
ch1.add("blue");
add(ch1);
t=new TextField(" ");
add(t);
b1=new Button("add");
add(b1);
b1.addActionListener(this);
b2=new Button("remove");
add (b2);
b2.addActionListener(this);
ch1.addItemListener(this);
ch1.addActionListener(this);

}

public void itemStateChanged(ItemEvent e) {
if(e.getSource()==ch1)
{
int c =ch1.getSelectedIndex();

switch(c)
{
case 0:
this.setBackground(Color.green);
break;
case 1:
this.setBackground(Color.red);
break;
case 2:
this.setBackground(Color.blue);
break;
default:
this.setBackground(Color.black);


}

}}

public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1)
{
ch1.add(t.getText());
}
else
{
ch1.remove(ch1.getSelectedIndex());
}
}}


OUTPUT:

Program to make a paint brush in java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class paint extends Applet implements MouseMotionListener{
Graphics g;
public void init()
{
g = getGraphics();
this.addMouseMotionListener(this);
}


public void mouseDragged(MouseEvent e) {
g.fillRect(e.getX(), e.getY(), 10, 10);
}
public void mouseMoved(MouseEvent arg0) {
}

}

outout:

Saturday 21 June 2014

Program to show boolean data type

package sum;

public class bool {

public static void main(String[] args) {
// Demonstrate boolean values.
boolean b;
b = false;
System.out.println("b is " + b);
b = true;
System.out.println("b is " + b);
// a boolean value can control the if statement
if(b) System.out.println("This is executed.");
b = false;
if(b) System.out.println("This is not executed.");
// outcome of a relational operator is a boolean value
System.out.println("10 <9 is " + (10 < 9));

}

}

output:
b is false
b is true
This is executed.
10 <9 is false

Wednesday 18 June 2014

Program to illustrate the use of mouse listener, mouse motion listener and key listener

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//import java.awt.event.MouseMotionListener;

public class Swingmouse extends Applet implements MouseListener, MouseMotionListener, KeyListener{
int x,y;
char k= ' ';
String str= " ";
Font f=new Font(" ", 50, 50);
public void init()
{
this.setFont(f);
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.addKeyListener(this);
}
public void paint(Graphics g)
{
g.drawString(str, 45,45);
}
public void mouseClicked(MouseEvent e) {
str="mouse clicked";
repaint();

}
public void mouseEntered(MouseEvent e) {
str="mouse entered";
repaint();


}
public void mouseExited(MouseEvent e) {
str="mouse exited";
repaint();

}
public void mousePressed(MouseEvent e) {
str="mouse pressed";
repaint();


}
public void mouseReleased(MouseEvent e) {
str="mouse released";
repaint();

}
public void mouseDragged(MouseEvent e) {
str="mouse dragged";
x=e.getX();
y=e.getY();
repaint();

}
public void mouseMoved(MouseEvent e) {
str="mouse moved";
repaint();

}
public void keyPressed(KeyEvent e) {
k=e.getKeyChar();
repaint();
}
public void keyReleased(KeyEvent e) {
str= " ";
repaint();
}
public void keyTyped(KeyEvent e) {
k=e.getKeyChar();
str=String.valueOf(e.getKeyChar());
repaint();
}
}

Program to use applets and make a diagram

import java.applet.Applet;
import java.awt.*;
public class graph extends Applet {

Font f=new Font("cambria",65,32);

public void init()
{
this.setFont(f);
}
public void paint(Graphics g)
{

g.drawLine(220,114,120,240);
g.drawLine(220,114,320,240);
g.drawLine(125,235,125,350);
g.drawLine(315,235,315,390);
g.drawLine(125,350,315,390);
g.drawLine(220,114,400,114);
g.drawLine(315,235,490,235);
g.drawLine(400,114,490,235);
g.drawLine(490,235,490,350);
g.drawLine(315,390,490,350);
g.drawRect(385,275,50,40);
g.drawLine(255,377,255,260);
g.drawLine(190,363,190,260);
g.drawLine(255,260,190,260);
g.drawLine(490,325,590,325);
g.drawLine(490,345,590,345);
g.drawLine(490,305,590,305);
g.drawLine(125,325,25,325);
g.drawLine(125,345,25,345);
g.drawLine(125,305,25,305);
g.drawString("HOME SWEET HOME",175,90);

}
}

output:

Sunday 15 June 2014

general Program to sow try catch statement

package sum;

import javax.swing.JOptionPane;

public class implementtryandcatch {

public static void main(String[] args) {
int a,b,c=0;
try
{
a=Integer.parseInt(JOptionPane.showInputDialog("enter  A:"));
b=Integer.parseInt(JOptionPane.showInputDialog("enter  B:"));
c=a/b;
}
catch (Exception p)
{
System.out.print(p.getMessage());
}
System.out.print("\ndivision="+c);
}

}

output:
enter A 5
enter B 0
/ by zero
division=0

Program to show Exception handling ( try and catch statement)

package sum;

import javax.swing.JOptionPane;

public class finallyaftercatch {

public static void main(String[] args) {
int a,b,c=0;
try
{
a=Integer.parseInt(JOptionPane.showInputDialog("enter  A:"));
b=Integer.parseInt(JOptionPane.showInputDialog("enter  B:"));
c=a/b;
}
catch (NumberFormatException p)
{
System.out.print("wrong value entered");
}
catch (ArithmeticException p)
{
System.out.print("denominator zero entered");
}
finally {
System.out.print("\ndivision="+c); }

}

}
 enter A 5
enter B 0
denominator zero entered
division=0

Program to show function overloading

import javax.swing.JOptionPane;

class over
{
int a,b;
public void in()
{
a=Integer.parseInt(JOptionPane.showInputDialog("enter  A:"));
b=Integer.parseInt(JOptionPane.showInputDialog("enter  B:"));

}
public void add()
{
int k=a+b;
System.out.print("\nsum="+k);
}
public void add(int k, int m)
{
int c=k+m;
System.out.print("\nsum="+c);
}
public int add(int q, int w, int e)
{
return (q+w+e);
}
}
public class overloading {

public static void main(String[] args) {
over t=new over();
t.in();
t.add();
t.add(2,4);
int l=t.add(1,2,3);
System.out.print("\nsum="+l);


}

}

output
enter a 2
enter b 3
sum=5
sum=6
sum=6

Program to show constructors in java

class A
{
int a,b,c;
public A() //default constructor
{
a=4;
b=5;
c=a*b;
System.out.print("into= "+c);
}
public A(int x, int y)  //parameterised constructor
{
c=x+y;
System.out.print("\nSUM= "+c);
}

}
public class consdes {

public static void main(String[] args) {
A t=new A();

A o=new A(1,2);

}

}

output:
into= 20
SUM= 3

Program to add two numbers in single inheritance

import javax.swing.JOptionPane;
 abstract class k
{
public int a,b;
public void show()
{
a=Integer.parseInt(JOptionPane.showInputDialog("enter  A:"));
b=Integer.parseInt(JOptionPane.showInputDialog("enter  B:"));

System.out.print("\nshow");
}
public int ret()
{
return (a);

}
public int urn()
{
return (b);
}
}
class l extends k
{
int sum;

public void in()
{
sum=a+b;
System.out.print("\nsum=" +sum);
System.out.print("\nin");
}
}
public class abs {

public static void main(String[] args) {

l n=new l();

n.show();
n.in();


}

}

output:
enter a 2
enter b 2
show
sum=4
in

Program to show single inheritance in java

class am
{
public void show()
{
System.out.print("\nshow");
}
}
class B extends am
{
public void in()
{
System.out.print("\nin");
}
}

public class Aaa {

public static void main(String[] args) {

am m=new am();
B n=new B();
m.show();
n.in();
n.show();
}
}
output:

show
in
show

Friday 13 June 2014

How to use java on ADT (android developer tool) kit

Java development overview
The JDT project provides the tool plug-ins that implement a Java IDE supporting the development of any Java application, including Eclipse plug-ins. It adds a Java project nature and Java perspective to the Eclipse Workbench as well as a number of views, editors, wizards, builders, and code merging and refactoring tools. The JDT project allows Eclipse to be a development environment for itself.

Preparing Eclipse

In this section, you will verify that Eclipse is properly set up for Java development.
The following is assumed:
  • You are starting with a new Eclipse installation with default settings.
  • You are familiar with the basic Eclipse workbench mechanisms, such as views and perspectives.

Verifying JRE installation and classpath variables

1.     If you still see the Eclipse Welcome page, click the arrow icon to begin using Eclipse.
2.     Select the menu item Description: Goto workbench preferencesWindow > Preferences... to open the workbench preferences. 
3.     Select the Description: Goto the installed JREs preference pageJava > Installed JREs preference page to display the installed Java Runtime Environments. Confirm that a JRE has been detected. By default, the JRE used to run the workbench will be used to build and run Java programs. It should appear with a checkmark in the list of installed JREs. We recommend that you use a Java SDK instead of a JRE. An SDK is designed for development and contains the source code for the Java library, easing debugging. Additional SDKs can be added by searching the hard drive for installed SDKs. To do so, simply click the Search... button and specify a root folder for the search.
If you work with code that does not yet use generics (as we do in this tutorial), we recommend that you install a Java SDK 1.4 as well, but leave the most recent version checked as default.


4.   Select the Description: Goto the workspace preference pageGeneral > Workspace preference page. Confirm that the Build automatically option is checked.
             5.     Select the Description: Goto the Java build path preference pageJava > Build Path preference page. Confirm that Source and                  output folder is set to Folders
             6.     Select the Description: Goto the Java editor preference pageJava > Editor preference page. Confirm that option Report                      problems as you type is checked. 
7.     Select the Description: Goto the Java compiler preference pageJava > Compiler preference page. Confirm that option Compiler compliance level matches your default JRE version (usually 1.6). 
8.     Click on OK to save the preferences.