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

CHAKRI

Uploaded by

beastboy232472
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)
57 views

CHAKRI

Uploaded by

beastboy232472
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
You are on page 1/ 65

JAVA PROGRAMMING

An Internship report submitted to


Jawaharlal Nehru Technological University, Kakinada,
In the partial fulfillment for the award of the Degree in

BACHELOR OF TECHNOLOGY
IN
COMPUTERSCIENCE & ENGINEERING
Submitted by

PASAM CHAKRADHAR

22F91A0521

Under the Supervision of

Mr.K MOHAN RAO(M.Tech)

PRAKASAMENGINEERINGCOLLEGE
(An ISO 9001-2008&NAAC Accredited Institution)

(Affiliated to Jawaharlal Nehru Technological University, Kakinada)

O.V.ROAD, KANDUKUR-523105, A.P.

A.Y:2024-2025
PRAKASAMENGINEERINGCOLLEGE
(AnISO9001-2008&NAACAccreditedInstitution)

(Affiliated to Jawaharlal Nehru Technological University, Kakinada)

O.V.ROAD,KANDUKUR-523105,A.P.

DEPARTMENTOF
COMPTERSCIENCE&ENGINEERING
BONAFIDECERTIFICATE
This is to certify that the Internship report entitled “JAVA PROGRAMMING” is a bonafide

work of PASAM CHAKRADHAR (22F91A0521) in the partial fulfillment of the

requirement for the award of the degree in Bachelor of Technology in COMPUTER

SCIENCE & ENGINEERING for the academic year 2023-2024.

Signature of the Coordinator Signature of the HOD

Mr.V. BALAKRISHNA RAO Mr. M.M.RAYUDU


M.Tech,(Ph.D)
MBA

Signature of External Examiner


ANDHRA PRADESH STATE COUNCIL OF HIGHER EDUCATION
(A Statutory Body of Government of A.P.)

Certificate of Completion
This is to certify Pasam Chakradhar
under of Prakasam Engineering College of JNTUK has
successfully completed 6 weeks Short -Term Internship on
Java Programming
Organized by ExcelR Edtech Pvt. Ltd. in collaboration with
Andhra Pradesh State Council of Higher Education

Cert No: EXCELR-85908 Ram Tavva


Presented on Aug 2nd 2024 CEO,
ExcelR EdTech Pvt. Ltd.
ACKNOWLEDGEMENT

I feel to render my thankful acknowledgement to the following distinguished personalities, who


stretched their helping hand to me, in completing my mini project work.

I am very grateful and my sincere thanks to our secretary & correspondent Dr.K.RAMAIAH of
PRAKASAM ENGINEERING COLLEGE for giving this opportunity.

I hereby, express my regards and extend my gratitude to our PRINCIPAL, Dr.CH. RAVI
KUMAR , for giving this opportunity to do the thesis as a part of our course.

I express my deep sense of gratitude to Mr.M.M.RAYUDU, M.Tech(Ph.d), Head of the


Department, Department of CSE for having shown keen interest at every stage of development
of our thesis and guiding us in every aspect.

I am thankful to my Internship Coordinator Mr.V. BALAKRISHNA RAO MBA who has


channeled my thoughts and timely suggestions.

I would like to thank Mr.RAM TAWA EXCELR PVT LTD,HYDERBAD for giving me the
opportunity to do an internship within the organization.

I would also like to thank all my Faculties in Prakasam Engineering College for their constant
encouragement and for being a great group of knowledgeable and cooperative people to work
with.

PASAM CHAKRADHAR
22F91A0521
Week 1: Introduction to Java Programming

Introduction to the Internship Program

- **Overview of the Company and Its Mission**

- Brief history of the company, including its founding and major milestones.

- Core values and mission statement, emphasizing the company’s commitment to


innovation and quality.

- Key products and services offered, highlighting the company’s market position and
unique selling points.

- **Introduction to the Team and Key Contacts**

- Names and roles of team members, including their areas of expertise and
responsibilities.

- Contact information and preferred communication channels (e.g., email, Slack,


Microsoft Teams).

- Team structure and hierarchy, explaining how different departments and roles interact.

- **Explanation of Internship Goals and Expectations**

- Specific objectives for the internship, such as learning outcomes and skill development.

- Expected outcomes and deliverables, including any projects or reports to be completed.

- Evaluation criteria and feedback mechanisms, detailing how performance will be


assessed and feedback provided.

#### Setting Up the Development Environment


- **Installing Java Development Kit (JDK)**

- Step-by-step guide to downloading and installing the JDK from the official Oracle
website.

- Configuring system environment variables, including setting JAVA_HOME and updating


the PATH variable.

- **Setting Up Integrated Development Environment (IDE)**

- Overview of popular IDEs (IntelliJ IDEA, Eclipse, NetBeans), with a focus on the chosen
IDE for the internship.

- Detailed setup instructions for the chosen IDE, including installation and initial
configuration.

- Customizing IDE settings for optimal workflow, such as configuring code style, enabling
useful plugins, and setting up version control.

- **Configuring Environment Variables**

- Importance of environment variables in Java development, explaining how they affect the
compilation and execution of Java programs.

- Instructions for setting JAVA_HOME and PATH variables on different operating systems
(Windows, macOS, Linux).

#### Basic Java Syntax

- **Writing the First Java Program: “Hello, World!”**

- Detailed explanation of the program structure, including the `public class` declaration
and the `main` method.

- Compiling and running the program from the command line, with a focus on
understanding the compilation process and common errors.

- **Understanding the Structure of a Java Program**


- Explanation of classes, methods, and the `main` method, highlighting their roles in a
Java application.

- Syntax rules and conventions, including naming conventions, code indentation, and
comments.

- **Compiling and Running Java Programs**

- Using the `javac` compiler to compile Java source files, with examples of common
commands and options.

- Running Java applications with the `java` command, including passing arguments to the
`main` method.

#### Java Basics

- **Data Types and Variables**

- Overview of primitive data types (int, char, float, boolean, etc.), including their ranges
and default values.

- Declaring and initializing variables, with examples of different data types and
initialization methods.

- Type casting and type conversion, explaining the difference between implicit and explicit
casting with examples.

```java

Public class DataTypesExample {

Public static void main(String[] args) {

// Integer data type

Int age = 25;

System.out.println(“Age: “ + age);

// Character data type


Char grade = ‘A’;

System.out.println(“Grade: “ + grade);

// Float data type

Float salary = 50000.50f;

System.out.println(“Salary: “ + salary);

// Boolean data type

Boolean isJavaFun = true;

System.out.println(“Is Java fun? “ + isJavaFun);

```

- **Operators and Expressions**

- Arithmetic operators, including addition, subtraction, multiplication, division, and


modulus, with examples of their usage.

- Relational operators, such as equality, inequality, greater than, and less than, with
examples of their use in conditional statements.

- Logical operators, including AND, OR, and NOT, with examples of combining logical
operators in complex expressions.

- Assignment operators, including basic assignment and compound assignment


operators, with examples of their usage.

```java

Public class TypeCastingExample {

Public static void main(String[] args) {


// Implicit casting (widening conversion)

Int num = 100;

Double doubleNum = num; // int to double

System.out.println(“Double value: “ + doubleNum);

// Explicit casting (narrowing conversion)

Double decimalNum = 9.78;

Int intNum = (int) decimalNum; // double to int

System.out.println(“Integer value: “ + intNum);

```

- **Control Flow Statements**

- Conditional statements, including `if`, `if-else`, and `switch` statements, with


examples and use cases.

- Looping statements, including `for`, `while`, and `do-while` loops, with examples of
iterative processes and common patterns.

```java

Public class ControlFlowExample {

Public static void main(String[] args) {

// If-else statement

Int number = 10;

If (number > 0) {

System.out.println(“The number is positive.”);

} else {
System.out.println(“The number is not positive.”);

// For loop

System.out.println(“For loop:”);

For (int I = 0; I < 5; i++) {

System.out.println(“i: “ + i);

// While loop

System.out.println(“While loop:”);

Int j = 0;

While (j < 5) {

System.out.println(“j: “ + j);

J++;

// Do-while loop

System.out.println(“Do-while loop:”);

Int k = 0;

Do {

System.out.println(“k: “ + k);

K++;

} while (k < 5);

}
```

#### Object-Oriented Programming (OOP) Concepts

- **Introduction to OOP**

- Understanding classes and objects, explaining the concepts of encapsulation,


inheritance, and polymorphism.

- Defining a class and creating objects, with examples of class definitions and object
instantiation.

- Constructors and methods, explaining their roles in initializing objects and defining
behavior.

```java

// Class and Object Example

Class Student {

String name;

Int age;

Void display() {

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

System.out.println(“Age: “ + age);

Public class Main {

Public static void main(String[] args) {

Student student1 = new Student();

Student1.name = “John”;
Student1.age = 20;

Student1.display();

```

- **Encapsulation**

- Access modifiers (private, public, protected), explaining their impact on visibility and
access control.

- Getters and setters, with examples of encapsulating fields and providing controlled
access.

```java

Class Person {

Private String name;

Private int age;

// Getter for name

Public String getName() {

Return name;

// Setter for name

Public void setName(String name) {

This.name = name;

}
// Getter for age

Public int getAge() {

Return age;

// Setter for age

Public void setAge(int age) {

This.age = age;

Public class Main {

Public static void main(String[] args) {

Person person = new Person();

Person.setName(“Alice”);

Person.setAge(30);

System.out.println(“Name: “ + person.getName());

System.out.println(“Age: “ + person.getAge());

```

- **Inheritance**

- Extending classes, explaining the concept of inheritance and the `extends` keyword.

- Method overriding, with examples of overriding methods in subclasses to provide


specific behavior.
```java

// Base class

Class Animal {

Void eat() {

System.out.println(“This animal eats food.”);

// Derived class

Class Dog extends Animal {

Void bark() {

System.out.println(“The dog barks.”);

Public class Main {

Public static void main(String[] args) {

Dog dog = new Dog();

Dog.eat(); // Inherited method

Dog.bark(); // Specific method

```

#### Advanced OOP Concepts


- **Polymorphism**

- Method overloading, explaining the concept and providing examples of overloaded


methods.

- Method overriding, with a focus on runtime polymorphism and the use of the
`@Override` annotation.

```java

Class MathOperations {

// Method overloading

Int add(int a, int b) {

Return a + b;

Double add(double a, double b) {

Return a + b;

Public class Main {

Public static void main(String[] args) {

MathOperations math = new MathOperations();

System.out.println(“Sum of integers: “ + math.add(5, 10));

System.out.println(“Sum of doubles: “ + math.add(5.5, 10.5));

```
- **Abstraction**

- Abstract classes and methods, explaining their roles in defining abstract behavior and
providing partial implementation.

- Interfaces, explaining their use in defining contracts and enabling multiple inheritance.

```java

// Abstract class

Abstract class Shape {

Abstract void draw();

// Concrete class

Class Circle extends Shape {

Void draw

___________________________________________

### Week 2: Advanced Java Programming Concepts

#### Introduction to Advanced Java Concepts

- **Overview of Week 2 Objectives**

- Deepening understanding of Java programming.

- Introduction to more complex programming concepts and techniques.

- Application of these concepts through practical exercises and projects.

#### Data Structures and Algorithms

- **Introduction to Data Structures**

- Importance of data structures in programming.


- Overview of common data structures: arrays, linked lists, stacks, queues, trees, and
graphs.

- **Arrays and Linked Lists**

- Definition and use cases of arrays.

- Basic operations on arrays: insertion, deletion, traversal.

- Definition and use cases of linked lists.

- Types of linked lists: singly linked list, doubly linked list, circular linked list.

- Basic operations on linked lists: insertion, deletion, traversal.

```java

// Example of Array Operations

Public class ArrayExample {

Public static void main(String[] args) {

Int[] numbers = {1, 2, 3, 4, 5};

// Traversing the array

For (int number : numbers) {

System.out.println(number);

// Example of Linked List Operations

Class Node {

Int data;

Node next;
Node(int data) {

This.data = data;

This.next = null;

Public class LinkedListExample {

Node head;

// Inserting a new node at the end

Public void insert(int data) {

Node newNode = new Node(data);

If (head == null) {

Head = newNode;

} else {

Node temp = head;

While (temp.next != null) {

Temp = temp.next;

Temp.next = newNode;

// Displaying the linked list

Public void display() {


Node temp = head;

While (temp != null) {

System.out.print(temp.data + “ “);

Temp = temp.next;

Public static void main(String[] args) {

LinkedListExample list = new LinkedListExample();

List.insert(1);

List.insert(2);

List.insert(3);

List.display();

```

- **Stacks and Queues**

- Definition and use cases of stacks.

- Basic operations on stacks: push, pop, peek.

- Definition and use cases of queues.

- Basic operations on queues: enqueue, dequeue, front, rear.

```java

// Example of Stack Operations

Import java.util.Stack;
Public class StackExample {

Public static void main(String[] args) {

Stack<Integer> stack = new Stack<>();

Stack.push(1);

Stack.push(2);

Stack.push(3);

System.out.println(“Stack: “ + stack);

Stack.pop();

System.out.println(“Stack after pop: “ + stack);

// Example of Queue Operations

Import java.util.LinkedList;

Import java.util.Queue;

Public class QueueExample {

Public static void main(String[] args) {

Queue<Integer> queue = new LinkedList<>();

Queue.add(1);

Queue.add(2);

Queue.add(3);

System.out.println(“Queue: “ + queue);

Queue.remove();

System.out.println(“Queue after remove: “ + queue);


}

```

#### Algorithms

- **Sorting Algorithms**

- Importance of sorting in computer science.

- Overview of common sorting algorithms: bubble sort, selection sort, insertion sort,
merge sort, quick sort.

```java

// Example of Bubble Sort

Public class BubbleSortExample {

Public static void bubbleSort(int[] arr) {

Int n = arr.length;

For (int I = 0; I < n – 1; i++) {

For (int j = 0; j < n – I – 1; j++) {

If (arr[j] > arr[j + 1]) {

// Swap arr[j] and arr[j + 1]

Int temp = arr[j];

Arr[j] = arr[j + 1];

Arr[j + 1] = temp;

}
Public static void main(String[] args) {

Int[] arr = {64, 34, 25, 12, 22, 11, 90};

bubbleSort(arr);

System.out.println(“Sorted array: “);

For (int num : arr) {

System.out.print(num + “ “);

```

- **Searching Algorithms**

- Importance of searching in computer science.

- Overview of common searching algorithms: linear search, binary search.

```java

// Example of Linear Search

Public class LinearSearchExample {

Public static int linearSearch(int[] arr, int key) {

For (int I = 0; I < arr.length; i++) {

If (arr[i] == key) {

Return I;

Return -1;
}

Public static void main(String[] args) {

Int[] arr = {2, 4, 0, 1, 9};

Int key = 1;

Int result = linearSearch(arr, key);

If (result == -1) {

System.out.println(“Element not found”);

} else {

System.out.println(“Element found at index: “ + result);

// Example of Binary Search

Public class BinarySearchExample {

Public static int binarySearch(int[] arr, int key) {

Int low = 0;

Int high = arr.length – 1;

While (low <= high) {

Int mid = (low + high) / 2;

If (arr[mid] == key) {

Return mid;

} else if (arr[mid] < key) {

Low = mid + 1;

} else {
High = mid – 1;

Return -1;

Public static void main(String[] args) {

Int[] arr = {2, 4, 6, 8, 10, 12, 14};

Int key = 10;

Int result = binarySearch(arr, key);

If (result == -1) {

System.out.println(“Element not found”);

} else {

System.out.println(“Element found at index: “ + result);

```

#### Practical Exercises and Mini-Project

- **Hands-on Coding Exercises**

- Writing programs to demonstrate the use of data structures and algorithms.

- Debugging and testing code, explaining common debugging techniques and tools.

- **Mini-Project: Library Management System**

- Designing a class structure for a library management system.


- Implementing functionalities like adding books, issuing books, returning books, and
searching for books.

```java

Import java.util.ArrayList;

Import java.util.List;

Class Book {

Private String title;

Private String author;

Private boolean isIssued;

Public Book(String title, String author) {

This.title = title;

This.author = author;

This.isIssued = false;

Public String getTitle() {

Return title;

Public String getAuthor() {

Return author;

}
Public boolean isIssued() {

Return isIssued;

Public void issue() {

isIssued = true;

Public void returnBook() {

isIssued = false;

Class Library {

Private List<Book> books;

Public Library() {

Books = new ArrayList<>();

Public void addBook(Book book) {

Books.add(book);

Public void issueBook(String title) {

For (Book book : books) {


If (book.getTitle().equals(title) && !book.isIssued()) {

Book.issue();

System.out.println(“Book issued: “ + title);

Return;

System.out.println(“Book not available or already issued.”);

Public void returnBook(String title) {

For (Book book : books) {

If (book.getTitle().equals(title) && book.isIssued()) {

Book.returnBook();

System.out.println(“Book returned: “ + title);

Return;

System.out.println(“Book not found or not issued.”);

Public void searchBook(String title) {

For (Book book : books) {

If (book.getTitle().equals(title)) {

System.out.println(“Book found: “ + title + “ by “ + book.getAuthor());

Return;

}
}

System.out.println(“Book not found.”);

Public class LibraryManagementSystem {

Public static void main(String[] args) {

Library library = new Library();

Library.addBook(new Book(“The Great Gatsby”, “F. Scott Fitzgerald”));

Library.addBook(new Book(“1984”, “George Orwell”));

Library.searchBook(“1984”);

Library.issueBook(“1984”);

Library.returnBook(“1984”);

```

### Week 3: Java Programming – Advanced Topics and Practical Applications

#### Introduction to Week 3

- **Overview of Week 3 Objectives**

- Deepening understanding of advanced Java programming concepts.

- Applying these concepts through practical exercises and projects.

- Enhancing problem-solving skills and coding efficiency.


#### Exception Handling

- **Introduction to Exceptions**

- Definition and importance of exception handling in Java.

- Types of exceptions: checked and unchecked exceptions.

- **Try-Catch Block**

- Syntax and usage of try-catch blocks.

- Multiple catch blocks and nested try statements.

```java

Public class ExceptionExample {

Public static void main(String[] args) {

Try {

Int[] numbers = {1, 2, 3};

System.out.println(numbers[5]); // This will throw an


ArrayIndexOutOfBoundsException

} catch (ArrayIndexOutOfBoundsException e) {

System.out.println(“Array index is out of bounds!”);

} finally {

System.out.println(“This block is always executed.”);

```
- **Throw and Throws**

- Using `throw` to manually throw an exception.

- Using `throws` to declare an exception.

```java

Public class ThrowExample {

Public static void checkAge(int age) {

If (age < 18) {

Throw new ArithmeticException(“Access denied – You must be at least 18 years


old.”);

} else {

System.out.println(“Access granted – You are old enough!”);

Public static void main(String[] args) {

checkAge(15); // This will throw an exception

```

#### File I/O

- **Introduction to File Handling**

- Importance of file handling in Java.

- Overview of java.io package.


- **Reading and Writing Files**

- Using FileReader and FileWriter classes.

- Using BufferedReader and BufferedWriter for efficient file operations.

```java

Import java.io.*;

Public class FileIOExample {

Public static void main(String[] args) {

// Writing to a file

Try (FileWriter writer = new FileWriter(“output.txt”);

BufferedWriter bw = new BufferedWriter(writer)) {

Bw.write(“Hello, World!”);

} catch (IOException e) {

e.printStackTrace();

// Reading from a file

Try (FileReader reader = new FileReader(“output.txt”);

BufferedReader br = new BufferedReader(reader)) {

String line;

While ((line = br.readLine()) != null) {

System.out.println(line);

} catch (IOException e) {

e.printStackTrace();
}

```

#### Collections Framework

- **Introduction to Collections**

- Importance of collections in Java.

- Overview of the Collections Framework: List, Set, Map, and Queue interfaces.

- **List Interface**

- ArrayList and LinkedList classes.

- Basic operations: adding, removing, and accessing elements.

```java

Import java.util.ArrayList;

Import java.util.List;

Public class ListExample {

Public static void main(String[] args) {

List<String> fruits = new ArrayList<>();

Fruits.add(“Apple”);

Fruits.add(“Banana”);

Fruits.add(“Orange”);

// Accessing elements
System.out.println(fruits.get(1)); // Output: Banana

// Removing an element

Fruits.remove(“Banana”);

// Iterating over the list

For (String fruit : fruits) {

System.out.println(fruit);

```

- **Set Interface**

- HashSet and TreeSet classes.

- Basic operations: adding, removing, and checking for elements.

```java

Import java.util.HashSet;

Import java.util.Set;

Public class SetExample {

Public static void main(String[] args) {

Set<String> animals = new HashSet<>();

Animals.add(“Dog”);

Animals.add(“Cat”);
Animals.add(“Horse”);

// Checking for an element

System.out.println(animals.contains(“Cat”)); // Output: true

// Removing an element

Animals.remove(“Cat”);

// Iterating over the set

For (String animal : animals) {

System.out.println(animal);

```

- **Map Interface**

- HashMap and TreeMap classes.

- Basic operations: adding, removing, and accessing key-value pairs.

```java

Import java.util.HashMap;

Import java.util.Map;

Public class MapExample {

Public static void main(String[] args) {


Map<String, Integer> ages = new HashMap<>();

Ages.put(“Alice”, 30);

Ages.put(“Bob”, 25);

Ages.put(“Charlie”, 35);

// Accessing a value

System.out.println(ages.get(“Alice”)); // Output: 30

// Removing a key-value pair

Ages.remove(“Bob”);

// Iterating over the map

For (Map.Entry<String, Integer> entry : ages.entrySet()) {

System.out.println(entry.getKey() + “: “ + entry.getValue());

```

#### Practical Exercises and Mini-Project

- **Hands-on Coding Exercises**

- Writing programs to demonstrate the use of exception handling, file I/O, and collections.

- Debugging and testing code, explaining common debugging techniques and tools.

- **Mini-Project: Student Management System**

- Designing a class structure for a student management system.


- Implementing functionalities like adding students, updating student information, and
displaying student details.

```java

Import java.util.ArrayList;

Import java.util.List;

Class Student {

Private String name;

Private int age;

Private String id;

Public Student(String name, int age, String id) {

This.name = name;

This.age = age;

This.id = id;

Public String getName() {

Return name;

Public int getAge() {

Return age;

}
Public String getId() {

Return id;

@Override

Public String toString() {

Return “Student{“ +

“name=’” + name + ‘\’’ +

“, age=” + age +

“, id=’” + id + ‘\’’ +

‘}’;

Class StudentManagementSystem {

Private List<Student> students;

Public StudentManagementSystem() {

Students = new ArrayList<>();

Public void addStudent(Student student) {

Students.add(student);

Public void updateStudent(String id, String newName, int newAge) {


For (Student student : students) {

If (student.getId().equals(id)) {

Students.remove(student);

Students.add(new Student(newName, newAge, id));

Break;

Public void displayStudents() {

For (Student student : students) {

System.out.println(student);

Public static void main(String[] args) {

StudentManagementSystem sms = new StudentManagementSystem();

Sms.addStudent(new Student(“Alice”, 20, “S001”));

Sms.addStudent(new Student(“Bob”, 22, “S002”));

System.out.println(“All Students:”);

Sms.displayStudents();

Sms.updateStudent(“S001”, “Alice Smith”, 21);

System.out.println(“Updated Students:”);

Sms.displayStudents();
}

``

___________________________________________

Ji### Week 4: Java Programming – GUI Development and Multithreading

#### Introduction to Week 4

- **Overview of Week 4 Objectives**

- Understanding the basics of GUI development in Java.

- Learning about multithreading and concurrency.

- Applying these concepts through practical exercises and projects.

#### Graphical User Interface (GUI) Development

- **Introduction to GUI Programming**

- Importance of GUI in application development.

- Overview of Java’s Abstract Window Toolkit (AWT) and Swing.

- **Creating a Simple GUI with AWT**

- Basic components: Frame, Button, Label, TextField.

- Event handling using ActionListener.

```java

Import java.awt.*;

Import java.awt.event.*;
Public class AWTExample {

Public static void main(String[] args) {

Frame frame = new Frame(“AWT Example”);

Label label = new Label(“Enter your name:”);

TextField textField = new TextField();

Button button = new Button(“Submit”);

Label.setBounds(50, 50, 100, 30);

textField.setBounds(160, 50, 150, 30);

button.setBounds(100, 100, 80, 30);

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.out.println(“Name: “ + textField.getText());

});

Frame.add(label);

Frame.add(textField);

Frame.add(button);

Frame.setSize(400, 200);

Frame.setLayout(null);

Frame.setVisible(true);

}
```

- **Creating a Simple GUI with Swing**

- Basic components: JFrame, JButton, JLabel, JTextField.

- Event handling using ActionListener.

```java

Import javax.swing.*;

Import java.awt.event.*;

Public class SwingExample {

Public static void main(String[] args) {

JFrame frame = new JFrame(“Swing Example”);

JLabel label = new JLabel(“Enter your name:”);

JTextField textField = new JTextField();

JButton button = new JButton(“Submit”);

Label.setBounds(50, 50, 100, 30);

textField.setBounds(160, 50, 150, 30);

button.setBounds(100, 100, 80, 30);

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.out.println(“Name: “ + textField.getText());

});
Frame.add(label);

Frame.add(textField);

Frame.add(button);

Frame.setSize(400, 200);

Frame.setLayout(null);

Frame.setVisible(true);

Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

```

#### Multithreading and Concurrency

- **Introduction to Multithreading**

- Importance of multithreading in Java.

- Overview of the Thread class and Runnable interface.

- **Creating and Running Threads**

- Extending the Thread class.

- Implementing the Runnable interface.

```java

// Extending the Thread class

Class MyThread extends Thread {

Public void run() {


For (int I = 0; I < 5; i++) {

System.out.println(Thread.currentThread().getId() + “ Value “ + i);

Public class ThreadExample {

Public static void main(String[] args) {

MyThread t1 = new MyThread();

MyThread t2 = new MyThread();

T1.start();

T2.start();

```

```java

// Implementing the Runnable interface

Class MyRunnable implements Runnable {

Public void run() {

For (int I = 0; I < 5; i++) {

System.out.println(Thread.currentThread().getId() + “ Value “ + i);

}
Public class RunnableExample {

Public static void main(String[] args) {

Thread t1 = new Thread(new MyRunnable());

Thread t2 = new Thread(new MyRunnable());

T1.start();

T2.start();

```

- **Thread Synchronization**

- Importance of synchronization in multithreading.

- Using synchronized methods and blocks.

```java

Class Counter {

Private int count = 0;

Public synchronized void increment() {

Count++;

Public int getCount() {

Return count;

}
Public class SynchronizationExample {

Public static void main(String[] args) {

Counter counter = new Counter();

Thread t1 = new Thread(new Runnable() {

Public void run() {

For (int I = 0; I < 1000; i++) {

Counter.increment();

});

Thread t2 = new Thread(new Runnable() {

Public void run() {

For (int I = 0; I < 1000; i++) {

Counter.increment();

});

T1.start();

T2.start();

Try {

T1.join();
T2.join();

} catch (InterruptedException e) {

e.printStackTrace();

System.out.println(“Count: “ + counter.getCount());

```

#### Practical Exercises and Mini-Project

- **Hands-on Coding Exercises**

- Writing programs to demonstrate the use of GUI components and multithreading.

- Debugging and testing code, explaining common debugging techniques and tools.

- **Mini-Project: Simple Chat Application**

- Designing a class structure for a simple chat application.

- Implementing functionalities like sending and receiving messages, and displaying chat
history.

```java

Import javax.swing.*;

Import java.awt.event.*;

Import java.awt.*;

Import java.util.ArrayList;
Class ChatWindow extends JFrame {

Private JTextArea chatArea;

Private JTextField inputField;

Private JButton sendButton;

Private ArrayList<String> chatHistory;

Public ChatWindow() {

chatHistory = new ArrayList<>();

chatArea = new JTextArea();

chatArea.setEditable(false);

chatArea.setBounds(20, 20, 360, 200);

inputField = new JTextField();

inputField.setBounds(20, 230, 260, 30);

sendButton = new JButton(“Send”);

sendButton.setBounds(290, 230, 90, 30);

sendButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String message = inputField.getText();

chatHistory.add(message);

chatArea.append(“You: “ + message + “\n”);

inputField.setText(“”);

});
Add(chatArea);

Add(inputField);

Add(sendButton);

setSize(400, 300);

setLayout(null);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Public class ChatApplication {

Public static void main(String[] args) {

New ChatWindow();

```

### Week 5: Java Programming – Advanced Topics and Practical Applications

#### Introduction to Week 5

- **Overview of Week 5 Objectives**

- Exploring advanced Java programming concepts.


- Applying these concepts through practical exercises and projects.

- Enhancing problem-solving skills and coding efficiency.

#### Java Networking

- **Introduction to Networking in Java**

- Importance of networking in modern applications.

- Overview of java.net package.

- **Working with Sockets**

- Understanding the concept of sockets.

- Creating a simple client-server application using sockets.

```java

// Server Program

Import java.io.*;

Import java.net.*;

Public class Server {

Public static void main(String[] args) {

Try (ServerSocket serverSocket = new ServerSocket(5000)) {

System.out.println(“Server is listening on port 5000”);

Socket socket = serverSocket.accept();

System.out.println(“Client connected”);

InputStream input = socket.getInputStream();

BufferedReader reader = new BufferedReader(new InputStreamReader(input));


String message = reader.readLine();

System.out.println(“Received: “ + message);

Socket.close();

} catch (IOException ex) {

Ex.printStackTrace();

// Client Program

Import java.io.*;

Import java.net.*;

Public class Client {

Public static void main(String[] args) {

Try (Socket socket = new Socket(“localhost”, 5000)) {

OutputStream output = socket.getOutputStream();

PrintWriter writer = new PrintWriter(output, true);

Writer.println(“Hello, Server!”);

Socket.close();

} catch (UnknownHostException ex) {

System.out.println(“Server not found: “ + ex.getMessage());


} catch (IOException ex) {

System.out.println(“I/O error: “ + ex.getMessage());

```

#### Java Database Connectivity (JDBC)

- **Introduction to JDBC**

- Importance of database connectivity in applications.

- Overview of JDBC API.

- **Connecting to a Database**

- Setting up a database connection.

- Executing SQL queries using JDBC.

```java

Import java.sql.*;

Public class JDBCExample {

Public static void main(String[] args) {

String url = “jdbc:mysql://localhost:3306/testdb”;

String user = “root”;

String password = “password”;

Try (Connection connection = DriverManager.getConnection(url, user, password)) {


String query = “SELECT * FROM users”;

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery(query);

While (resultSet.next()) {

System.out.println(“User ID: “ + resultSet.getInt(“id”));

System.out.println(“User Name: “ + resultSet.getString(“name”));

} catch (SQLException e) {

e.printStackTrace();

```

#### JavaFX for GUI Development

- **Introduction to JavaFX**

- Importance of JavaFX in modern GUI development.

- Overview of JavaFX components and layout managers.

- **Creating a Simple JavaFX Application**

- Setting up a JavaFX project.

- Creating a basic user interface with JavaFX.

```java

Import javafx.application.Application;
Import javafx.scene.Scene;

Import javafx.scene.control.Button;

Import javafx.scene.layout.StackPane;

Import javafx.stage.Stage;

Public class JavaFXExample extends Application {

@Override

Public void start(Stage primaryStage) {

Button button = new Button(“Click Me”);

Button.setOnAction(e -> System.out.println(“Button Clicked”));

StackPane root = new StackPane();

Root.getChildren().add(button);

Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle(“JavaFX Example”);

primaryStage.setScene(scene);

primaryStage.show();

Public static void main(String[] args) {

Launch(args);

```
#### Practical Exercises and Mini-Project

- **Hands-on Coding Exercises**

- Writing programs to demonstrate the use of networking, JDBC, and JavaFX.

- Debugging and testing code, explaining common debugging techniques and tools.

- **Mini-Project: Online Bookstore Application**

- Designing a class structure for an online bookstore application.

- Implementing functionalities like browsing books, adding books to the cart, and checking
out.

```java

Import javafx.application.Application;

Import javafx.scene.Scene;

Import javafx.scene.control.Button;

Import javafx.scene.control.ListView;

Import javafx.scene.layout.VBox;

Import javafx.stage.Stage;

Import java.sql.*;

Import java.util.ArrayList;

Import java.util.List;

Class Book {

Private String title;

Private String author;


Public Book(String title, String author) {

This.title = title;

This.author = author;

@Override

Public String toString() {

Return title + “ by “ + author;

Public class BookstoreApplication extends Application {

Private List<Book> books = new ArrayList<>();

@Override

Public void start(Stage primaryStage) {

ListView<Book> listView = new ListView<>();

Button loadButton = new Button(“Load Books”);

loadButton.setOnAction(e -> loadBooks(listView));

VBox vbox = new VBox(listView, loadButton);

Scene scene = new Scene(vbox, 400, 300);

primaryStage.setTitle(“Online Bookstore”);

primaryStage.setScene(scene);
primaryStage.show();

Private void loadBooks(ListView<Book> listView) {

String url = “jdbc:mysql://localhost:3306/bookstore”;

String user = “root”;

String password = “password”;

Try (Connection connection = DriverManager.getConnection(url, user, password)) {

String query = “SELECT * FROM books”;

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery(query);

Books.clear();

While (resultSet.next()) {

String title = resultSet.getString(“title”);

String author = resultSet.getString(“author”);

Books.add(new Book(title, author));

listView.getItems().setAll(books);

} catch (SQLException e) {

e.printStackTrace();

}
Public static void main(String[] args) {

Launch(args);

```

### Week 6: Java Programming – Advanced Topics and Practical Applications

#### Introduction to Week 6

- **Overview of Week 6 Objectives**

- Exploring advanced Java programming concepts.

- Applying these concepts through practical exercises and projects.

- Enhancing problem-solving skills and coding efficiency.

#### Java Networking

- **Introduction to Networking in Java**

- Importance of networking in modern applications.

- Overview of java.net package.

- **Working with Sockets**

- Understanding the concept of sockets.

- Creating a simple client-server application using sockets.

```java

// Server Program
Import java.io.*;

Import java.net.*;

Public class Server {

Public static void main(String[] args) {

Try (ServerSocket serverSocket = new ServerSocket(5000)) {

System.out.println(“Server is listening on port 5000”);

Socket socket = serverSocket.accept();

System.out.println(“Client connected”);

InputStream input = socket.getInputStream();

BufferedReader reader = new BufferedReader(new InputStreamReader(input));

String message = reader.readLine();

System.out.println(“Received: “ + message);

Socket.close();

} catch (IOException ex) {

Ex.printStackTrace();

// Client Program

Import java.io.*;

Import java.net.*;
Public class Client {

Public static void main(String[] args) {

Try (Socket socket = new Socket(“localhost”, 5000)) {

OutputStream output = socket.getOutputStream();

PrintWriter writer = new PrintWriter(output, true);

Writer.println(“Hello, Server!”);

Socket.close();

} catch (UnknownHostException ex) {

System.out.println(“Server not found: “ + ex.getMessage());

} catch (IOException ex) {

System.out.println(“I/O error: “ + ex.getMessage());

```

#### Java Database Connectivity (JDBC)

- **Introduction to JDBC**

- Importance of database connectivity in applications.

- Overview of JDBC API.

- **Connecting to a Database**

- Setting up a database connection.


- Executing SQL queries using JDBC.

```java

Import java.sql.*;

Public class JDBCExample {

Public static void main(String[] args) {

String url = “jdbc:mysql://localhost:3306/testdb”;

String user = “root”;

String password = “password”;

Try (Connection connection = DriverManager.getConnection(url, user, password)) {

String query = “SELECT * FROM users”;

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery(query);

While (resultSet.next()) {

System.out.println(“User ID: “ + resultSet.getInt(“id”));

System.out.println(“User Name: “ + resultSet.getString(“name”));

} catch (SQLException e) {

e.printStackTrace();

```
#### JavaFX for GUI Development

- **Introduction to JavaFX**

- Importance of JavaFX in modern GUI development.

- Overview of JavaFX components and layout managers.

- **Creating a Simple JavaFX Application**

- Setting up a JavaFX project.

- Creating a basic user interface with JavaFX.

```java

Import javafx.application.Application;

Import javafx.scene.Scene;

Import javafx.scene.control.Button;

Import javafx.scene.layout.StackPane;

Import javafx.stage.Stage;

Public class JavaFXExample extends Application {

@Override

Public void start(Stage primaryStage) {

Button button = new Button(“Click Me”);

Button.setOnAction(e -> System.out.println(“Button Clicked”));

StackPane root = new StackPane();

Root.getChildren().add(button);
Scene scene = new Scene(root, 300, 250);

primaryStage.setTitle(“JavaFX Example”);

primaryStage.setScene(scene);

primaryStage.show();

Public static void main(String[] args) {

Launch(args);

```

#### Practical Exercises and Mini-Project

- **Hands-on Coding Exercises**

- Writing programs to demonstrate the use of networking, JDBC, and JavaFX.

- Debugging and testing code, explaining common debugging techniques and tools.

- **Mini-Project: Online Bookstore Application**

- Designing a class structure for an online bookstore application.

- Implementing functionalities like browsing books, adding books to the cart, and checking
out.

```java

Import javafx.application.Application;

Import javafx.scene.Scene;

Import javafx.scene.control.Button;
Import javafx.scene.control.ListView;

Import javafx.scene.layout.VBox;

Import javafx.stage.Stage;

Import java.sql.*;

Import java.util.ArrayList;

Import java.util.List;

Class Book {

Private String title;

Private String author;

Public Book(String title, String author) {

This.title = title;

This.author = author;

@Override

Public String toString() {

Return title + “ by “ + author;

Public class BookstoreApplication extends Application {

Private List<Book> books = new ArrayList<>();


@Override

Public void start(Stage primaryStage) {

ListView<Book> listView = new ListView<>();

Button loadButton = new Button(“Load Books”);

loadButton.setOnAction(e -> loadBooks(listView));

VBox vbox = new VBox(listView, loadButton);

Scene scene = new Scene(vbox, 400, 300);

primaryStage.setTitle(“Online Bookstore”);

primaryStage.setScene(scene);

primaryStage.show();

Private void loadBooks(ListView<Book> listView) {

String url = “jdbc:mysql://localhost:3306/bookstore”;

String user = “root”;

String password = “password”;

Try (Connection connection = DriverManager.getConnection(url, user, password)) {

String query = “SELECT * FROM books”;

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery(query);

Books.clear();
While (resultSet.next()) {

String title = resultSet.getString(“title”);

String author = resultSet.getString(“author”);

Books.add(new Book(title, author));

listView.getItems().setAll(books);

} catch (SQLException e) {

e.printStackTrace();

Public static void main(String[] args) {

Launch(args);

```

You might also like