LAB Experiments Aaradhya
LAB Experiments Aaradhya
ON
JAVA PROGRAMMING AND INTRODUCTION OF PYTHON
BACHELOR OF TECHNOLOGY
IN
ELECTRONICS AND COMMUNICATION ENGINEERING
Summitted To
Dr. Aman Tyagi
Assistant Professor, Department of Computer Science & Engineering, Faculty
of Engineering & Technology, Gurukul Kangri Deemed to be University,
Haridwar
Submitted By
Aaradhya Srivastava (216320088)
Certificate
This is to certify that Mr. AARADHYA SRIVASTAVA of B.Tech VI semester has
satisfactorily completed his experiments for Java programming and Introduction
of python lab in requirement for partial fulfillment of bachelor degree in
Electronics & Communication Engineering prescribed by Faculty of Engineering
& Technology, Gurukula Kangri Deemed to be University, Haridwar during the
year 2023-2024
Index
Code:
public class aaradhya { public static void main(String[] args) {
System.out.println("Aaradhya Srivastava 216320088 ECE 6th SEM");
byte byteVar = 10;
short shortVar = byteVar;
int intVar = shortVar;
long longVar = intVar;
float floatVar = longVar;
double doubleVar = floatVar;
Code:
public class aaradhya { public static void main(String[] args) {
System.out.println("Aaradhya Srivastava 216320088 ECE 6th SEM");
// Declare and initialize a double variable
double doubleValue = 123.456;
// Display the original double value and the narrowed int value
System.out.println("Original double value: " + doubleValue);
System.out.println("Narrowed int value: " + intValue);
}
}
Output:
PROGRAM – 03
Java Program in which class variables are assigned via method of a class.
Code:
class MyClass {
// Class variables
static int num1;
static int num2;
// Method to assign values to class variables
}
}
public class Main {
public static void main(String[] args) {
// Assign values to class variables via method
MyClass.assignValues(10, 20);
}
}
PROGRAM – 04
Java program for default constructor
Code:
class MyClass {
// Class variables
num1 = a;
num2 = b;
MyClass.assignValues(10, 20);
MyClass.displayValues();
Output:
PROGRAM – 05
Java program for parameterized constructor.
Code:
class Car {
String make;
String model;
int year;
// Parameterized constructor
this.make = make;
this.model = model;
this.year = year;
void displayInfo() {
System.out.println("My Car:");
myCar.displayInfo();}}
Output:
PROGRAM – 06
Java program using Constructor Overloading.
Code:
class Rectangle {
double length;
double width;
// Default constructor
Rectangle() {
length = 0;
width = 0;
}
Output:
PROGRAM – 07
Java program using Method Overloading.
Code:
public class Sum {
return (x + y + z);
// parameters
return (x + y);
// Driver code
System.out.println(s.sum(10, 20));
System.out.println(s.sum(10.5, 20.5)); } }
Output:
PROGRAM – 08
Java program using multi-level inheritance
Code:
// Parent class
class Animal {
void eat() {
System.out.println("Animal is eating");
}
}
Output:
PROGRAM – 09
Java program using method overriding
Code:
// Parent class
class Animal {
// Method to make sound
void makeSound() {
System.out.println("Animal is making a sound");
}
}
// Child class inheriting from Animal
class Dog extends Animal {
// Overriding the makeSound method of the parent class
@Override
void makeSound() {
System.out.println("Dog is barking");
}
}
public class Main {
Output:
PROGRAM – 10
Java program using interface.
Code:
// Interface defining the methods that must be implemented by classes
interface Animal {
void makeSound();
void move();
}
Output:
PROGRAM – 11
java program for extending interface
Code:
// Parent class
class Animal {
// Method to make sound
void makeSound() {
System.out.println("Animal is making a sound");
}}
// Child class inheriting from Animal
class Dog extends Animal {
// Overriding the makeSound method of the parent class
@Override
void makeSound() {
System.out.println("Dog is barking");
}}
public class Main {
public static void main(String[] args) {
// Creating an object of Dog class
Dog dog = new Dog();
// Calling the makeSound method of Dog class
dog.makeSound(); // This will call the overridden method in Dog class
}}
Output
PROGRAM – 12
Python program for Explaining Logical expressions “and”, “or” and not
Code:
# Define variables
a = True
b = False
# Logical OR (or)
result_or = a or b
print("Logical OR (a or b):", result_or)
Output
PROGRAM – 13
Python program for left shift and right shift.
Code:
def left_shift(num, shift):
return num << shift
# Example usage:
number = 10
shift_amount = 2
# Left shift
result_left_shift = left_shift(number, shift_amount)
print("Left shift:", result_left_shift)
# Right shift
result_right_shift = right_shift(number, shift_amount)
print("Right shift:", result_right_shift)
Output
PROGRAM – 14
A python program to explain Operator Precedence.
Code:
# Define variables
a = 10
b=5
c=2
# Arithmetic operations
result = a + b * c
print("Result of a + b * c:", result)
# More examples
result_ex1 = a + b / c
print("Result of a + b / c:", result_ex1)
result_ex2 = (a + b) / c
print("Result of (a + b) / c:", result_ex2)
Output
PROGRAM – 15
A python program to explain Case Changing of Strings.
Code:
# Example of Case Changing of Strings
# Original string
string = "Hello, World!"
# Convert the string to uppercase
uppercase_string = string.upper()
print("Uppercase:", uppercase_string) # Output: HELLO, WORLD!
# Convert the string to lowercase
lowercase_string = string.lower()
print("Lowercase:", lowercase_string) # Output: hello, world!
# Convert the first character of each word to uppercase
titlecase_string = string.title()
print("Titlecase:", titlecase_string) # Output: Hello, World!
# Swap the case of each character in the string
swapcase_string = string.swapcase()
print("Swapcase:", swapcase_string) # Output: hELLO, wORLD!
Output:
PROGRAM – 16
A python program to explain String replace() Method.
Code:
# Example of String replace() Method
# Original string
string = "Hello, World!"
Output
PROGRAM – 17
A python program to explain the calling a function
Code:
# Define a function named 'greet' which takes one parameter 'name'
def greet(name):
# Print a greeting message with the provided name
print("Hello, " + name + "!")
Code:
def find_greater_number(num1, num2):
Output:
PROGRAM – 19
A python program to find whether a list is empty or not
Code:
def is_list_empty(input_list):
if not input_list:
return True
else:
return False
# Example usage:
empty_list = []
non_empty_list = [1, 2, 3]
if is_list_empty(empty_list):
print("The list is empty")
else:
print("The list is not empty")
if is_list_empty(non_empty_list):
print("The list is empty")
else:
print("The list is not empty")