0% found this document useful (0 votes)
39 views

JAVA LAB PROGRAMS SEM-3 NEP 1-12 (3)

1-12 java lab programs ,3rd sem very important notes on lab program

Uploaded by

mrutuber9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

JAVA LAB PROGRAMS SEM-3 NEP 1-12 (3)

1-12 java lab programs ,3rd sem very important notes on lab program

Uploaded by

mrutuber9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3

1. Program to read the radius of a circle and to find the area and /*LAB#1 Write a Java program to read the radius of a circle and
circumference. to find the area and circumference. */
2. Program to demonstrate String Operators import java.util.Scanner;
3. Program to find N prime numbers reading N as command line public class circle {
argument. public static void main(String args[]) {
4. Program to find factorial of N numbers reading N as command Scanner io = new Scanner(System.in);
line argument. System.out.println("Input the radius of the circle: ");
5. Program to read N numbers and sort them using one- double r = io.nextDouble();
dimensional arrays. System.out.println("Area is = " + (Math.PI * r * r));
System.out.println("circumference is = " + (2 * Math.PI * r));
6. Program to illustrate Method Overloading.
7. Program to illustrate Operator Overloading. }
8. Program to demonstrate Single Inheritance. }
9. Program to illustrate Constructor Overloading
10. Program to illustrate Method Overriding Output:

11. Program demonstrating Multithreading. Input the radius of the circle:


12. Program demonstrating Exception Handling. 10
13. Program to demonstrate the user-defined package program. Area is = 314.1592653589793
circumference is = 62.83185307179586
14. Applet Program to display Geometrical Figures using objects. ---------------------------------------------------------------------------
15. Applet Program which illustrates the Scroll bar object. // LAB#2 Write a java program to demonstrate String
16. Applet program to change the background color randomly. Operators.
17. Applet program to change the color of applet using combo
box. public class strings{
18. Applet program to implement Digital Clock using thread. public static void main(String[] args) {
19. Applet program to implement Mouse events. String str = "Java Language";
20. Applet program to implement Keyboard events. String s1= "JAVA";
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
String s2= "Java"; Checking equals ignoring case: true
String s3 = " Hello Java "; Checking equals with case: false
System.out.println(str); Length: 13
System.out.println(s1); Replace function: JAVA Language
System.out.println(s2); lower case: java language
System.out.println(s3+"\n"); upper case: JAVA LANGUAGE
System.out.println("Char at index 3(fourth position): " + Trim string: Hello Java
str.charAt(3)); */
System.out.println("After Concat: "+ str.concat("-App-")); ---------------------------------------------------------------------------
System.out.println("Checking equals ignoring case: "
+s2.equalsIgnoreCase(s1)); //LAB#3 Write a Java program to find N prime numbers
System.out.println("Checking equals with case: " +s2.equals(s1)); reading N as command line argument.
System.out.println("Length: "+ str.length());
System.out.println("Replace function: "+ str.replace("Java", public class Prime {
"JAVA")); public static void main(String args[]) {
System.out.println("lower case: "+ str.toLowerCase()); // Read N from the command line
System.out.println("upper case: "+ str.toUpperCase()); int N = Integer.parseInt(args[0]);
System.out.println("Trim string: " + s3.trim());
} int count = 0;
} int number = 2;

Output: while (count < N) {


Java Language if (isPrime(number)) {
JAVA System.out.println(number);
Java count++;
Hello Java }
Char at index 3(fourth position): a number++;
After Concat: Java Language-App- }
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
} //LAB#4 Write a program to find factorial of N numbers
reading N as command line argument
// Method to check if a number is prime
public static boolean isPrime(int num) { class fact {
for (int i = 2; i < num; i++) { public static void main(String[] args)
if (num % i == 0) { {
return false; int n, f, i, j;
} f = 1;
} n = Integer.parseInt(args[0]);
return true; for (i = 1; i <= n; i++)
} {
} for (j = i; j <= i; j++)
{
/* f = f * i;
OUTPUT }
2 System.out.println(f);
3 }
5 }
7 }
11 /*
*/ OUTPUT
1
--------------------------------------------------------------------------- 2
6
24
120
*/
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
//LAB#5 Write a program to read N numbers and sort them a[i] = a[j];
using one-dimensional arrays. a[j] = t;
}
import java.util.*; }
}
class sorting // Sorted Array`
{ System.out.println("\n Sorted Array ");
public static void main(String args[]) for (int i = 0; i < a.length; i++) {
{ System.out.print(a[i] + " ");
int l, t; // l-length t-temp }
Scanner sc = new Scanner(System.in); }
System.out.println("Enter length of Array-"); }
l = sc.nextInt();
int a[] = new int[l];// Array declaration
System.out.print("Enter " + l + " Elements to Array:\n"); /* OUTPUT
for (int i=0; i<l; i++) Enter length of Array-
{ 5
a[i] = sc.nextInt(); Enter 5 Elements to Array:
} 20
System.out.print("Array Elements:\n"); 30
for (int i=0; i<l; i++) { 10
System.out.print(a[i] + " "); 45
} 15
// Sorting Array Elements:
for (int i = 0; i < a.length; i++) { 20 30 10 45 15
for (int j = i + 1; j < a.length; j++) { Sorted Array
if (a[i] > a[j]) { 10 15 20 30 45
t = a[i]; */
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
//LAB#6 Write a Java program to illustrate Method System.out.println("Area of Square\t"+b.area(3));
Overloading. }
}
import java.lang.Math;
/*
class Box OUTPUT
{ Area of Rectangle 20
int area(int l,int b) Area of Circle 314.1592653589793
{ Area of Square 9
return l*b; */
} ---------------------------------------------------------------------------
double area(double r)
{ //LAB#7 Write a java Program to illustrate operator
return Math.PI*r*r; overloading
}
int area(int a) import java.util.Scanner;
{
return a*a; public class opr
} {
} public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
class loadmethod System.out.println("Enter one string");
{ String s1 = sc.next();
public static void main(String args[]) System.out.println("Enter another string: ");
{ String s2 = sc.next();
Box b=new Box(); System.out.println("+ operator for concatination of two
System.out.println("Area of Rectangle\t"+b.area(10,2)); strings\t"+(s1+s2));
System.out.println("Area of Circle\t"+b.area(10.0)); System.out.println("Enter one number");
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
int x = sc.nextInt(); }
System.out.println("Enter another number"); }
int y = sc.nextInt(); public class inher extends Rect
System.out.println("+ operator adds the two {
numbers\t"+(x+y)); public static void main(String[] args)
} {
} Rect obj = new Rect();
/* System.out.println("Area of rectangle is "+obj.Area(10,5));
OUTPUT }
Enter one string }
BCA /*
Enter another string: OUTPUT
COURSE Area of rectangle is 50
+ operator for concatination of two strings BCACOURSE */
Enter one number ---------------------------------------------------------------------------
20
Enter another number //LAB#9 Java program to illustrate constructor overloading
24
+ operator adds the two numbers 44 class Const
*/ {
--------------------------------------------------------------------------- Const(int a, int b)
//LAB#8 Java program to implement single inheritance {
System.out.println("Sum is " + (a + b));
class Rect }
{ Const(int a, int b, int c)
int Area(int l, int b) {
{ System.out.println("Sum is " + (a + b + c));
return l * b; }
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
Const(String dept) }
{ class Axis extends Bank
System.out.println("Department is: " + dept); {
} int ROI()
} {
class overload return 8;
{ }
public static void main(String args[]) { }
Const obj = new Const(20,30); class Union extends Bank
Const obj1 = new Const(9,19,29); {
Const obj2 = new Const("BCA"); int ROI()
} {
} return 7;
/* }
OUTPUT }
Sum is 50 class over
Sum is 57 {
Department is: BCA public static void main(String args[])
{
//LAB#10 Java program to illustrate Method Overriding Axis a = new Axis();
Union u = new Union();
//ROI-Rate Of Interest. Two Banks 1. AXIS 2. Union System.out.println("Axis Bank - Rate of Interest: " +a.ROI());
class Bank System.out.println("Union Bank - Rate of Interest: " +u.ROI());
{ }
int ROI() }
{
return 0; /**
} Output:
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
Axis Bank - Rate of Interest: 8 }
Union Bank - Rate of Interest: 7 }
*/ class ThirdThread extends Thread
--------------------------------------------------------------------------- {
//LAB#11 Java program to Demonstrate Multithreading public void run() {
for (int i = 0; i < 4; i++)
import java.lang.*; {
System.out.println(i);
class FirstThread extends Thread }
{ System.out.println("Third Thread Finished");
public void run() }
{ }
for (int i = 0; i < 4; i++)
{ class mthread // Multithreading
System.out.println(i); {
} public static void main(String arg[])
System.out.println("First Thread Finished"); {
} FirstThread t1 = new FirstThread();
} SecondThread t2 = new SecondThread();
class SecondThread extends Thread ThirdThread t3 = new ThirdThread();
{ t1.start();
public void run() t2.start();
{ t3.start();
for (int i = 0; i < 4; i++) }
{ }
System.out.println(i);
} /*
System.out.println("Second Thread Finished"); OUTPUT
SHREE GURU SUDHINDRA COLLEGE OF COMPUTER APPLICATIONS (BCA), BHATKAL JAVA LAB PROGRAMS |NEP |SEM-3
0 catch (ArithmeticException e)
1 {
2 System.out.println("Error: Cannot divide by zero.");
3 }
First Thread Finished finally
0 {
1 System.out.println("Execution of try-catch block
2 completed.");
3 }
0 System.out.println("Program continues after exception
1 handling.");
2 }
3 }
Second Thread Finished /*
Third Thread Finished OUTPUT
--------------------------------------------------------------------------- Error: Cannot divide by zero.
//LAB#12 Java program to demonstrate Exception Handling. Execution of try-catch block completed.
Program continues after exception handling.
public class exception */
{
public static void main(String[] args) {
try
{
// Example of potential exception: dividing by zero
int a = 10;
int b = 0;
System.out.println("Result: " + (a / b));
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy