0% found this document useful (0 votes)
13 views20 pages

Java Action Learning

The document outlines a series of Java programming exercises aimed at demonstrating various concepts such as variables, arithmetic operations, conditional statements, loops, exception handling, file I/O, threading, lambda expressions, and CRUD operations using JDBC. Each exercise includes a coding phase with example code, a testing phase confirming no errors, and an implementation phase showcasing the final output. Additionally, a rubric for evaluation is provided, emphasizing concepts, planning, execution, and practical simulation.

Uploaded by

uunknowns032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views20 pages

Java Action Learning

The document outlines a series of Java programming exercises aimed at demonstrating various concepts such as variables, arithmetic operations, conditional statements, loops, exception handling, file I/O, threading, lambda expressions, and CRUD operations using JDBC. Each exercise includes a coding phase with example code, a testing phase confirming no errors, and an implementation phase showcasing the final output. Additionally, a rubric for evaluation is provided, emphasizing concepts, planning, execution, and practical simulation.

Uploaded by

uunknowns032
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to demonstrate the use of variables and data types in Java.
* Coding Phase: Pseudo Code / Flow Chart / Algorithm

public class DataTypesDemo {


public static void main(String[] args) {
int age = 25;
float salary = 45000.75f;
char grade = 'A';
boolean isPassed = true;
String name = "Sameer";

System.out.println("Name: " + name);


System.out.println("Age: " + age);
System.out.println("Salary: " + salary);
System.out.println("Grade: " + grade);
System.out.println("Passed: " + isPassed);
}
}

* Testing Phase: Compilation of Code (error detection)

No error

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

Name: Sameer
Age: 25
Salary: 45000.75
Grade: A
Passed: true

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

02
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to perform arithmetic operations in Java.


* Coding Phase: Pseudo Code / Flow Chart / Algorithm

public class ArithmeticOperations {


public static void main(String[] args) {
int a = 10;
int b = 5;

System.out.println("Addition: " + (a + b));


System.out.println("Subtraction: " + (a - b));
System.out.println("Multiplication: " + (a * b));
System.out.println("Division: " + (a / b));
System.out.println("Modulus: " + (a % b));
}
}

* Testing Phase: Compilation of Code (error detection)

No error

03

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2
Modulus: 0

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

04
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to demonstrate the use of conditional statements in Java.


* Coding Phase: Pseudo Code / Flow Chart / Algorithm
import java.util.Scanner;

public class ConditionalDemo {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = sc.nextInt();

if (age >= 18) {


System.out.println("You are eligible to vote.");
} else {
System.out.println("You are not eligible to vote.");
}

sc.close();
}
}

* Testing Phase: Compilation of Code (error detection)

No error

05

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

Enter your age: 20


You are eligible to vote.

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:


06

Signature of the Faculty:


*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to demonstrate the use of loops in Java.


* Coding Phase: Pseudo Code / Flow Chart / Algorithm

public class LoopDemo {


public static void main(String[] args) {
System.out.println("Numbers from 1 to 10:");
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
}

System.out.println("\nEven numbers from 1 to 20:");


int i = 1;
while (i <= 20) {
if (i % 2 == 0) {
System.out.print(i + " ");
}
i++;
}
}
}

* Testing Phase: Compilation of Code (error detection)

No error

07

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

Numbers from 1 to 10:

1 2 3 4 5 6 7 8 9 10

Even numbers from 1 to 20:


2 4 6 8 10 12 14 16 18 20

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

08
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)


Write a program to demonstrate the use of try-catch block in Java.
* Coding Phase: Pseudo Code / Flow Chart / Algorithm

public class TryCatchDemo {


public static void main(String[] args) {
try {
int[] numbers = {1, 2, 3};
System.out.println("Accessing element at index 5: " + numbers[5]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Exception caught: " + e);
}

System.out.println("Program continues after exception handling.");


}
}

* Testing Phase: Compilation of Code (error detection)

No error

09

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

Exception caught: java.lang.ArrayIndexOutOfBoundsException:


Index 5 out of bounds for length 3

Program continues after exception handling.

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

10
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to read and write data to a file in Java.


* Coding Phase: Pseudo Code / Flow Chart / Algorithm
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;

public class FileReadWrite {


public static void main(String[] args) {
String data = "Welcome to Java File I/O!";
try {
FileWriter writer = new FileWriter("sample.txt");
writer.write(data);
writer.close();
System.out.println("Data written to file.");

FileReader reader = new FileReader("sample.txt");


int ch;
System.out.print("Reading from file: ");
while ((ch = reader.read()) != -1) {
System.out.print((char) ch);
}
reader.close();
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
}
}
}

* Testing Phase: Compilation of Code (error detection)

No error

11

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

Data written to file.

Reading from file: Welcome to Java File I/O!

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:


12
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to create a thread by extending Thread class in Java


* Coding Phase: Pseudo Code / Flow Chart / Algorithm
class MyThread extends Thread {
public void run() {
for (int i = 1; i <= 5; i++) {
System.out.println("Thread running: " + i);
try {
Thread.sleep(500); // Pause for 500ms
} catch (InterruptedException e) {
System.out.println("Thread interrupted.");
}
}
}
}

public class ThreadDemo {


public static void main(String[] args) {
MyThread t1 = new MyThread();
t1.start();
}
}

* Testing Phase: Compilation of Code (error detection)

No error

13

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)


Thread running: 1
Thread running: 2
Thread running: 3
Thread running: 4
Thread running: 5

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

14
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to demonstrate the use of lambda expressions in Java.


* Coding Phase: Pseudo Code / Flow Chart / Algorithm

interface Operation {
int calculate(int a, int b);
}

public class LambdaDemo {


public static void main(String[] args) {
Operation add = (a, b) -> a + b;
Operation multiply = (a, b) -> a * b;

System.out.println("Addition: " + add.calculate(10, 5));


System.out.println("Multiplication: " + multiply.calculate(10, 5));
}
}

* Testing Phase: Compilation of Code (error detection)

No error

15
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)


Addition: 15
Multiplication: 50

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

16
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)

Write a program to perform CRUD operations using JDBC in Java.


* Coding Phase: Pseudo Code / Flow Chart / Algorithm
import java.sql.*;

public class JDBCDemo {

public static void main(String[] args) {


try {
Class.forName("com.mysql.cj.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "root", "password");

Statement stmt = con.createStatement();

// Create
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS students (id INT, name VARCHAR(100))");

// Insert
stmt.executeUpdate("INSERT INTO students VALUES (1, 'Sameer')");

// Read
ResultSet rs = stmt.executeQuery("SELECT * FROM students");
while (rs.next()) {
System.out.println("ID: " + rs.getInt(1) + ", Name: " + rs.getString(2));
}

// Update
stmt.executeUpdate("UPDATE students SET name = 'Kumar' WHERE id = 1");

// Delete
stmt.executeUpdate("DELETE FROM students WHERE id = 1");

con.close();
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
}

* Testing Phase: Compilation of Code (error detection)

No error (Assuming database connection details are correct)

17

*As applicable according to the experiment.


One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

ID: 1,
Name: Sameer

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

18
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
School: ............................................................................................................. Campus: .......................................................

Academic Year: ...................... Subject Name: ........................................................... Subject Code: ..........................

Semester: ............... Program: ........................................ Branch: ......................... Specialization: ..........................

Date: .....................................

(Learning by Doing and Discovery)


Write a program to demonstrate ArrayList in Java.
* Coding Phase: Pseudo Code / Flow Chart / Algorithm

import java.util.ArrayList;

public class Example {


public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("Apple");
list.add("Banana");
System.out.println(list);
}
}
Type your text

* Testing Phase: Compilation of Code (error detection)

no error

19
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.
Applied and Action Learning

* Implementation Phase: Final Output (no error)

[Apple, Banana]

Rubrics
Concept 10
Planning and Execution/ 10
Practical Simulation/ Programming
Result and Interpretation 10
Record of Applied and Action Learning 10
Viva 10
Total 50

Signature of the Student:

20
Signature of the Faculty:
*As applicable according to the experiment.
One sheet per experiment (10-20) to be used.

You might also like