Vedant
Vedant
01
AIM: Write a program to show to show scope of variables in JAVA.
PROGRAM:
class Main
{
public static void main(String[] args)
{
int a=10;
int b=10;
int c=a+b;
System.out.println("value of a="+a);
System.out.println("value of b="+b);
System.out.println("sum="+c);
}
EXPERIMENT NO.02
AIM: Write a program to show Concept of CLASS in JAVA.
PROGRAM:
class Student{
int rollno;
String name;
rollno=r;
name=n;
}
void displayInformation(){System.out.println(rollno+" "+name);}
class TestStudent4{
s1.insertRecord(111,"Karan");
s2.insertRecord(222,"Aryan");
s1.displayInformation();
s2.displayInformation();}
}
OUTPUT:
EXPERIMENT NO.03
AIM: Write a program to show typecasting in java
PROGRAM:
Converting double into an int
class Main {
public static void main(String[] args) {
// create double type variable
double num = 10.99;
System.out.println("The double value: " + num);
OUTPUT:
OUTPUT:
PROGRAM:
import java.lang.*;
import java.io.*;
import java.sql.*;
public class connec vity
{
public sta c void main(String args[])
{
Stmt.execute(str0);
stmt.execute(str1);
System.out.println("table is created");
int count1=stmt.executeUpdate(str2);
System.out.println("value 1 is inserted");
int count2=stmt.executeUpdate(str3);
System.out.println("value 2 is inserted");
int count3=stmt.executeUpdate(str4);
System.out.println("value 3 is inserted");
ResultSet rs=stmt.executeQuery(str5);
System.out.println("id \t name");
while(rs.next())
{
String id=rs.getString("c_id");
String name=rs.getString("c_name");
System.out.print(id+"\t");
System.out.print(name+"\n");
System.out.print();
}
int count4=stmt.executeUpdate(str6);
System.out.println("tableis updated");
int count5=stmt.executeUpdate(str7);
System.out.println("tableis deleted");
con.close();
}
catch(Excep on ex)
{
System.out.println("error occured"+ ex);
}
OUTPUT:
EXPERIMENT NO. 5
AIM: Write A Program To Perform Multithreading Operation
importjava.io
*;
importjava.net
.;
String
name;
Thread t;
NewThread(String threadname)
name=threadname;
t=new
Thread(this,name);
System.out.println("new
thread:"+t); t.start();
try
for(int i=5;i>0;i--)
{
System.out.println(name
+":"+i);
Thread.sleep(1000);
}
catch(InterruptedException e)
System.out.println(name+"Intrrupted");
System.out.println(name+"existing");
class MultithreadDemo
new
NewThread("one");
new
NewThread("two");
new
NewThread("three")
; try
{
Thread.sleep(1000);
catch(InterruptedException e)
System.out.println("mainthread interrupted");
System.out.println("mainthread Exiting");
OUTPUT:
EXPERIMENT NO. 6
AIM: Write a Program to show Inheritance .
class Animal {
// field and method of the parent class
String name;
public void eat() {
System.out.println("I can eat");
}
}
// inherit from Animal
class Dog extends Animal {
// new method in subclass
public void display() {
System.out.println("My name is " + name);
}
}
class Main {
public sta c void main(String[] args) {
// create an object of the subclass
Dog labrador = new Dog();
//Animal java
// public class
public class Animal {
// public variable
public int legCount;
// public method
public void display() {
System.out.println("I am an animal.");
System.out.println("I have " + legCount + " legs.");
}
}
// Main.java
public class Main {
public static void main( String[] args ) {
// accessing the public class
Animal animal = new Animal();
OUTPUT: I AM AN ANIMAL
I HAVE 4 LEGS
Protected
class Animal {
// protected method
protected void display() {
System.out.println("I am an animal");
}
}
Output:: I am an animal
Private
class Data {
private String name;
// getter method
public String getName() {
return this.name;
}
// setter method
public void setName(String name) {
this.name= name;
}
}
public class Main {
public static void main(String[] main){
Data d = new Data();
// Base Class
class Complex {
public sta c void f1()
{
System.out.println(
"f1 method of the Complex class is executed.");
}
}
Output
f1 method of the Complex class is executed.
class Polygon {
// renders Square
public void render() {
System.out.println("Rendering Square...");
}
}
// renders circle
public void render() {
System.out.println("Rendering Circle...");
}
}
class Main {
public sta c void main(String[] args) {
Output
Rendering Square...
Rendering Circle...
EXPERIMENT NO. 10
AIM: Write a program to demonstrate AWT.
1. import java.awt.*;
2.
3.
4. public class AwtProgram1 {
5. public AwtProgram1()
6. {
7. Frame f = new Frame();
8. Button btn=new Button("Hello World");
9. btn.setBounds(80, 80, 100, 50);
10. f.add(btn); //adding a new Button.
11. f.setSize(300, 250); //setting size.
12. f.setTitle("JavaTPoint"); //setting title.
13. f.setLayout(null); //set default layout for frame.
14. f.setVisible(true); //set frame visibility true.
15. }
16.
17.
18. public static void main(String[] args) {
19. // TODO Auto-generated method stub
20.
21. AwtProgram1 awt = new AwtProgram1(); //creating a frame.
22. }
23. }
Output: