.
Home About-us Privacy Policy Contact-us Services

Showing posts with label Java Examples. Show all posts
Showing posts with label Java Examples. Show all posts

Wednesday, March 22, 2017

Java - Static Method Program Example - Allprogramexample

By With No comments:
Static Program Example in Java
 class stm
{
static int i=10;       
static void add(int a,int b)      //static method
{
System.out.println("sum is "+(a+b));
}}
class static1
{
public static void main(String aa[])
{
stm.add(30,51);                        //calling static method
int i=stm.i;                             //accessing the the vaiable
System.out.println("sum is "+i);
}
}


Read More

Friday, October 23, 2015

Java - Method Overriding Program Example - Allprogramexample

By With No comments:
Method Overriding Program
class person
{
String name="Allprogramexample";
int age =23;
void result()
{
System.out.println("name is"+name+"age is"+age);
}}
class student extends person
{
int marks=1800;
void result()                      //method overrading
{
System.out.println("name is"+name+"age is"+age+"marks is "+marks);
}}
public class mov
{
public static void main(String aa[])
{
student obj1=new student();
obj1.result();
}}


Read More

Java - if else Program Example - Allprogramexample

By With No comments:
If else Program in Java
class ie
{
public static void main (String aa[])
{
int a=20;
{
if(a>100)
System.out.print("a is grater then");
else
{
System.out.print("a is Lesser then");
}
}
}
}


Read More

Saturday, October 17, 2015

Java - For loop Program Example - Allprogramexample

By With No comments:
For Loop Program
class for1
{
public static void main(String aa[])
{
 for(int i=0 ; i < 5 ; i++)
{
System.out.println("i is : " + i);
 }
}}


Read More

Java - Do While Program Example - Allprogramexample

By With No comments:
Do while Program Example
class dow1
{
public static void main(String aa[])
{
int a=0;
do
{
System.out.println("Result is "+a);
a++;
}
while(a<10);
}}



 
Read More

Friday, October 16, 2015

Java - while program example - Allprogramexample

By With No comments:
While program example
class wl
{
public static void main(String aa[])
{
int a=1;
while(a<=10)
{
System.out.print("REsult is "+a);
a++;
System.out.print("\n");
}
}
}


Read More

Java - Cube program Example - Allprogramexample

By With No comments:
Cube Program Example
class cube
{
int len;
int width;
int hei;
int volum()   //Method Definaton
{
return(len*width*hei);       
}
}
class cube2
{
public static void main(String aa[])
{
cube cc=new cube();
cc.len=60;
cc.width=20;
cc.hei=10;
int vol=cc.volum();  //Calling a method
System.out.println("The Volum of cube "+vol);
}}


Read More

Java - Constructor Program Example - Allprogramexample

By With No comments:
Constructor Program Example
class cube
{
int lenth;
int width;
int height;
cube()         //Constructor initilize
{
lenth=10;
width=20;
height=2;
}
int volume()
{
return(lenth*width*height);
}
}
class cons
{
public static void main(String aa[])
{
cube cc1=new cube();

int a=cc1.volume();
System.out.println("the volum of "+a);
}}



Read More

Java - Array Program Example - Allprogramexample

By With No comments:
Array Program Example - 
class array1
{
public static void main(String arg[])
{
int ar[][]={{3,5,7},{4,7,2}};
int n=ar.length;
System.out.println("The list of elements are");
for(int i=0;i<n;i++)
for (int j=0;j<n;j++)
System.out.println(ar[i][j]);
}
}

 
Read More

Java - Add the Two Number Program Example - Allprogramexample

By With No comments:
Add the Two Number Program
class add1
{
public static void main(String args[])
{
System.out.println("Addtion of two numbers");
int a=10;
int b=15;
int c=a+b;
System.out.println("result is "+c);
}


Output - 
25

 
Read More

Java - String Function Program Example - Allprogramexample

By With No comments:
String Function Example
class stringfun
{
public static void main(String[] args)
{
String s="cjsoftech";
String s2="iitsdpatiala";
String s3=s2.substring(2,5);
String s4=s.concat(s2);
int i;
int j;
System.out.println("hello "+s);
System.out.println("length of s "+s.length());
System.out.println("s2.subString(2,5) "+s3);
System.out.println("s2.charAt(2) "+s2.charAt(2));
i=s.compareTo(s2);
System.out.println("s.compareTo(s2) "+i);
System.out.println("concate  "+s4);
j=s.indexOf('o');
System.out.println("index of o "+j);
String s5=s.replace('s','S');
System.out.println("after replace "+s5);
String s6=s.toUpperCase();
System.out.println("s6 uppercase "+s6);
String s7=s6.toLowerCase();
System.out.println("s6 lowercase "+s7);
int m=123;
String s8=String.valueOf(m);
System.out.println("valueof "+s8);
}
}






Read More

Java - Final class program example - Allprogramexample

By With No comments:
final class rect
{
public void input1()
{
System.out.println("rect");
}
}

class box extends rect
{
public void input2()
    {
System.out.println("box");
}
}

class test
{
public static void main(String arg[])
{
box x=new box();
x.input1();
x.input2();
  }
  }




Read More

Java - factorial number example - Allprogramexample

By With No comments:
Factorial number example
class  fact
{
public static void main(String r[] )
{
int i=1,m=1,n;
n=Integer.parseInt(r[0]);
do
{
 m=m*i;
 i++;
}
while (i<=n);
System.out.println("Fact of "+n+"is ="+m);
}
}


Read More

Java - Bitwise Operator Example - Allprogramexample

By With No comments:
Bitwise Operator Example
class bitwise
{
 public static void main(String args[])
 {
  int a=22,b=10,and,or,comp,xor,rs,ls;
and=a&b;
or=a|b;
comp=~a;
xor=a^b;
rs=a<<2;
ls=a>>2;
System.out.println("and "+and);
System.out.println("or "+or);
System.out.println("comp "+comp);
System.out.println("xor "+xor);
System.out.println("rs "+rs);
System.out.println("ls "+ls);
}
}

Read More

In Java - Arithmatic Operator Example

By With No comments:
Arithmatic  Operator Example

class oper1
{
public static void main (String aa[])
{
int a=20;
int b=a*2;
int c=b-30;
int d=c/2;
System.out.println("Result of a is"+a);
System.out.println("Result of a is"+b);
System.out.println("Result of a is"+c);
System.out.println("Result of a is"+d);
}}

Output -
Result of a = 20
Result of b = 40
Result of c = 10
Result of d =5


Read More

java Hello world program example

By With No comments:
Helloo World Java program example

class helloo
{
public static void main(String arg[])
{
sytem.out.println("helloo java program ");
}
}

you can save this program in your computer drive with the extension of .java like helloo.java and compile with javac helloo.java when it compile and error free then you can run with simple java helloo.


Read More
Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates