0% found this document useful (0 votes)
15 views7 pages

Comprehensive Java Notes UMS

Uploaded by

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

Comprehensive Java Notes UMS

Uploaded by

ilakoulbv2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Comprehensive Java Notes for

University Management System


1. Core Java Fundamentals

Java is a platform-independent, object-oriented programming language. At its core are basic


constructs like data types,
control statements, operators, and methods which form the building blocks of every
program.

1.1 Data Types

Java provides two categories of data types:


1. Primitive Data Types:
- byte (8-bit), short (16-bit), int (32-bit), long (64-bit)
- float (32-bit), double (64-bit)
- char (16-bit Unicode character)
- boolean (true/false)
2. Non-Primitive (Reference) Data Types:
- String, Arrays, Objects, Classes

Example:

int rollno = 101;


String name = "Ila";
float percentage = 85.6f;
boolean passed = true;

1.2 Control Statements

Control statements define the flow of execution in Java programs:


- if-else statements
- switch-case
- loops (for, while, do-while)
- break and continue
Example:

int marks = 75;


if(marks >= 40) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}

1.3 Methods

Methods allow code reusability by grouping statements into callable units.


- Syntax:
returnType methodName(parameters) { ... }
- Types: static methods, instance methods, constructors

Example:

public int add(int a, int b) {


return a+b;
}

2. Object-Oriented Programming

Java is fully object-oriented and follows OOP principles: Encapsulation, Inheritance,


Polymorphism, and Abstraction.
These help in modularity, reusability, and maintainability of code.

2.1 Encapsulation

Encapsulation means restricting direct access to class data using private fields and exposing
them via getters/setters.

class Student {
private String name;
public void setName(String n){ name = n; }
public String getName(){ return name; }
}

2.2 Inheritance

Inheritance allows one class to acquire properties of another. In Java, this is achieved using
the 'extends' keyword.

class Person { String name; }


class Student extends Person { int rollno; }

2.3 Polymorphism

Polymorphism allows one interface with multiple implementations.


- Compile-time (method overloading)
- Runtime (method overriding)

class Calculator {
int add(int a, int b){ return a+b; }
double add(double a, double b){ return a+b; } // overloading
}

class Animal { void sound(){ System.out.println("Animal sound"); } }


class Dog extends Animal { void sound(){ System.out.println("Bark"); } } // overriding

2.4 Abstraction

Abstraction hides implementation details and shows only essential features.


Implemented using abstract classes and interfaces.

abstract class Shape { abstract void draw(); }


class Circle extends Shape { void draw(){ System.out.println("Drawing Circle"); } }
3. Exception Handling

Exceptions handle runtime errors gracefully. Mechanisms include try-catch, throw, throws,
and finally.

try {
int x = 10/0;
} catch(ArithmeticException e) {
System.out.println("Error: "+e);
} finally {
System.out.println("Always executes");
}

Custom Exception Example:

class InvalidAgeException extends Exception {


InvalidAgeException(String msg){ super(msg); }
}

4. Collections Framework

Collections provide dynamic data structures for storing and manipulating groups of objects.
Main Interfaces: List, Set, Map.

4.1 List

ArrayList<String> list = new ArrayList<>();


list.add("Alice");
list.add("Bob");
for(String s: list){ System.out.println(s); }

4.2 Set

HashSet<Integer> set = new HashSet<>();


set.add(1);
set.add(2);

4.3 Map

HashMap<Integer,String> map = new HashMap<>();


map.put(1,"CSE");
map.put(2,"ECE");

5. Java I/O

I/O in Java allows reading/writing files and serializing objects.

FileWriter fw = new FileWriter("out.txt");


fw.write("Hello World");
fw.close();

BufferedReader br = new BufferedReader(new FileReader("out.txt"));


System.out.println(br.readLine());

6. Java Swing (UI)

Swing provides GUI components in Java: JFrame, JButton, JLabel, JTable.

JFrame f = new JFrame("Demo");


JButton b = new JButton("Click");
b.setBounds(50,100,80,30);
f.add(b);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);

b.addActionListener(e -> System.out.println("Button clicked"));


7. JDBC (Database Connectivity)

Steps to connect Java with MySQL:


1. Load driver
2. Establish connection
3. Create statement
4. Execute query
5. Close connection

Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/university","root","password"
);
String query = "INSERT INTO student VALUES(?,?,?,?)";
PreparedStatement ps = con.prepareStatement(query);
ps.setInt(1,1);
ps.setString(2,"Ila");
ps.setString(3,"CSE");
ps.setInt(4,3);
ps.executeUpdate();

8. SQL Queries for UMS

CREATE TABLE student(rollno INT PRIMARY KEY, name VARCHAR(50), course


VARCHAR(50), branch VARCHAR(50));
INSERT INTO student VALUES(1,'Ila','CSE','AI');
SELECT * FROM student WHERE rollno=1;
UPDATE student SET course='ECE' WHERE rollno=1;
DELETE FROM student WHERE rollno=1;

9. Advanced Topics

- Multithreading: run multiple tasks simultaneously.


class MyThread extends Thread {
public void run(){ System.out.println("Thread running"); }
}

- Synchronization: ensures thread safety.


synchronized void print(){ ... }

- Lambda Expressions: introduced in Java 8, simplify anonymous classes.


(a,b) -> a+b;

- Stream API: process collections in functional style.


list.stream().filter(x->x.startsWith("A")).forEach(System.out::println);

You might also like