0% found this document useful (0 votes)
35 views15 pages

Edu Bridege

The document contains a series of programming assignments and code snippets related to Java, covering topics such as basic arithmetic operations, object-oriented programming, SQL database connections, and lambda expressions. It includes various Java classes demonstrating concepts like method overloading, abstraction, and functional interfaces. Additionally, it provides links to resources and examples for further learning in Java programming.

Uploaded by

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

Edu Bridege

The document contains a series of programming assignments and code snippets related to Java, covering topics such as basic arithmetic operations, object-oriented programming, SQL database connections, and lambda expressions. It includes various Java classes demonstrating concepts like method overloading, abstraction, and functional interfaces. Additionally, it provides links to resources and examples for further learning in Java programming.

Uploaded by

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

Date: 07/08/2023

shubham patil:==
Enrollment Number :
EBEON0823830336
Batch :
2023-10232
Enlorment no:_---EBEON0823830344
ECLIPSE ZIP:
https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/
release/2023-06/R/eclipse-jee-2023-06-R-win32-x86_64.zip&mirror_id=1142

public class Addintion {

public static void main(String[] args) {


int i,j,s;
i=15;
j=20;
s=i+j;
//The sum of 10 and 20 is 30
System.out.println("The sum of "+i+" and "+j+" is "+s);

Homework:
subtration, multiplicatio, division /, %
area of square, reactangle, triangle and circle

Date: 08/08/2023
PPT on Java Architecture

Date: 10/08/2023
1. Program to check the given number positive or negative
2.Program to check the given number is odd or even
3.Program to find the largest 2 numbers using if else

Date: 11/08/2023
package com.edu;

import java.util.Scanner;

public class ElectricityBill {

public static void main(String[] args) {


//name and units->input
//output->billamount

String name;
int units;
float amount;

Scanner sc = new Scanner(System.in);


System.out.println("Enter customer name");
name=sc.nextLine();

System.out.println("Enter units consumed");


units = sc.nextInt();
//first 200 units

if(units>=0 && units<=200) { //0 to 200

amount = units * 3.80f;


}

//more than 200 and upto 300 // 250 = 200*3.80 + (units-200)*4.40f;


//200*3.80f +(unints
%200)*4.40

else if(units>200 && units<=300) {


amount = 200 * 3.80f+(units-200)*4.40f;

}
else if(units>300 && units<=400) {
amount = 200*3.80f+100*4.40f+(units-300)*5.10f;
}
else {
amount = 200*3.80f+100*4.40f+100*5.10f+(units-400)*5.80f;
}

System.out.println("Customer Name:"+name);
System.out.println("Units Consumed "+units);
System.out.println("Amount to pay Rs."+amount);

Date- 17/08/2023
1.program to find sum of all array elements
2.to find the average of all array elements
3.find larget of all array elements
4.find the smallest of all array elements
5. Find the elements exists in given array(linear search)
6.find 2nd largest element from the given array
(Bubble sort)

package com.edu;

import java.util.Scanner;

public class TwoDimensional {

public static void main(String[] args) {


int arr[][]=new int[3][3];
Scanner sc = new Scanner(System.in);

System.out.println("Enter 3x3 matrix");

for(int r=0;r<3;r++) {
for(int c=0;c<3;c++) {
arr[r][c]=sc.nextInt();
}
}

System.out.println("Enterd matrix is ");


for(int r=0;r<3;r++) {
for(int c=0;c<3;c++) {
System.out.print(arr[r][c]+" ");
}
System.out.println();
}

Date- 18/08/2023

1 program to count no of vowels in a given word


2 write a program to count no of words
3
Ex: Manoj Hankare
o/p: M.K

Mahathma Karamachand Gandhi


M.K.Gandhi

write a program to check username and password is valid


name="admin";
pass="admin123";

public static void main(String[] args) {

String s1 ="Mahatma Karamchad Gandhi";


String s2 ="";
s2 = s1.charAt(0)+ "."; // M.
System.out.print(s2);

int pos = s1.indexOf(' ');

s2 =s1.charAt(pos +1)+ "."; // M.K.


int l = s1.lastIndexOf(' ');

String ls = s1.substring( l + 1);


s2 = s2+ls; // M.K.Gandhi

System.out.print(s2);
}
}
package com.edu;

import java.util.Scanner;

public class ReverseNumber {

public static void main(String[] args) {


// TODO Auto-generated method stub

int num;
Scanner sc = new Scanner(System.in);

System.out.println("Enter number");
num = sc.nextInt();

String str = String.valueOf(num); //"572789"

// for(int i=str.length()-1;i>=0;i--) {
// System.out.print(str.charAt(i));
// }

StringBuffer strb=new StringBuffer(str);


System.out.println(strb.reverse().toString());

Date= 21/08/2023

package com.edu;

class Addition{
void add(int i, int j){
int s=i+j;
System.out.println("Integer addition s="+s);
}
void add(short i, short j){
short s=(short) (i+j);
System.out.println("short addition s="+s);
}
void add(long i, long j){
long s=i+j;
System.out.println("long addition s="+s);
}
void add(byte i, byte j){
byte s=(byte) (i+j);
System.out.println("byte addition s="+s);
}
void add(float i, float j){
float s=i+j;
System.out.println("float addition s="+s);
}
void add(double i, double j){
double s=i+j;
System.out.println("double addition s="+s);
}
}

public class MainOverload{


public static void main(String args[]){
Addition ob=new Addition();
ob.add(76,89);
ob.add((short)4,(short)8);
ob.add((byte)76,(byte)89);
ob.add(76l,89l);
ob.add(76.3f,89.2f); //
ob.add(76.3,89.2); //double

}
}
---------------------------------------------------------

void display(int i){


}
void display(int i , int j){
}

void display(int i, int j, int k){


}
Function overloading based on number of arguments
void display(int i){
}
void display(int i , int j){
}

void display(int i, int j, int k){


}
______________________________________________
//function overloading by interchaging the argument datatype
void display(int i, float j){
}

void display(float i , int j){


}

Date 24/08/2023

Abstraction
public class BankMain{
public static void main(String args[]){
Bank bob;
//HdfcBank hob=new HdfcBank();

bob=new HdfcBank();

System.out.println("Rate of interest of Hdfc


"+bob.rateOfInterest());
//SbiBank sob=new SbiBank();
bob=new SbiBank();
System.out.println("Rate of interest of SBI
"+bob.rateOfInterest());
//CitiBank cob=new CitiBank();
bob=new CitiBank();
System.out.println("Rate of interest of Citi
"+bob.rateOfInterest());
}
}

java links:::::https://vtuupdates.com/vtu/21csl35-java-laboratory-solutions/

Date 24/08/2023
class Mobile {
void ringTone() {
System.out.println("Default RingTone");
}

void theme() {
System.out.println("Default Theme");
}
//final method cannot be overriden
final void ram() {
System.out.println("4GB RAM");
}
}

class MyMobile extends Mobile{


@Override
void ringTone() {
System.out.println("My RingTone");
}

// @Override
// void ram() {
// System.out.println("8GB RAM");
// }

class Car{

void start() {
System.out.println("START");
}

void move() {
System.out.println("MOVE");
}

void stop() {
System.out.println("STOP");
}
}

class MyCar extends Car{

abstract class Vehicle {


String colour;
Vehicle(String colour) {
System.out.println("Vehicle Constructor");
this.colour = colour;
}

Vehicle() {
System.out.println("ZERO AURG CONSTURUCTOR");
}

abstract void wheels();

void start() {
System.out.println("START");
}
}

void move() {
System.out.println("MOVE");
}

void stop() {
System.out.println("STOP");
}

class Bike extends Vehicle{

Bike(String colour) {
super(colour);

@Override
void wheels() {
System.out.println("TWO WHEELS");

class Auto extends Vehicle{

@Override
void wheels() {
System.out.println("THREE WHEELS");

public class OverridingDemo {

public static void main(String[] args) {

// MyMobile mob = new MyMobile();


// mob.ringTone();
// mob.theme();
// mob.ram();
// Mobile m1 = new Mobile();
// m1.ram();
Bike bike = new Bike("red");
bike.start();

package com.edu;
import java.io.*;
import java.util.*;
public class OccurrenceOfChar{
static void count_characters(String input_str){
HashMap<Character, Integer> my_map = new HashMap<Character, Integer>();
char[] str_array = input_str.toCharArray();
for (char c : str_array){
if (my_map.containsKey(c)){
my_map.put(c, my_map.get(c) + 1);
}else{
my_map.put(c, 1);
}
}
for (Map.Entry entry : my_map.entrySet()){
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
public static void main(String[] args){
String my_str = "Joe Erien ";
System.out.println("The occurence of every character in the string is ");
count_characters(my_str);
}
}

Date= 05/09/2023

Interface and lambada expression

package com.edu;

@FunctionalInterface
interface Message{
void display();

public class MainApp {

public static void main(String[] args) {


//no argument and no return type
//Lambda expression can be applied only for functional interface
//which has single abstract method
Message mob=()->{
System.out.println("Display method called");
};

mob.display();

Message mob1=()->System.out.println("Display method");


mob1.display();

package com.edu;
@FunctionalInterface
interface Subtraction{
int sub(int i, int j);
}

public class MainApp2 {

public static void main(String[] args) {


Subtraction sobj=(i,j)->{
int ans;
ans = i-j;
return ans;
};
System.out.println("differene="+sobj.sub(4, 1));

Subtraction s1=(i,j)->(i-j);
System.out.println("difference "+s1.sub(6, 2));
}

package com.edu;

@FunctionalInterface
interface Message{
void display();

}
@FunctionalInterface
interface Addition{
void add(int a, int b);
}

public class MainApp {

public static void main(String[] args) {


//no argument and no return type
//Lambda expression can be applied only for functional interface
//which has single abstract method
Message mob=()->{
System.out.println("Display method called");
};

mob.display();

Message mob1=()->System.out.println("Display method");


mob1.display();

//with argument and no return type


Addition aob=( i,j)->{
int s=i+j;
System.out.println("sum="+s);
};
aob.add(9, 3);
Addition aob1=(i, j)->System.out.println("sum="+(i+j));
aob1.add(19, 3);
}
}

Date = 13/09/2023

Sana Samani to Everyone 15:17


Okay ma'am

Indrakka Mali to Everyone 15:26


<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>

Indrakka Mali to Everyone 15:39


package com.edu;

import java.sql.Connection;
import java.sql.DriverManager;

public class UserLoginDetails {

public static void main(String[] args) {


String driver="com.mysql.cj.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/10223_10224_10225db";
String un="root";
String pass="root";

//1. Load the driver


//2.Make the connection
//3.create a statement object
//execute or executeUpdate()

try {
//1. Load the driver
//Class.forName("com.mysql.cj.jdbc.Driver");
Class.forName(driver);
Connection conn=DriverManager.getConnection(url,un,pass);
if(conn!=null) {
System.out.println("connection established");

}
else {
System.out.println("Not connected");
}

}catch(Exception e) {
e.printStackTrace();
}

Indrakka Mali to Everyone 15:50


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class UserLoginDetails {

public static void main(String[] args) {


String driver="com.mysql.cj.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/10223_10224_10225db";
String un="root";
String pass="root";

//1. Load the driver


//2.Make the connection
//3.create a statement object
//execute or executeUpdate()

try {
//1. Load the driver
//Class.forName("com.mysql.cj.jdbc.Driver");
Class.forName(driver);
Connection conn=DriverManager.getConnection(url,un,pass);
if(conn!=null) {
System.out.println("connection established");
Statement st=conn.createStatement();
String sql= "select * from login";
ResultSet rs=st.executeQuery(sql);
w
while(rs.next()){
//getInt
//getFloat
//System.out.println(rs.getString("emailid")+"
"+rs.getString("password"));
System.out.println(rs.getString(1)+" "+rs.getString(2));
}

}
else {
System.out.println("Not connected");
}

}catch(Exception e) {
e.printStackTrace();
}

Indrakka Mali to Everyone 16:47


package com.edu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
public class GetRecordBasedEmailID {

public static void main(String[] args) {


String driver="com.mysql.cj.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/10223_10224_10225db";
String un="root";
String pass="root";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
Scanner sc=new Scanner(System.in);

try {
//load the driver
Class.forName(driver);
//Make the connection
conn = DriverManager.getConnection(url,un,pass);
//create a Statement
stmt = conn.createStatement();
System.out.println("Enter email id");
String em=sc.next();
//select * from login where emailid='[email protected]'
String s="select * from login where emailid='"+em+"'";
rs = stmt.executeQuery(s);
if(rs.next()) {
System.out.println("user exists with email id
"+rs.getString("emailid"));
}
else {
System.out.println("User not exists with email id ="+em);
}
}catch(Exception e) {
e.printStackTrace();
}

}
package com.edu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class GetRecordBasedEmailID {

public static void main(String[] args) throws SQLException {


String driver="com.mysql.cj.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/10223_10224_10225db";
String un="root";
String pass="root";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
Scanner sc=new Scanner(System.in);

try {
//load the driver
Class.forName(driver);
//Make the connection
conn = DriverManager.getConnection(url,un,pass);
//create a Statement
stmt = conn.createStatement();
System.out.println("Enter email id");
String em=sc.next();
//select * from login where emailid='[email protected]'
String s="select * from login where emailid='"+em+"'";
rs = stmt.executeQuery(s);
if(rs.next()) {
System.out.println("user exists with email id
"+rs.getString("emailid"));
}
else {
System.out.println("User not exists with email id ="+em);
}
}catch(Exception e) {
e.printStackTrace();
}
finally {
stmt.close();
rs.close();
conn.close();
}

Indrakka Mali to Everyone 17:01


package com.edu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class UpdatePassword {

public static void main(String[] args) throws SQLException {


String driver="com.mysql.cj.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/10223_10224_10225db";
String un="root";
String pass="root";
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
Scanner sc=new Scanner(System.in);

try {
//load the driver
Class.forName(driver);
//Make the connection
conn = DriverManager.getConnection(url,un,pass);
//create a Statement
stmt = conn.createStatement();
System.out.println("Enter email id");
String em=sc.next();
//select * from login where emailid='[email protected]'
String s="select * from login where emailid='"+em+"'";
rs = stmt.executeQuery(s);
if(rs.next()) {
//System.out.println("user exists with email id
"+rs.getString("emailid"));
System.out.println("Enter password to change");
String upass=sc.next();
String pu="update login set password='"+upass+"' where
emailid='"+em+"'";
int i=stmt.executeUpdate(pu);
if(i>0) {
System.out.println("Password changed successfully");
}else {
System.out.println("Error occurred");
}
}
else {
System.out.println("User not exists with email id ="+em);
}
}catch(Exception e) {
e.printStackTrace();
}
finally {
stmt.close();
rs.close();
conn.close();
}

Date= 14/09/2023
https://edubridgeindia.zoom.us/j/2335853210

@NotBlank(message = "Department name should not be blank")

pagadala eshwar kumar to Everyone 15:10


mam his system got shutdown

Indrakka Mali to Everyone 15:18


ValidateHandler
@ControllerAdvice
public class ValidateHandler extends ResponseEntityExceptionHandler {
@Override
protected ResponseEntity<Object>
handleMethodArgumentNotValid(MethodArgumentNotValidException ex,
HttpHeaders headers, HttpStatus status, WebRequest request) {
Map<String,String> errors = new HashMap<>();
ex.getBindingResult().getAllErrors().forEach((error) ->{
String fieldName = ((FieldError) error).getField();
String message = error.getDefaultMessage();
errors.put(fieldName, message);
});

return new ResponseEntity<Object> (errors,HttpStatus.BAD_REQUEST);


}

}
import java.util.HashMap;
import java.util.Map;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandle
r;

You might also like