Project Report Core Java: Under The Guidance: Mr. Arvind Kalyan
Project Report Core Java: Under The Guidance: Mr. Arvind Kalyan
Branch: CSE-C
ACKNOWLEDGEMENT
Firstly, I would like to thank my project guide MR. ARVIND , who has
been a constant source of inspiration for me during the completion of
this project.
INDEX
CORE-JAVA
Introduction to Java:
Java used:
1. JSP: Used to create web applications like PHP, JSP(Java Server Pages
) used with normal HTML tags to create dynamic web pages.
2. Applets: Another type of Java program. Used to add features to
Web Browser.
3. J2EE(Java 2 Enterprise Edition):Used to transfer data based on XML
documents between one another.
4. Java Beans: It is reusable software component. Easily assemble to
create a new and advance application.
5. Mobile: Games and services build in java. All Nokia , Vodaphone
using Java technology.
1. Object oriented.
2. Platform independent.
3. Simple and Secure.
4. Architectural neutral.
5. Portable.
6. Robust in nature.
7. Multi-threaded.
8. Interpreted java code into machine language.
9. High performance.
class IfExample
{
public static void main(String[]args)
{
int age=20;
if(age>18)
{
System.out.println("age is greater than 18");
}}}
Output:
class IfelseExample
{
public static void main(String[]args)
{
int a=13;
if(a%2==0)
{
System.out.println("even number");
}
else
{
System.out.println("odd number");
}}}
Output:
class IfelseifExample
{
public static void main(String[]args)
{
int marks=97;
if(marks<50)
{
System.out.println("fail");
}
else if(marks>=50&&marks<60)
{
System.out.println("D grade");
}
else if(marks>=60&&marks<70)
{
System.out.println("C grade");
}
else if(marks>=70&&marks<80)
{
System.out.println("B grade");
}
else if(marks>=80&&marks<90)
{
System.out.println("A grade");
}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
else if(marks>=90&&marks<100)
{
System.out.println("A++ grade");
}
else
{
System.out.println("Invalid");
}}}
Output:
class SwitchExample
{
public static void main(String[]args)
{int number=20;
switch(number)
{
case 10:System.out.println("10");
break;
case 20:System.out.println("20");
break;
case 30:System.out.println("30");
break;
default:System.out.println("not in 10,20,30");
}}}
Output:
1. FOR LOOP : The For loop has all it’s loop-control elements are
gathered in one place, means the initialization, condition and
increment or decrement are in one place.
class ForExample
{
public static void main(String[]args)
{
for(int i=1;i<=10;i++)
{
System.out.println(i);
}}}
Output:
class ForeachExample
{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
int arr[]={12,23,34,45,56,67,78,89};
for(int i:arr)
System.out.println(i);
}}}
Output:
class DowhileExample
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
int i=1;
do{
System.out.println(i);
i++;
while(i<=6);
}}
Output:
class Reverse
int number=1234;
int reversed=0;
int temp=0;
while(number>0)
temp=number%10;
reversed=reversed*10+temp;
number=number/10;
}}
Output:
INPUT:
import java.util.Scanner;
class Input
System.out.println("enter hobbies");
String hobbies=sc.next();
}}
Output:
class Fibo
int limit=5;
long[]series=new long[limit];
series[0]=0;
series[1]=1;
for(int i=2;i<limit;i++)
series[i]=series[i-1]+series[i-2];
for(int i=0;i<limit;i++)
System.out.println(series[i]+"");
}}}
Output:
PYRAMIDS:
class Pyramid1
for(int i=1;i<=5;i++)
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
for(int j=1;j<=i;j++)
System.out.print("*");
System.out.println("");
}}}
Output:
class Pyramid2
for(int i=1;i<=4;i++)
for(int j=1;j<=i;j++)
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
System.out.print("*");
System.out.println("");
for(int i=1;i<=4;i++)
for(int j=3;j>=i;j--)
System.out.print("*");
System.out.println("");
}}}
Output:
CALENDAR:
import java.time.*;
class Cal2
Instant timestamp=Instant.now();
}}
Output:
OBJECT: They are instances of class, which are used to access data
members and member functions of a class.
CLASS: A class is a collection of objects having similar features. It is
used for better management of data and its security.
class Student
int id;
String name;
class Test1
s1.id=101;
s1.name="Kashika";
s2.id=102;
s2.name="krishna";
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
System.out.println(s1.id+" "+s1.name);
System.out.println(s2.id+" "+s2.name);
}}
Output:
class Account
int acc_no;
String name;
float amount;
acc_no=a;
name=n;
amount=amt;
amount=amount+amt;
System.out.println(amt+"deposited");
if(amount<amt)
System.out.println("insufficient amount");
else
amount=amount+amt;
System.out.println(amt+"withdraw");
void checkBalance()
System.out.println("balance is:"+amount);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
void display()
}}
class TestAccount
a1.insert(832345,"kashika",10000);
a1.display();
a1.checkBalance();
a1.deposit(40000);
a1.checkBalance();
a1.withdraw(1500);
a1.checkBalance();
}}
Output:
class Teacher
String destination="Teacher";
String collegeName="CGC";
void does()
System.out.println("teaching");
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
}}
String mainSubject="Math";
System.out.println(m.collegeName);
System.out.println(m.destination);
System.out.println(m.mainSubject);
m.does();
}}
Output:
class A
A()
System.out.println("constructor of A");
}}
class B extends A
B()
System.out.println("constructor of B");
new B();
}}
Output:
class A
A()
System.out.println("constructor of A");
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
void display()
System.out.println("A method");
}}
class B extends A
B()
System.out.println("constructor of B");
void display()
System.out.println("B method");
super.display();
B b=new B();
b.display();
}}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
Output:
class A
String ourString=myString+yourString;
ourString=myString.concat(yourString);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
System.out.println(ourString);
}}
Output:
class A
{String myString="hello";
System.out.println(myString.charAt(3));
}}
Output:
Runtime-polymorphism.
Compile time-polymorphism.
class A
void display()
System.out.println("class A");
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
}}
class B extends A
void display()
System.out.println("class B");
A a=new B();
a.display();
}}
Output:
class Sample
{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
System.out.println("value of x:"+x);
System.out.println("value of y:"+y);
System.out.println("value of x:"+x);
s.display(5,6);
s.display(7);
}}
Output:
System.out.println("run method");
System.out.println("t1 State"+t1.getState());
System.out.println("t2 State"+t2.getState());
t1.start();
System.out.println("t1 State"+t1.getState());
System.out.println("t2 State"+t2.getState());
t2.start();
System.out.println("t1 State"+t1.getState());
System.out.println("t2 State"+t2.getState());
}}
Output:
APPLETS: It is Java program that runs in the Browser. It can work with
HTML.
import java.applet.Applet;
import java.awt.*;
g.setColor(Color.pink);
g.drawString("welcome",50,50);
g.drawLine(20,30,20,300);
g.drawRect(70,100,30,30);
g.drawRect(170,100,30,30);
g.drawOval(70,200,30,30);
}}
Html:
<html>
<body>
<applet code="Demo.class"
width="300"
height="300">
</applet>
</body>
</html>
Output:
EVENT-HANDLING:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
{Button b;
TextField tf;
{tf=new TextField();
tf.setBounds(20,40,150,20);
b=new Button("click");
b.setBounds(80,150,60,50);
add(b);add(tf);
b.addActionListener(this);
setLayout(null);
}}
Html:
<html>
<body>
<applet code="Event.class"
width="300"
height="300">
</applet>
</body>
</html>
Output:
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
addMouseMotionListener(this);
setBackground(Color.Green);
Graphics g=getGraphics();
g.setColor(Color.white);
g.fillOval(e.getX(),e.getY(),5,5);
}}
Html:
<html>
<body>
<applet code="Mouse.class"
width="300"
height="300">
</applet>
</body>
</html>
Output:
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
Thread t=null;
int hours=0,minutes=0,seconds=0;
String timeString="";
{setBackground(Color.blue);
{t=new Thread(this);
t.start();
try{
while(true)
{Calendar cal=Calendar.getInstance();
hours=cal.get(Calendar.HOUR_OF_DAY);
if(hours>12)
hours-=12;
minutes=cal.get(Calendar.MINUTE);
seconds=cal.get(Calendar.SECOND);
Date date=cal.getTime();
timeString=formatter.format(date);
repaint();
t.sleep(100);
}}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
catch(Exception e){}
{g.setColor(Color.yellow);
g.drawString(timeString,50,50);
}}
Html:
<html>
<body>
<applet code="Digital.class"
width="300"
height="300">
</applet>
</body>
</html>
Output:
import java.awt.*;
public class A
{A()
fm.add(lb);
fm.setSize(300,300);
fm.setVisible(true);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
A a=new A();
}}
Output:
import java.awt.*;
A()
b.setBounds(30,100,80,30);
add(b);
setSize(300,300);
setLayout(null);
setVisible(true);
A a=new A();
}}
Output:
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
int width,height;
Thread t=null;
boolean threadSuspended;
int hours=0,minutes=0,seconds=0;
String timeString="";
width=getSize().width;
height=getSize().height;
setBackground(Color.pink);
if(t==null)
{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
t=new Thread(this);
t.setPriority(Thread.MIN_PRIORITY);
threadSuspended=false;
t.start();
else
{if(threadSuspended)
{threadSuspended=false;
synchronized(this)
notify();
}}
}}
threadSuspended=true;
{try
while(true)
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
{Calendar cal=Calendar.getInstance();
hours=cal.get(Calendar.HOUR_OF_DAY);
if(hours>12)hours-=12;
minutes=cal.get(Calendar.MINUTE);
seconds=cal.get(Calendar.SECOND);
SimpleDateFormat formatter=new
SimpleDateFormat("hh:mm:ss",Locale.getDefault());
Date date=cal.getTime();
timeString=formatter.format(date);
if(threadSuspended)
{synchronized(this)
while(threadSuspended)
{wait();
}}}
repaint();
t.sleep(100);
}}
catch(Exception e)
}}
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
angle-=0.5*Math.PI;
int x=(int)(radius*Math.cos(angle));
int y=(int)(radius*Math.sin(angle));
g.drawLine(width/2,height/2,width/2+x,height/2+y);
angle-=0.5*Math.PI;
int x=(int)(radius*Math.cos(angle));
int y=(int)(radius*Math.sin(angle));
angle+=2*Math.PI/3;
int x2=(int)(5*Math.cos(angle));
int y2=(int)(5*Math.sin(angle));
angle+=2*Math.PI/3;
int x3=(int)(5*Math.cos(angle));
int y3=(int)(5*Math.sin(angle));
g.drawLine(width/2+x2,height/2+y2,width/2+x,height/2+y);
g.drawLine(width/2+x3,height/2+y3,width/2+x,height/2+y);
g.drawLine(width/2+x2,height/2+y2,width/2+x3,height/2+y3);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
{g.setColor(Color.white);
drawWedge(2*Math.PI*hours/12,width/5,g);
drawWedge(2*Math.PI*minutes/60,width/3,g);
drawWedge(2*Math.PI*seconds/60,width/2,g);
g.setColor(Color.blue);
g.drawString(timeString,10,height-10);
}}
Html:
<html>
<body>
<applet code="Analog.class"
width="300"
height="300">
</applet>
</body>
</html>
Output:
PROJECT
CALCULATOR:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Cal extends Applet implements ActionListener
{String s,s1,s2,s3,s4;
int a,b,c;
Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b11,b12,b13,b14,b15,b16,b17,b18;
TextField tf1;
Label lb1;
public void init()
{
lb1=new Label("result");
lb1.setBounds(50,40,100,20);
tf1=new TextField();
tf1.setBounds(150,40,200,30);
b1=new Button("7");
b1.setBounds(150,80,50,20);
b2=new Button("8");
b2.setBounds(200,80,50,20);
b3=new Button("9");
b3.setBounds(250,80,50,20);
b4=new Button("+");
b4.setBounds(300,80,50,20);
b5=new Button("4");
b5.setBounds(150,120,50,20);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
b6=new Button("5");
b6.setBounds(200,120,50,20);
b7=new Button("6");
b7.setBounds(250,120,50,20);
b8=new Button("-");
b8.setBounds(300,120,50,20);
b9=new Button("1");
b9.setBounds(150,160,50,20);
b11=new Button("2");
b11.setBounds(200,160,50,20);
b12=new Button("3");
b12.setBounds(250,160,50,20);
b13=new Button("*");
b13.setBounds(300,160,50,20);
b14=new Button("%");
b14.setBounds(150,200,50,20);
b15=new Button("0");
b15.setBounds(200,200,50,20);
b16=new Button("/");
b16.setBounds(250,200,50,20);
b17=new Button("=");
b17.setBounds(300,200,50,20);
b18=new Button("clear");
b18.setBounds(150,240,200,20);
add(lb1);
add(tf1);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b11);
add(b12);
add(b13);
add(b14);
add(b15);
add(b16);
add(b17);
add(b18);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(this);
setLayout(null);
}
public void actionPerformed(ActionEvent e)
{
s=e.getActionCommand();
if(s.equals("0")||s.equals("1")||s.equals("2")||s.equals("3")||s.equals("
4")||s.equals("5")||s.equals("6")||s.equals("7")||s.equals("8")||s.equal
s("9"))
{
s1=tf1.getText()+s;
tf1.setText(s1);
}
if(s.equals("+"))
{
s2=tf1.getText();
tf1.setText("");
s3="+";
}
if(s.equals("-"))
{
s2=tf1.getText();
tf1.setText("");
s3="-";
}
if(s.equals("*"))
{
s2=tf1.getText();
tf1.setText("");
s3="*";
}
if(s.equals("/"))
{
s2=tf1.getText();
tf1.setText("");
s3="/";
}
if(s.equals("%"))
{
s2=tf1.getText();
tf1.setText("");
s3="%";
}
if(s.equals("="))
{
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
s4=tf1.getText();
a=Integer.parseInt(s2);
b=Integer.parseInt(s4);
if(s3.equals("+"))
c=a+b;
if(s3.equals("-"))
c=a-b;
if(s3.equals("*"))
c=a*b;
if(s3.equals("/"))
c=a/b;
if(s3.equals("%"))
c=a%b;
tf1.setText(String.valueOf(c));
}
if(s.equals("clear"))
{
tf1.setText("");
}}
public void textvalueChanged(TextEvent e)
{
}}
Html:
<html>
<body>
<applet code="Cal.class"
Submitted By- KASHIKA DUGGAL
Project Report CORE JAVA
width="300"
height="300">
</applet>
</body>
</html>
Output:
1.)Enter 7
3.)Enter 8
4.)output is: