100 Java Programs by TechnoLamror
100 Java Programs by TechnoLamror
Java Programs
Designed By : Rajendra Lamror
Contents
Java Programs.............................................................................................................................................................................. 1
1.
2.
3.
4.
5.
rd
6.
7.
8.
9.
rd
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
www.TechnoLamror.com
Technolamror
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
How to convert all char in string lower case in java Program ......................................................................... 26
42.
43.
44.
45.
Difference between Static and Instance method working in java Program ................................................. 28
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
www.TechnoLamror.com
Technolamror
67.
68.
69.
70.
71.
How to read data from text file using java program .......................................................................................... 40
72.
73.
How to get IP address from site URL using java program ................................................................................ 41
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
x = x + y;
y = x - y;
x = x - y;
System.out.println("After Swapping\nx = "+x+"\ny = "+y);
}
}
www.TechnoLamror.com
Technolamror
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
else if
grade
else if
grade
else
grade
www.TechnoLamror.com
Technolamror
if ( n < 0 )
System.out.println("Number should be non-negative.");
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact*c;
System.out.println("Factorial of "+n+" is = "+fact);
}
}
}
//Calculate factorial
import java.util.Scanner;
import java.math.BigInteger;
for large No
class BigFactorial
{
public static void main(String args[])
{
int n, c;
BigInteger inc = new BigInteger("1");
BigInteger fact = new BigInteger("1");
Scanner input = new Scanner(System.in);
System.out.println("Input an integer");
n = input.nextInt();
for (c = 1; c <= n; c++) {
fact = fact.multiply(inc);
inc = inc.add(BigInteger.ONE);
}
System.out.println(n + "! = " + fact);
}
}
www.TechnoLamror.com
Technolamror
System.out.println("Enter the second string");
s2 = in.nextLine();
if ( s1.compareTo(s2) > 0 )
System.out.println("First string is greater than second.");
else if ( s1.compareTo(s2) < 0 )
System.out.println("First string is smaller than second.");
else
System.out.println("Both strings are equal.");
}
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
//For String
class EnhancedForLoop {
public static void main(String[] args) {
String languages[] = { "C", "C++", "Java", "Python", "Ruby"};
for (String sample: languages) {
System.out.println(sample);
}
}
}
www.TechnoLamror.com
Technolamror
System.out.println("Enter range of numbers to print their multiplication
table");
Scanner in = new Scanner(System.in);
a = in.nextInt();
b = in.nextInt();
for (c = a; c <= b; c++) {
System.out.println("Multiplication table of "+c);
for (d = 1; d <= 10; d++) {
System.out.println(c+"*"+d+" = "+(c*d));
}
}
}
}
www.TechnoLamror.com
Technolamror
status = 1;
num++;
}
}
}
www.TechnoLamror.com
Technolamror
}
}
www.TechnoLamror.com
Technolamror
System.out.println("Substrings of \""+string+"\" are :-");
for( c = 0 ; c < length ; c++ )
{
for( i = 1 ; i <= length - c ; i++ )
{
sub = string.substring(c, c+i);
System.out.println(sub);
}
}
}
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
if (i == middle + 1) {
System.out.println("Palindrome");
}
else {
System.out.println("Not a palindrome");
}
}
}
www.TechnoLamror.com
Technolamror
}
}
}
www.TechnoLamror.com
Technolamror
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
System.out.println("Product of entered matrices:-");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
System.out.print(multiply[c][d]+"\t");
System.out.print("\n");
}
}
}
}
www.TechnoLamror.com
Technolamror
System.out.println("Transpose of entered matrix:-");
for ( c = 0 ; c < n ; c++ )
{
for ( d = 0 ; d < m ; d++ )
System.out.print(transpose[c][d]+"\t");
System.out.print("\n");
}
}
}
www.TechnoLamror.com
Technolamror
//passing substring with from index
int index3=s1.indexOf("is",4);//returns the index of is substring after 4th index
System.out.println(index3);//5 i.e. the index of another is
//passing char value
int index4=s1.indexOf('s');//returns the index of s char value
System.out.println(index4);//3
}}
class StringLowerExample{
static void main(String args[]){
s1="TECHNOLAMROR by Rajendralamror HELLO stRIng";
s1lower=s1.toLowerCase();
www.TechnoLamror.com
Technolamror
System.out.println(s1lower);
}}
www.TechnoLamror.com
Technolamror
n = s.length();
System.out.println("Number of characters = " + n);
// Replace characters in string
t = s.replace("Java", "C++");
System.out.println(s);
System.out.println(t);
// Concatenating string with another string
u = s.concat(" is fun");
System.out.println(s);
System.out.println(u);
}
}
www.TechnoLamror.com
Technolamror
Difference t = new Difference();
t.show(); //calling using object
}
static void display() {
System.out.println("Programming is amazing.");
}
void show(){
System.out.println("Java is awesome.");
}
}
www.TechnoLamror.com
Technolamror
public static void main(String[] args) {
Programming object = new Programming(); //creating object
}
}
www.TechnoLamror.com
Technolamror
a = input.nextInt();
b = input.nextInt();
// try block
try {
result = a / b;
System.out.println("Result = " + result);
}
// catch block
catch (ArithmeticException e) {
System.out.println("Exception caught: Division by zero.");
}
}
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
System.out.println("Current date is
System.out.println("Current time is
"+day+"/"+(month+1)+"/"+year);
"+hour+" : "+minute+" : "+second);
}
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
}
if (c == n) /* Searching element is absent */
System.out.println(search + " is not present in array.");
}
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracl
e");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
//step5 close the connection object
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
www.TechnoLamror.com
Technolamror
ps.setString(1,"Technolamror");
FileInputStream fin=new FileInputStream("d:\\g.jpg");
ps.setBinaryStream(2,fin,fin.available());
int i=ps.executeUpdate();
System.out.println(i+" records affected");
con.close();
}catch (Exception e) {e.printStackTrace();}
}
}
www.TechnoLamror.com
Technolamror
public static void main(String args[]){
Multi t1=new Multi();
t1.start();
}
}
www.TechnoLamror.com
Technolamror
public static void main(String args[]){
try{
FileInputStream fin=new FileInputStream("D:\\Technolamror.txt");
int i=fin.read();
System.out.print((char)i);
fin.close();
}catch(Exception e){System.out.println(e);}
}
}
www.TechnoLamror.com
Technolamror
add(b);//adding button into frame
setSize(300,300);//frame size 300 width and 300 height
setLayout(null);//no layout manager
setVisible(true);//now frame will be visible, by default not visible
}
public static void main(String args[]){
First f=new First();
}}
www.TechnoLamror.com
Technolamror
Frame f= new Frame();
Choice c=new Choice();
c.setBounds(100,100, 75,75);
c.add("Item 1 by Rajendra");
c.add("Item 2 by Lamror");
c.add("Item 3 by Technolamror");
c.add("Item 4");
c.add("Item 5");
f.add(c);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new ChoiceExample();
}
}
www.TechnoLamror.com
Technolamror
{
new CheckBoxExample();
}}
www.TechnoLamror.com
Technolamror
String s="23.6";
double d=Double.parseDouble("23.6");
System.out.println(d);
}}
www.TechnoLamror.com
Technolamror
//Traversing list through Iterator
Iterator itr=list.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
}
www.TechnoLamror.com
Technolamror
list.add(b1);
list.add(b2);
list.add(b3);
System.out.println("Original content of list is: ");
//Traversing list
for(Book b:list){
System.out.println(b.id+" "+b.name+" "+b.author+" "+b.publisher+" "+b.quantity);
}
ListIterator<Book> itr=list.listIterator();
System.out.println("Modified content of list in backward is: ");
while(itr.hasNext()){
Book st=(Book)itr.next();
System.out.println(st.quantity+" "+st.publisher+" "+st.author+" "+st.name+"
"+st.id);
}
}
}
www.TechnoLamror.com
Technolamror
}
}
}
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
www.TechnoLamror.com
Technolamror
}}
100.
How to create Method Overriding
program in java
class Bank{
int getRateOfInterest(){return 0;}
}
class SBI extends Bank{
int getRateOfInterest(){return 8;}
}
class ICICI extends Bank{
int getRateOfInterest(){return 7;}
}
class AXIS extends Bank{
int getRateOfInterest(){return 9;}
}
class Test2{
public static void main(String args[]){
SBI s=new SBI();
ICICI i=new ICICI();
AXIS a=new AXIS();
System.out.println("SBI Rate of Interest: "+s.getRateOfInterest());
System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest());
System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest());
} }
www.TechnoLamror.com
Technolamror
Thank You
For
Reading
Give Your FeedBack
If You Required Other PDF
Submit Your Request Here
Rajendra lamror
www.TechnoLamror.com