Source ds
Source ds
class student {
int rno=420;
string name=""raju”;
string_class="CSD";
system.out.println(name);
system.out.println(rno);
system.out.println(-class);
S.display();
}
Source:-
return (x+y+z);
return(x+y);
system.out.println(s.sum(10,20));
system.out.println(s.sum(10,20,30));
system.out.println(s.sum(10,5,20.5));
}
Source:-
//fields
//constructor
this.name=name;
this,age=age;
System.out.println("Name:"+name);
System.out.println("Age:"+age);
Person1.displayInfo();
}
Source:-
class Box{
double width,height,depth;
width=w
height=h
depth=d
Box(){width=height=deph=0;}
Box(double len){width=height=depth=len;}
double vol;
vol=mybox1.Volume();
vol=mybox2.Volume();
system.out.println("Volume of mybox2 is"*void);
vol=mycubes.volume c();
}
Source:-
Class shape{
//calculate area is member of shape class public int calculate Area(int length,int breadth){
//In heriting shape member using extends keyword class rectangle extends shape{
}
Source:-
Class Sem1
int eng,math,phy,chem,avg1;
Sem1()
eng=95;
math=93;
phy=88;
chem=90;
avg1=(eng+math+phy+chem)/4;
int eng2,math2,phy2,chem2,avg2;
Sem2()
eng2=89;
math2=98;
phy2=97;
chem2=79;
avg2=(eng2+math2+phy2+chem2)/4;
{
int eng3,math3,phy3,chem3,avg3;
Sem3()
eng3=87;
math3=78;
phy3=88;
chem3=96;
avg3=(eng3+math3+phy3+chem3)/4;
int eng4,math4,phy4,chem4,avg4;
Sem4()
eng4=79;
math4=90;
phy4=77;
chem4=96;
avg4=(eng4+math4+phy4+chem4)/4;
int totalavg()
return(avg1+avg2+avg3+avg4)/4;
Class Multipleinheritanceexample
{
System.out.println("Semester 1avg:"+S4.avg1);
System.out.println("Semester 2avg:"+S4.avg2);
System.out.println("Semester 3avg:"+S4.avg3);
System.out.println("Semester 4avg:"+S4.avg4);
System.out.println("Total average:"+S4.totalavg(1));
}
Source:-
this.radius=radius;
@override
double calculateArea(){
return Math.PI*radius*radius;
this.length=length;
this.width=width;
@override
double calculateArea(){
return length*width;
system.out.println("Area of circle:"+circle.calculateArea());
system.out.println("Area of rectangle:"+rectangle.calculateArea());
}
source code:-
class Person
int id;
string name;
this.id=id;
this.name=name;
float salary;
super(id,name);
this.salary
void display()
system.out.println(id+""+name+""+salary);
class Testsuper
E1.display();
}
Source code:
interface Animal{
void sound();
interface Pet{
void play();
dog.sound();
dog.play();
}
Source code:
class Animal
Void sound()
Void sound(){
Void sound(){
animal.sound();
animal.sound();
}
Source code:
int[]numbers={12345};
try{
system.out.println("exception caught:"+e);
finally{
}
Source code:
package com.tutorialspoint;
try{
int b=0;
int c=1/b;
catch(ArrayIndexoutofBoundsException e){
system.out.println("ArrayIndexoutofBoundsexception thrown:"+e);
catch(Exception e)
system.out.println("Exception thrown:"+e);
}
Sourc code:
package com.tutorialspoint;
try{
int b=0;
int c=1/b;
system.out.println("c:"+c);
system.out.println("Exception thrown:"+e);
}
Source code:
public myException(string S)
Super(s);
try{
catch(myexception ex){
system.out.println("caught");
system.out.println(ex.getmessage());
}
Source code:
Import java.io.*;
for(int i=0;i<100;i++)
try{
thread.sleep(1000);}
catch(interuptedExpextion e){
Systemout.printin(e);
Systemout.printin(“Good morning”);
}
}
for(int i=0;i<100;i++)
try{
Thread.sleep(200);}
Catch(interruptedException e)
Systemout.printin(e);
}
}
Systemprintin(“Hello”);
}
}
}
for(i=0;i<100;i++)
try{
Thread.sleep(3000);}
Catch(interuptedException e){
Systemout.printin(“Welcome”);
}
}
}
class ThreadEx
t1.SetName(“One”);
t2.SetName(“Two”);
t3.SetName(“Three”);
Systemout.printin(t1);
Systemout.printin(t2);
Systemout.printin(t3);
Thread t=Thread.currentthread();
t1.start();
t2.start();
t3.start();
}
Source code:
This.name=name;
This.sleeptime=sleeptime;
Systemout.printin(“Thread”,+name+,”Starting”);
Try{
Thread.sleep(Sleeptime*1000);
Catch(interuptedException e)
Systemout.printin(“Thread”,+name+,”interrupted”);
Systemout.printin(“Thread”,+name+,”Finished”);
}
}
Mytask.thread1=new Mytask(“one”,2);
Mytask.thread2=new Mytask(“tab”,4);
Thread1.start();
Thread2.start();
try{
thread1.join();
thread2.join();
Catch(interruptedExpection e){
Systemout.printin(“Therad interrupted”);
}
}
Public class TestDaemon Thread1 extends thread
if(Thread.currentthread() is daemon())
else{
}
}
t1.setDaemon(true);
t1.start();
t2.start();
t3.start();
}
Source code:
Import java.util.linkedlidst;
@override
try{
pc.produce();
Catch(interuptedExeption e){
e.printstackTrace();
}
}
});
@override
try{
pc.consume();
Catch(interuptedExeption e){
e.printstackTrace();
}
}
});
t1.start():
t2.start();
t1.join()
t2.join();
Linkedlist<integer>list=new linkedlist<>();
Int capacity=2;
Int value=0;
While(true){
Synchronized(this)
While(list.size()==capacity)
Wait();
Systemoutprintin(“Producer produced-“,+value);
List.add(value++);
Notify();
Thread.sleep(100);
}
}
}
While(true){
Synchronized(this)
While(list.size()==0)
Wait();
Int val=list.removeFirst();
Systemoutprintin(“consumer consumed-“,+value);
notify();
Thread.sleep(1000);
Source Code:-
package com.example;
return a+b;
return a-b;
return a*b;
if(b!=0){
return a/b;
else {
import com.example.calculator;
system.out.println("Addition:"+result);
result=calculator.subtract(5,3);
system.out.println("Subtraction:"+result);
result=calculator.multiply(5,3);
system.out.println("Multiplication:"+result);
result=calculator.divide(10,2);
system.out.println("Division:"+result);
}
SOURCE CODE:
import java.io.*;
import java.sql.*;
class GFG{
string url
string password="gfg123";
class.forName(
"com.mysql.cj.jdbc.Driver");
connection.con = Drivermanager.getconnection(url,username,password);
statement st=con.createstatement();
Result rs=st.executeQuery(query);
rs.next();
string name=rs.getstring("name");
system.out.println(name);
st.close();
con.close();
system.out.println("connection closed");