Saturday, 8 August 2015

WHERE TO DOWNLOAD JAVA

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html


you can go through this site to download java programme.

Friday, 24 July 2015

If there is any problem in java. you can email it at kmpiyush89@gmail.com


LABELS, BUTTONS, CHECKBOXES, TEXTFIELDS

Theory behind forming the LABELS, BUTTONS, CHECKBOXES, TEXTFIELD.
1) Labels
      A) label() - create an empty label.
        B) label(String) - create a label with the given string.
2) Buttons
      A) Button() - Create a button without any name.
        B) Button(String) - Create a button with the given desired name.
3) Checkboxes
      A) Checkbox() - Create a checkbox without any label.
        B) Checkbox(String) - Create a labeled checkbox.
4) Text Areas:
      A) TextArea() - Creates a blank textField.
        B) TextArea(rows,character) - Creates a text area of rows with certain numbers of character. 

SIMPLE THEORY ON COMPONENETS OF AWT.

The statement import java.awt.*; imports all the componenets,containers and layout managers for designing the user interface.
The AWT supplies necessary following components.
1) Labels (java.awt.Label)
2) Buttons (java.awt.Checkbox)
3) Checkboxes (java.awt.checkbox)
4) Single-line text field (java.awt.TextField)
5) Larger text display and editing areas (java.awt.TextAreas)
6) Lists (java.awt.list)
7) Sliders and scrollbars (java.awt.Scrollbar)
8) Drawing areas ( java.awt.Canvas)

SIMPLE PATH WAY TO WRITE AN APPLET

              HOW TO WRITE AN APPLET PROGRAMME
import java.awt.*;
import java.applet.*;
//<applet code="Appletprogramme" height="500" width="500"></applet>
publi class Appletprogramme extends Applet
{
// Called first;
public void init() {
// initialization
}
/* Called second; after init(); Also called whenever
the applet is restarted. */
public void start() {
// start or resume execution
}
// Called when the applet is stopped.

SIMPLE THEORY ON APPLET.

1)Applet: An applet is a java program that can be embedde in a web page. Java application are run by using a java interpreter. Applet are run on any browser that
   supports java Applets can also be tested using the appletviewer tool included in java development kit.

2)To run an applet it must be included in a web page, using HTML tags.

3)All applets sre subclasses of the Applet class in the java.applet package.

4)Applets do not contain void main() method.

5)Applets must be declared public: ex: (public class FileName extends Applet).

6)Applet display informations on the screen by using paint method. For example: public class paint(Graphic g).

7)To view an Appletviewer there must be written an Applet code. Applet code basically controls the dimensions of the viewer.  
                                                         For example: //<appletcode="File name" height="500" width="500"></applet>
                                                                                 ( // This means not to print in java)

8)The applet runs in a web page that is loaded in a web browser. But one thing must be reminded In your browser PLUGIN is must be installed.

9)The enviroment of the applet is known as the context of the applet.

10)The cycle of an Applet:
         A)The init() method: Basically it is called the first time an applet is loaded into the memory of the computer.
            B)The start() method: It comes immediately after the init() process. And can use this method when you want to restart a process.
               C)The stop() method: you can use this method to reset variables.
                  D)The destroy() method: you can use this method to perform clean-up operations like closing a file.


Thursday, 23 July 2015

SIMPLE WAY TO CREATE A CLASS FILE.

CLASS

PUBLIC CLASS CLASSNAME
{
//MEMBER DATA
//MEMBERFUNCTION
}

PUBLIC CLASS ABC
{
INT X=8;
PUBLIC VOID DISP()
{
sYSTEM.OUT.PRINTLN("X"+X)
}
}

SIMPLE PROGRAMME TO MAKE CALCULATOR ADDITION APPLICATION THROUGH FORM USING WINDOWS ACTION LISTNER.

programme:- to make calculator addition application through form using windows action listner.




import java.awt.*;
import java.awt.event.*;
public class calci extends Frame implements ActionListener
{
TextField t1,t2,t3;
public static void main(String args[])
{
calci t = new calci();
}
public calci()
{
super("Event in Java awt");
setLayout(new BorderLayout());
try
{
t1=new TextField();
t2=new TextField();
add(t1, BorderLayout.NORTH);
add(t2, BorderLayout.CENTER);
Button button1 = new Button("add");
button1.addActionListener(this);
add(button1, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
}
catch (Exception e){}
setSize(400,400);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Button button1 = (Button)e.getSource();
t2.setText(Integer.toString(Integer.parseInt(t1.getText())+Integer.parseInt(t2.getText())));
}
}


Save it by calci.java
Run it on cmd
1) javac calci.java
2) java calci

Wednesday, 22 July 2015

SIMPLE PROGRAMME TO GIVE NUMBERS TO ARRAY AND SUM OF ALL OF IT.

programme: To input five numbers in array and add all of it.




import java.util.*;
public class testarray
{
public static void main(String args[])
{
int x[];
x=new int[5];
int i,temp=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter the five number");
for(i=0;i<5;i++)
{
x[i]=sc.nextInt();
}
System.out.println("value in array");
for(i=0;i<5;i++)
{
System.out.println(x[i]);
temp=temp+x[i];
}
System.out.println("temp="+(temp));
}
}


In this programme we further a temporary file called temp for adding all the array numbers

To run it:
save it by testarray.java
1) javac testarray.java
2) java testarray
then give 5 numbers and we got array numbers and sum.
                                                                                                            MENTOR: ANIL KUMAR

SIMPLE PROGRAMME TO FIND THE TABLE OF NUMBERS TAKEN BY USERS

programme:- To find out the table of the numbers taken by users.



import java.util.*;
public class table
{
public static void main(String args[])
{
int x,z,i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of x");
x=sc.nextInt();
for(i=1;i<=10;i++)
{
z=i*x;
System.out.println(""+(z));
}
}
}
                                                                                                            MENTOR:ANIL KUMAR
if you need any explanation or any programme or any problem you faced. You can email me at
kmpiyush89@gmail.com

SIMPLE PROGRAMME TO KNOW HOW TO ASSIGN THE VALUE IN VARIABLES OF CLASS FILE.

programme: use of constructor by assigning the value of x in class file and we recall it in another programme.

class file:

public class cons
{
int x;
cons()
{
x=500;
}
void disp()
{
System.out.println(" value of x "+x);
}
}


we assign the value of x now when we recall the value of x it will show 500.

another programme to recall the value of x:

public class cons1
{
public static void main(String args[])
{
cons c=new cons();
c.disp();
}
}

Tuesday, 21 July 2015

Guys you please comment on my post. so that i can judge that my post is beneficial for you or not. you can also send me any suggestion regarding post.

SIMPLE PROGRAMME TO KNOW HOW TO USE THE CONCEPT OF ARRAY.

programme:- to view the numbers in the array
34324




public class array1
{
public static void main(String args[])
{
int x[]={3,4,3,2,4};
int i;
for(i=0;i<5;i++)
{
System.out.print(x[i]);
}
System.out.println();
}
}

SIMPLE PROGRAMME TO SHOW THE USE OF INHERIT AND USE OF EXTENDS.

programme:- use of inherit and use of extends..


class test
{
int x;
void prints()
{
System.out.println(x*x);
}
void sum()
{
System.out.println(x+x);
}
}
public class xyz extends test
{
int y;
xyz()
{
x=5;
}
void fromchild()
{
System.out.println("hello from child class");
}
public static void main(String args[])
{
xyz b=new xyz();
b.prints();
b.sum();
b.fromchild();
}
}


In this programme you will see that the class file is extended and how class and recall file is combined so there is no use of making another recall file.

Monday, 20 July 2015

SIMPLE PROGRAMME TO BULIT A CALCULATOR APPLICATION.

programme:- to build a claculator application that sum,multiply,divide,subtract.


import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
//<applet code="calci2" height="300" width="300"></applet>
public class calci2 extends Applet implements ActionListener
{
Label l1=new Label("enter 1st number");
TextField t1=new TextField(20);
Label l2=new Label("enter 2nd number");
TextField t2=new TextField(20);
Label l3=new Label("Result");
TextField t3=new TextField(20);
Button b1=new Button("Sum");
Button b2=new Button("Subtract");
Button b3=new Button("Multiply");
Button b4=new Button("Division");
{
Component add1=add(l1);
Component add2=add(t1);
Component add3=add(l2);
Component add4=add(t2);
Component add5=add(l3);
Component add6=add(t3);
Component add7=add(b1);
Component add8=add(b2);
Component add9=add(b3);
Component add10=add(b4);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
//public void init()
//{
//setBackground(Color.YELLOW);
//}
public void actionPerformed(ActionEvent e)
{
int s1,s2,s3,s4,s5,s6;
if(e.getSource()==b1)
{
s1=Integer.parseInt(t1.getText());
s2=Integer.parseInt(t2.getText());
s3=s1+s2;
t3.setText(Integer.toString(s3));
setBackground(Color.YELLOW);
}
if(e.getSource()==b2)
{
s1=Integer.parseInt(t1.getText());
s2=Integer.parseInt(t2.getText());
s4=s1-s2;
t3.setText(Integer.toString(s4));
}
if(e.getSource()==b3)
{
s1=Integer.parseInt(t1.getText());
s2=Integer.parseInt(t2.getText());
s5=s1*s2;
t3.setText(Integer.toString(s5));
}
if(e.getSource()==b4)
{
s1=Integer.parseInt(t1.getText());
s2=Integer.parseInt(t2.getText());
s6=s1/s2;
t3.setText(Integer.toString(s6));
}
}
}


Run it by saving by calci2.java

1) javac calci2.java
2) appletviewer calci2.java

SIMPLE PROGRAMME TO CREATE AN APPLET VIEWER LIKE A CALCULATOR HAVING LABELS,TEXTFIELDS,BUTTONS.

programme:-simple method to create labels and textfield and buttons simply like calculator


import java.awt.*;
import java.applet.*;
//<applet code="calci" height="300" width="300"></applet>
public class calci extends Applet
{
Label l1=new Label("calculator",Label.CENTER);
Label l2=new Label("enter 1st no.");
TextField t1=new TextField(10);
Label l3=new Label("enter a 2nd no.");
TextField t2=new TextField(10);
Label l4=new Label("result");
TextField t3=new TextField(10);
Button b1=new Button("Sum");
Button b2=new Button("subtract");
Button b3=new Button("multiply");
public void init()
{
add(l1);
add(l2);
add(t1);
add(l3);
add(t2);
add(l4);
add(t3);
add(b1);
add(b2);
add(b3);
}
}

Run this by saving calci.java
1) javac calci.java
2) appletviewer calci.java

SIMPLE METHOD TO VIEW THE CARTOON OR ANY THING DRAWN THROUGH APPLET ON WEB PAGE.

programme:- To view the drawn thing made through an applet on web page.

We have to only add the applet code in the html programme of that applet cartoon that we want to view on web page like this

<html>
<head>
<title>my first web page</title>
</head>
<body bgcolor="aqua">
<h1>hello in my first web page</h1>
<div >
<APPLET CODE="Main.class" WIDTH="800" HEIGHT="500">
</APPLET>
</body>
</html>


First of all write a simple html programme as i described earlier how to write a simple html programme and then only add the Applet code of that programme which you want to view on web page inbetween the html programme like above.Run it with google chrome and internet explorer

But make sure that plugin is must be supported on your browser.

SIMPLE PROGRAMME TO SAVE A CLASS FILE IN A PACKAGE AND USE IT TO RECALL THAT CLASS FILE.

programme: To save the class file in a package and to recall it in another programme


package abc2;
import java.util.*;
public class basicsalary
{
int bs,ta,da,hra,pf,netpay,total;
public void getdata()
{
System.out.println("enter the bs");
Scanner sc=new Scanner(System.in);
bs=sc.nextInt();
}
public void tadata()
{
ta=bs*5/100;
System.out.println("value of ta"+(ta));
}
public void dadata()
{
da=bs*10/100;
System.out.println("value of da"+(da));
}
public void hradata()
{
hra=bs*12/100;
System.out.println("value of hra"+(hra));
}
public void pfdata()
{
pf=bs*13/100;
System.out.println("value of pf"+(pf));
}
public void totaldata()
{
total=bs+ta+da+hra;
System.out.println("total"+(total));
}
public void netpaydata()
{
netpay=total-pf;
System.out.println("netpay"+(netpay));
}
}
 

save it by basicsalary.java
Run it by
1) javac basicsalary.java
2) javac -d . basicsalary.java


Now recall it in another programme;

import abc2.basicsalary;
public class salary
{
public static void main(String args[])
{
basicsalary b=new basicsalary();
b.getdata();
b.tadata();
b.dadata();
b.hradata();
b.pfdata();
b.totaldata();
b.netpaydata();
}
}

Run this programme;
1) javac salary.java
2) java salary

SIMPLE PROGRAMME TO CREATE A PACKAGE AND TO RECALL IT IN A PROGRAMME.

programme:-to create a package and save all class file in it and to recall it in using other file.
First of  all write a programme like this or what you want only write a (package name;)
on top

package abc2;
public class simple
{
int x;
//simple()
{
x=45;
}
public void disp()
{
System.out.println("value of x"+(x));
}
}

save it by simple.java
open CMD
1) javac simple.java             (press enter)
2) javac -d . simple.java             (press enter)

A class file is created along with a folder name abc2,,
now how to recall simple class file form package abc2,
let see,

import abc2.simple;
public class notepad
{
public static void main(String args[])
{
simple s=new simple();
s.disp();
}
}

to recall class file in package only write (import package name.class file name;)

SIMPLE PROGRAMME TO USE CONSTRUCTION OVERLOADING TO USE IT IN CLASS FILE AND RECALL IT IN OTHER.

programme:- to use construction overloading to create a class file and recall it in another file.


public class overloading
{
double t;
overloading(double f1,double f2)
{
t=(f1+f2);
}
overloading(double f1)
{
t=(f1+f1);
}
void disp()
{
System.out.println("display t="+(t));
}
}

we use 'double' instead of 'float'
save it by overloading.java
1) javac overloading.java

recall programme:



public class over
{
public static void main(String args[])
{
overloading o=new overloading(3.4,5.6);
o.disp();
overloading o1=new overloading(5.6);
o1.disp();
}
}


save it by over.java
1) javac over.java
2) java over

Sunday, 19 July 2015

SIMPLE PROGRAMME TO DRAW A APPLICATION FORM AND LABELS AND TEXTFIELD AND BUTTONS.

programme:- To draw a form (Application form) like Labels and TextFields and Buttons


import java.awt.*;
import java.applet.*;
//<applet code="applicationform" height="900" width="500"></applet>
public class applicationform extends Applet
{
Label l1=new Label("application form",Label.CENTER);
Label l2=new Label("Name");
TextField t1=new TextField(10);
Label l3=new Label("Father's name");
TextField t2=new TextField(10);
Label l4=new Label("Mother's name");
TextField t3=new TextField(10);
Label l5=new Label("mobile no.");
TextField t4=new TextField(10);
Label l6=new Label("Address");
TextField t5=new TextField(10);
Button b1=new Button("Save");
Button b2=new Button("Submit");
Button b3=new Button("Send");
public void init()
{
add(l1);
add(l2);
add(t1);
add(l3);
add(t2);
add(l4);
add(t3);
add(l5);
add(t4);
add(l6);
add(t5);
add(b1);
add(b2);
add(b3);
}
}



Run this programme;-
1) javac applicationform.java
2) appletviewer applicationform.java

SIMPLE METHODS THAT SHOULD BE CARE FOR WRITING APPLET PROGRAMME.

Important things that should must be noted when writing a programme for creating a applet programmes.

1)import java.awt.*;
2)import java.applet.*;
3)//<applet code="stairs" height="500" width="500"></applet>
This applet code is must to be written it basically delivers the applet bar. and all Game of drawing cartoon depends upon Co-ordinates System.
In this co-ordinate System (0,0) starts from top left hand side and from that horizontal is x axis and verticall downward line is y axis.
you can change file name and height and width of the applet bar
4)public class stairs extends Applet (here Applet is case sensitive so Take care of that).
5)g.drawString("welcome to the cartoon world",80,20);
Here in the string you can write the head topic of your file for examples:Welcome to the cartoon World. At any co-ordinates you want.

SIMPLE PROGRAMME TO DRAW THE BLOCK UPLOADING DIAGRAM IN APPLET VIEWER.

programme: to draw the block uploading diagram in applet viewer


import java.awt.*;
import java.applet.*;
//<applet code="stairs" height="500" width="500"></applet>
public class stairs extends Applet
{
 public void paint(Graphics g)
{
g.drawString("welcome to the cartoon world",80,20);
g.drawRect(100,100,250,100);
g.setColor(Color.blue);
g.fillRect(100,100,250,100);
g.drawRect(125,200,200,100);
g.setColor(Color.yellow);
g.fillRect(125,200,200,100);
g.drawRect(150,300,150,100);
g.setColor(Color.red);
g.fillRect(150,300,150,100);
g.drawRect(105,200,10,200);
g.setColor(Color.cyan);
g.fillRect(105,200,10,200);
g.drawRect(335,200,10,200);
g.setColor(Color.cyan);
g.fillRect(335,200,10,200);
}
}



Run this programme
1) javac stairs.java
2) appletviewer stairs.java

SIMPLE PROGRAMME TO DRAW A CARTOON MAN IN APPLET VIEWER.

programme:- To make this upper shown cartoon in applet viewer.

import java.awt.*;
import java.applet.*;
//<applet code="cartoon1" height="500" width="500"></applet>
public class cartoon1 extends Applet
{
public void paint(Graphics g)
{
g.drawString("welcome to applet cartoon man",80,20);
g.drawOval(150,50,90,90);
g.setColor(Color.blue);
g.fillOval(150,50,90,90);
g.drawRect(120,140,150,200);
g.setColor(Color.red);
g.fillRect(120,140,150,200);
g.drawRect(120,340,50,100);
g.setColor(Color.cyan);
g.fillRect(120,340,50,100);
g.drawRect(220,340,50,100);
g.setColor(Color.cyan);
g.fillRect(220,340,50,100);
}
}



Run this programme:
1) javac cartoon1.java
2) appletviewer cartoon1.java


SOME GRAPHIC PROGRAMME THAT YOU CAN USED IN DRAWING CARTOONS.

programme:- some graphic programme that you can used in drawing cartoons.
All are case sensitive so write as written below

g.drawString("String text", int x, int y)
g.drawLine(int x1,int y1,int x2,int y2)
g.drawRect(int x1,int y1,int width, int height)
g.setColor(Color.CYAN)
g.fillRect(int x1,int y1,int width, int height)
g.clearRect(int x1, int y1,int width, int height)
g.draw3DRect(int x1,int y1,int width, int height, boolean raised)
g.drawRoundRect(int x1,int y1,int width, int height,int arcWidth, int arcHeight)
g.fillRoundRect(int x1,int y1,int width, int height,int arcWidth, int arcHeight)
g.drawOval(int x1,int y1,int Width,int Height)
g.fillOval(int x1,int y1,int Width,int Height)


You can used by writing

public void paint(Graphic g)

SIMPLE PROGRAMME TO DRAW A OVAL AND FILL THE COLOR IN SHAPE OF OVAL OUTSIDE IT.

programme:- to draw a oval and fill the color in shape of oval outside it in applet.


import java.awt.*;
import java.applet.*;
//<applet code="cartoon" height="300" width="300"></applet>
public class cartoon extends Applet
{
public void paint(Graphics g)
{
g.drawString("welcome to applet cartoon",80,20);
g.drawOval(50,100,100,100);
g.setColor(Color.blue);
g.fillOval(150,100,100,100);
}
}

SIMPLE PROGRAMME TO DRAW A OVAL AND FILL A OVAL IN APPLET.

programme:- To draw a oval and fill color in applet.





import java.awt.*;
import java.applet.*;
//<applet code="cartoon" height="300" width="300"></applet>
public class cartoon extends Applet
{
public void paint(Graphics g)
{
g.drawString("welcome to applet cartoon",80,20);
g.drawOval(100,100,100,100);
g.setColor(Color.blue);
g.fillOval(100,100,100,100);
}
}


To run this programme:-
1) javac cartoon.java
2) appletviewer cartoon.java

SIMPLE PROGRAMME TO DRAW A RECTANGLE IN APPLET AND FILL COLOR.

programme:- To draw rectangle in applet filling with color





import java.awt.*;
import java.applet.*;
//<applet code="cartoon" height="300" width="300"></applet>
public class cartoon extends Applet
{
public void paint(Graphics g)
{
g.drawString("welcome to applet cartoon",80,20);
g.drawRect(100,100,100,100);
g.setColor(Color.blue);
g.fillRect(100,100,100,100);
}
}



to run this programme:-
1) javac cartoon.java
2) appletviewer cartoon.java

SOME IMPORTANT METHOD THAT CAN BE USED IN STRING PROGRAMMES.

programme:-some important method you can used in string

1) s2=s1.toUpperCase;  converts the string s1 to all uppercase.
2) s2=s1.toLowerCase;  converts the string s1 to all lowercase;
3) s2=s1.replace('x' , 'y');  Replace all appearances of x with y
4) s1.equals(s2)   Returns 'true' if s1 is equal to s2
5) s1.length()   Gives the length of s1
6) s1.compareTo(s2)  Returns negative if s1<s2, positive if s1>s2, and zero if s1 is equal s2

Saturday, 18 July 2015

SIMPLE WAY OF WRITING HTML PROGRAMME SO THAT YOU CANNOT FEEL ANY PROBLEM IN APPLET.

Guys those people who do not know how to do work in html. i am giving a small programme so that you can understand how to create it. so that you do not feel problem in APPLET.


<html>
<head>
<title>kumar piyush</title>
</head>
<body bgcolor="yellow">
<h1>This is sci-fi network.do not dare to enter</h1>
</body>
</html>

After writing this in notepad save it by kumarpiyush.html
and you can open with google chrome or Internet explorer.

SIMPLE PROGRAMME TO CHECK THAT THE GIVEN NAME IS PALINDROME OR NOT

programme:- to show that the word we taken from user is palindrome or not


public class string2
{
public static void main(String args[])
{
String s1,s2;
s1=new String(args[0]);
s2=new StringBuffer(s1).reverse().toString();
if(s1.equals(s2))
{
System.out.println("The word is palindrome");
}
else
{
System.out.println("not palindrome");
}
}
}


The word palindrome means that the word is equal from both the ends
ex:MADAM

to use this
1) go to cmd
2) javac string2.java
3) java string MADAM

SIMPLE PROGRAMME TO CONVERT NAME INTO SMALL LETTERS AND COUNT THE NUMBERS OF CHARACTER.

programme:- to take name from input and convert in into small letters and count the no. of character.



public class string
{
public static void main(String args[])
{
String s1;
s1= new String(args[0]);
System.out.println(s1.toLowerCase());
System.out.println(s1.length());
}
}

how to use it:
go to cmd
1) javac string.java
2) java string SHIP

SIMPLE PROGRAMME TO SHOW THE MULTIPLICATION OF TWO MATRICES USING TWO DIMENSIONAL ARRAY.

programme:- to multiply the matrices



public class array5
{
public static void main(String[] args)
{
int x[][]={{3,4},{4,5}};
int y[][]={{1,2},{9,8}};
int i,j;
int z[][]=new int[2][2];
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
z[i][j]=x[i][j]*y[i][j];
System.out.print(z[i][j]);
}
System.out.println();
}
}
}

SIMPLE PROGRAMME TO SHOW THE SUM OF MATRICES USING TWO DIMENSIONAL ARRAY.

programme:- sum of matrices using two dimensional array.





public class array3
{
public static void main(String args[])
{
int x[][]={{4,5},{4,3}};
int y[][]={{5,3},{4,3}};
int i,j;
int z[][]=new int[2][2];
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
z[i][j]=x[i][j]+y[i][j];
System.out.print(z[i][j]);
}
System.out.println();
}
}
}

SIMPLE PROGRAMME TO CHECK WHICH NUMBERS IS GREATEST OF ALL NUMBERS IN THE LIST USING ARRAY.

programme:- to check that which no. is greatest of all no. in the list.




public class array4
{
public static void main(String args[])
{
int a[]={8,10,56,65,3};
int x,i;
x=a[0];
for(i=0;i<5;i++)
{
if(x<a[i])
{
x=a[i];
}
}
System.out.println(x);
}
}

SIMPLE PROGRAMME TO CHECK THAT THE GIVEN NUMBERS IS PRESENT IN THE LIST OR NOT.

programme:- to check that the given numbers is present in the list or not.



import java.util.*;
public class array2
{
public static void main(String args[])
{
int x[]={4,3,5,6,2};
int i,z;
System.out.println("enter the value of z");
Scanner sc=new Scanner(System.in);
z=sc.nextInt();
for(i=0;i<5;i++)
if(x[i]==z)
{
System.out.println("number is present in list");
}
}
}



this programme helps you to find your numbers in large bank of numbers.

SIMPLE PROGRAMME TO DEFINE HOW TO CREATE A CLASS AND HOW TO USE IT IN ANOTHER PROGRAMME.

programme:- programme to create a class



import java.util.*;
public class student
{
int phy,chem,total,perc;
void getdata()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the marks of phy and chem");
phy=sc.nextInt();
chem=sc.nextInt();
}
void totaldata()
{
total=phy+chem;
System.out.println("total"+(total));
}
void percdata()
{
perc=(total)/3;
System.out.println("perc"+(perc));
}
void div()
{
if(perc>=65)
{
System.out.println("first divison");
}
}
}

This is a class programme now how we use this:we use this in other programme
1.)run the class programme in cmd by typing (javac student.java)
then use this class where you want


public class student1
{
public static void main(String args[])
{
student s=new student();
s.getdata();
s.totaldata();
s.percdata();
}
}


save this by student1.java
and run in cmd
1) javac student1.java
2) java student1

SIMPLE PROGRAMME FOR CREATING LOOP 6

programme:-
                               *
                            *    *
                        *     *     *
                     *    *     *     *



public class pyramid5
{
public static void main(String args[])
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
System.out.print(" ");
}
for(k=1;k<=i;k++)
{
System.out.print(" "+"*");
}
System.out.println();
}
}
}

SIMPLE PROGRAMME FOR CREATING LOOP 5

programme:-
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15


public class pyramid5
{
public static void main(String args[])
{
int i,j,z=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(z);
z++;
}
System.out.println();
}
}
}

SIMPLE PROGRAMME TO CREATE LOOP 4

programme:-
*
**
***
****
*****


public class pyramid4
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}


SIMPLE PROGRAMME FOR CREATING LOOP 3

programme:-
11111
2222
333
44
5



public class pyramid2
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
System.out.print(i);
}
System.out.println();
}
}
}

SIMPLE PROGRAMME FOR CREATING LOOP 2

programme:-
54321
5432
543
54
5



public class pyramid1
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
System.out.print(j);
}
System.out.println();
}
}
}



save it by pyramid1.java

SIMPLE PROGRAMME FOR CREATING LOOP 1

programme:-for writing this loop
1
12
123
1234
12345



public class pyramid
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}


save it by pyramid.java

SIMPLE PROGRAMME TO FIND THE FACTORIAL OF A GIVEN NUMBER

programme:-



import java.util.*;
public class fact
{
public static void main(String args[])
{
int i,fa,x;
fa=1;
Scanner sc=new Scanner(System.in);
System.out.println("enter the value of x");
x=sc.nextInt();
for(i=1;i<=x;i++)
{
fa=fa*i;
}
System.out.println("factorial of a given no" +fa);
}
}


save it by fact.java
1)javac fact.java
2)java fact


type on cmd

PROGRAMME TO TAKE THREE SUBJECTS INPUT MARKS AND DISPLAY TOTAL,PERCENTAGE AND DIVISION OF STUDENT.

programme:-write it in notepad.


import java.util.*;
public class marks
{
public static void main(String args[])
{
int phy,chem,math,total,perc,div;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the marks of phy and chem and math");
phy=sc.nextInt();
chem=sc.nextInt();
math=sc.nextInt();
total=(phy+chem+math);
perc=(total/3);
{
System.out.println("Total" +(total));
System.out.println("perc" +(perc));
}
if(perc>=65)
{
System.out.println("Student is first divison");
}
else
{
System.out.println("second division");
}
}
}


save it by marks.java in notepad
1) javac marks.java
2) java marks




PROGRAMME TO CHECK NUMBER IS ODD OR EVEN

programme:-


import java.util.*;
public class evenodd
{
public static void main(String args[])
{
int x;
Scanner sc=new Scanner(System.in);
System.out.println("enter the number");
x=sc.nextInt();
if(x%2==0)
{
System.out.println("The number is even");
}
else
{
System.out.println("odd number");
}
}
}


save it by evenodd.java
1) javac evenodd.java
2) java evenodd

SIMPLE PROGRAMME FOR SUM OF TWO NUMBERS TAKING INPUT FROM USER.

programme:-write it in notepad


import java.util.*;
public class sum
{
public static void main(String args[])
{
int x,y,z;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of x and y");
x=sc.nextInt();
y=sc.nextInt();
z=x+y;
{
System.out.println("sum"+(z));
}
}
}


To run this first save it by sum.java
1) javac sum.java                   (press enter)
2) java sum                        (press enter)


Type this lines 1 and 2 in cmd

Friday, 17 July 2015

SIMPLE PROGRAMME TO SUM TO KNOWN NUMBERS.

programme sum:-write it in notepad


public class sum
{
public static void main(String args[])
{
int x,y,z;
x=5;y=10;
z=x+y;
{
System.out.println("sum"+(z));
}
}
}


To run this programme:-
1) Save it by sum.java
2) javac sum.java                 (press enter)
3) java sum           (press enter)

SIMPLE PROGRAMME TO PRINT HELLO JAVA ON JDK(CMD) FOR BEGINEERS

programme:-write it in notepad

public class abc
{
public static void main(String args[])
{
System.out.println("Hello java");
}
}


To run this programme save it by abc.java
1.open cmd.
2.type as according to me
 a) cd\        (enter)
 b) cd foldername(where you save your batch file)      (enter)
 c) batch file name      (enter)
 d) javac abc.java
 e) java abc

HOW TO CREATE A PATH(BATCH) FILE FOR RUNNING JAVA PROGRAMME.

To run java programme you have to create a batch file;

How to create it:-
1. Go to java file where you installed it.
2. Then go to jdk1.8.0_45 file.
3. Then Right click on bin file and open properties and copy the file location.
4. Open notepad and paste it.
5. Then write path ahead of it and \bin at last of the paste item.
for example:-path C:\Program Files (x86)\Java\jdk1.8.0_45\bin
6. Then save it by giving .bat file ex:name.bat and save it in the folder that you create in the c drive.
7. Save all the programme in that folder where you save batch file.