Master for Micro service spring boot JAVA complete live project
Rough Note: Java Micro Service Full Video with Code
- It includes Basic Java concept
- It includes different java basic, core concept
- It has complete Spring boot project code. and many more
Rough Note: Java Micro Service Full Video with Code
- It includes Basic Java concept
- It includes different java basic, core concept
- It has complete Spring boot project code. and many more
*******************************************************************************************************************************
1st class
Important Intellij Shortcut (click me for more short-cut):
In windows
psvm :public static void main(String[] args) {}
psvm :public static void main(String[] args) {}
sout: System.out.println();
shift + 10 ==> execute program
Alt + Insert ==> Generate Getter and setter
Alt + Insert ==> Create New class, package
Alt + Ctrl + L ==> Formatting code
Alt + Enter ==> Import
Alt + Ctrl + O == > Import all
Alt + Insert ==> Create New class, package
Alt + Ctrl + L ==> Formatting code
Alt + Enter ==> Import
Alt + Ctrl + O == > Import all
- java jdk1.8 and intellij idea download
- method- 1st letter starts from small leter..parameter ....void doesnot have return type... void is return type..
static - allows aceess directly without creating object
main method is a special-
system is a class, (out - variable or method, print- method)
.....................................................
Data types: primitimve and complex
8 types of primitive:
- 1. Boolean data type, - 1 bit
- 2. byte date type , - 1 byte, 128- to 127 --> 8 bits --> 2 pow 8 --> 256
- 3. char data type, - 2 byte
- 4. short data type, 2 byte --> 2 pow 16
- 5. int data type , - 4 byte
- 6. long data type, - 8 byte
- 7. float data type , ( decimal value) - 4 byte
- 8. double data type. ( decimal) - 8 byte
Boolean is data type which hold the data true or false.
Non primitive data type:
Stirng " manoj" ;
public class FirstDay {
public static void main(String[] args) {
// primitive data type
boolean isThisValueTrue = true; // decleare variable
int i = 10;
double m = 2.4;
int k = 4;
int d = i + k;
char c = 'a';
// Non - primitive data type
String s = "Manoj";
System.out.println("Value of Variable: " + isThisValueTrue +
"print int: " + i + m + c + "print stirng: "+ s + "sum: " + d );
}
}
/*
OUTPUT
* Value of Variable: trueprint int: 102.4aprint stirng: Manojsum: 14
*/
**************************************************************************************************************************************************
2nd class
**************************************************************************************************************************************************
Operators type: catagory, precedence
unary, postfix exp++ expr --
prifix ++ expr -expr +expr -expr
arithmatic multiplicative * % /
additive + -
shift shift << >> >>>>
rational comparison < > <= >= instance
equality == !=
logical AND $$
logical OR ||
ternary ? :
assogmmennt : = += -= /+
urinary: 1 oprand / operator eg: ++ used postfix or prefix
Binary : 2 operand
Ternary: 3 operand
postfix"
prefix
public class Day2 {
public static void main(String[] args) {
int a = 5;
a++; // add 1 value
++a; // add 1 value
System.out.println(a); // ouput 7
int b = 10;
// int c = b--; // output of c is 10. value assign first
int d = --b; // output of d is 9. assign value change
// System.out.println(c); // ouptput is 10
System.out.println(d); //output is 9
boolean k = true;
boolean m = !k;
System.out.println(m); // output: false
// arithmatic operator
int y = 10;
int x = 4;
int z = 8;
System.out.println(y%x);// output: 2
System.out.println(y>x); // relational operator: output: true
System.out.println(x!=y);// output: true
// logical operator is used for two boolean
System.out.println(y>x && x!=y);// both condition should be true, output: true
System.out.println(y>x || x>z);// either one condition is true, output: true
// turniary --> writing two condition : syntex: condition ? <true statement: < false statement;
System.out.println(y>x ? true : false); // output : true
System.out.println(y>x ? z : false); // output : 8
// assignment operator
}
}
*******************************************************************************************************************************
3rd class
*******************************************************************************************************************************
// Conditional Statements
// if else
// switch case
public class Day2i {
/*
Conditional Statements
if else
switch case
*/
public static void main(String[] args) {
int a = 5;
int b = 10;
int c = 89;
if(a > b && a > c){
System.out.println(" a is greater than b");
}else if(b>c){
System.out.println(" b is greater than a");
}else{
System.out.println("c is greater");
}
}
}
public class Day2i {
/*
Conditional Statements
if else
switch case
*/
public static void main(String[] args) {
int day =4;
switch (day){
case 1:
System.out.println("sunday");
break;
case 2:
System.out.println("monday");
break;
case 3:
System.out.println("tuesday");
break;
case 4:
System.out.println("wednesday");
break;
case 5:
System.out.println("thursday");
break;
case 6:
System.out.println("friday");
break;
default:
System.out.println("saturday");
}
}
}
/*
output: wednesday
*/
Read:
SPRINT, Hybernet, how does it works on web development
sprint: helps you design create server and server site code, writing business use cases, logic
hybernet: use connecting server with data base.
assignment even or odd
public class Day3 {
public static void main(String[] args) {
int a =20, b = 31, c = 32;
System.out.println( a%2==0 && b%2==0&&c%2==0 ? "even" : "odd");
}
}
How to compile file on Java C compiler:...
go to terminal on the bottom on InteliJ and type javac Day3.java
C:\Users\Manoj Adhikari\Downloads\demo\com.java.firstProject\src>cd main
C:\Users\Manoj Adhikari\Downloads\demo\com.java.firstProject\src\main>cd java
C:\Users\Manoj Adhikari\Downloads\demo\com.java.firstProject\src\main\java>javac Day3.java
C:\Users\Manoj Adhikari\Downloads\demo\com.java.firstProject\src\main\java>java DAy3.java
==> file execute
// for, while, do while , advanced for loop
// for loop
/*
for (initialize statement: condition : statement){
body of the loop
}
1. intialize statement
2. codniton: evalutate the conditon
3. body of the loop
4. statement: increment/decrement statement
*/
// do while, for, nested loop, control statement: break continue.
//asssignment:
print first 5 odd numbers,
sum, mul of (5 even, odd numbers)
check if a number is prime or not,
calculate pow of given number (m to the power n)
print fab series first n number
calculate factorial of a number
public class Day3 {
/*
// Assignment:
//even
int a =20, b = 31, c = 32;
System.out.println( a%2==0 && b%2==0&&c%2==0 ? "even" : "odd");
// odd
System.out.println( a%2!=0 && b%2!=0&&c%2!=0 ? "even" : "odd");
*/
public static void main(String[] args) {
// for, while, do while , advanced for loop
// for loop
// control statement : break , contiue
/*
for (initialize statement: condition : statement){
body of the loop
}
1. intialize statement
2. codniton: evalutate the conditon
3. body of the loop
4. statement: increment/decrement statement
*/
//for loop
for (int count=0; count <5; count++){
if (count ==3){
/*
break;
Output: My name is Nick:0
My name is Nick:1
My name is Nick:2
*/
continue;
/*
output: My name is Nick:0
My name is Nick:1
My name is Nick:2
My name is Nick:4
*/
}
System.out.println("My name is Nick:" + count);
}
}
}
package JavaTraining.Assignment;
public class Assignment2aOddNumber {
public static void main(String[] args) {
int n = 10;
System.out.println("Odd number are: ");
for(int i = 1; i <= n; i ++){
if(i%2!=0){
System.out.print(i + " ");
}
}
}
}
/*
OUTPUT:
Odd number are:
1 3 5 7 9
*/
package JavaTraining.Assignment;
public class Assignment2bEvenNumber {
public static void main(String[] args) {
int n = 10;
System.out.println("The even numbers are: ");
for (int i = 1; i <= n; i ++){
if (i%2==0){
System.out.print(i +" ");
}
}
}
}
/*
OUTPUT:
The even numbers are:
2 4 6 8 10
*/
package JavaTraining.Assignment;
public class Assignment2cFactorial {
public static void main(String[] args) {
int n = 5;
int fact =1; // 5*4*3*2
for (int count =2; count <= n; count++){
fact = fact*count;
}
System.out.println(fact);
}
}
//output: 120
package JavaTraining.Assignment;
public class Assignment2dSumOfEvenNumber {
public static void main(String[] args) {
int n =10, sum = 0;
for(int i = 1; i <=n; i++){
if(i%2==0){
sum=sum+i;
}
}
System.out.println("sum of even number upto " + n + " = " + sum );
}
}
//Output: sum of even number upto 10 = 30
package JavaTraining.Assignment;
public class Assignment2eSumofOddNumber {
public static void main(String[] args) {
int n = 10, sum = 0;
for(int i =1; i<=n; i++){
if(i%2!=0){
sum = sum +i;
}
}
System.out.println("Sum of odd number upto :" + n + " = " + sum);
}
}
//output: Sum of odd number upto :10 = 25
package tutorial;
public class SumOf10OddNumbers {
public static void main(String[] args) {
int number = 10, sum = 0;
for (int i = 1; i <= number; i++) {
sum += (2*i)-1;
}
System.out.print("sum of odd number up to " + number + " = "+ sum);
}
}
// OUtput: sum of odd number up to 10 = 100
package tutorial;
public class SumOf10Numbers {
public static void main(String[] args) {
int number = 10, sum=0;
for (int i = 1; i <= number ; i++) {
sum = sum + i *2;
}
System.out.println("sum of even number upto " + number + " = " + sum);
}
}
package classTutorial;
public class Day4 {
//nested loop
/*
<initialization>
while(<condition>){
//body of loop
<update>}
*/
/*
do {
//statement
} while (<condition>);
*/
public static void main(String[] args) {
int number = 0;
// while(number < 5){
// System.out.print( number);
// number++;
// }
do {
System.out.print(number);
number ++;
}while (number < 5);
}
}
package classTutorial;
public class Day4NestedLoop {
public static void main(String[] args) {
int n = 5;
for (int line = n; line >= 1 ; line--) {
//print the space
for (int s = 1; s < n - line ; s++) {
System.out.print(" ");
}
//print the starts
for (int i = 1; i <= line; i++) {
System.out.print("*");
}
//print next line
System.out.println();
/*
output:
****
***
**
*/
/*
for (int line = 5; line >= 1 ; line--) {
for (int i = 1; i <= line; i++) {
System.out.print("*");
}
System.out.println();
output:
*****
****
***
**
*
*/
/*
for (int line = 1; line <= 5 ; line++) {
for (int i = 1; i <= line; i++) {
System.out.print("*");
}
System.out.println();
output:
*
**
***
****
*****
*/ }
}
}
Assignment:
1
12
123
1234
1
12
123
1234
1
23
456
1 1
12 21
123321
==> hints
on ith line
i numbers;
2*(n-i) is space
i numbers,
1 2 4 8 16 32
package tutorial;
public class ReverseString {
public static void main(String[] args) {
String name = "Manoj";
// convert String to character array
// by using toCharArray
char[] man = name.toCharArray();
for (int i = man.length-1; i >= 0 ; i--) {
System.out.print(man[i]);
}
}
}
package tutorial;
import java.util.Scanner;
public class ReverseNumber {
public static void main(String[] args) {
int n, reverse = 0;
System.out.println("Enter an integer to reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while(n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println("Reverse of the number is " + reverse);
}
}
*******************************************************************************************************************************
4th class
*******************************************************************************************************************************
//Example of Nested loop
package classTutorial;
public class Day5NestedLoop {
public static void main(String[] args) {
int n = 5;
//print increment order: 12345
for (int line = 1; line <= n; line++) {
int no = 1;
for (no = 1; no <=line;no++){
System.out.print(no);
}
/*
1........1
12......21
123....321
1234..4321
1234554321
*/
//print the spaces
for (int s = 1;s <= 2*(n-line); s++){
System.out.print(" ");
}
//print decrement order: 54321
for (no = line; no >=1;no--){
System.out.print(no);
}
//change the line
System.out.println();
}
}
}
/*
output:
1 1
12 21
123 321
1234 4321
1234554321
*/
package tutorial;
public class nestedUnderstood {
public static void main(String[] args) {
for (int n=1;n<=5;n++) // for 5 loops
{
for (int s=1;s<=n;s++) // to display values
{
System.out.print(s);
}
System.out.println();// for line break
}
}
}
/*
output:
1
12
123
1234
12345
*/
package classTutorial;
public class Day5aVector {
public static void main(String[] args) {
//Arrays: any primitve and complex data type
// int a[] = {1,2,3,4};
//one dimentional arrays
int a[] = new int[5]; //alocated 5 arraysize and defalt value is zero
a[0] =15;
a[4]=234;
//lenght of array is 4.
for (int i = 0; i < a.length ; i++) {
System.out.println(a[i]);
}
}
}
package classTutorial;
public class Day5bArrays {
public static void main(String[] args) {
//arrays of arrays
int a[][] = new int[2][];
a[0] = new int[5];
a[0][0] =1;
a[0][4]=5;
a[1]=new int[3];
a[1][0]=11;
a[1][2]=3;
for (int i = 0; i <a.length ; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}
package classTutorial;
public class Day5Arrays {
public static void main(String[] args) {
//advanced for loop
// int a[] = {1,2,3,4};
//character arrays
char a[] = {'a','b','c'};
for (char i : a){
System.out.println(i);
}
}
}
/*
output:
a
b
c
*/
/*can not directly call this function which is non static
//create an object of the class, then call the fucntion with the object
//Static method- you do not need to create object of the class, you can call directly
***IMPORTANT****
static , non static call
package classTutorial;
public class Day5eMethods {
public static void main(String[] args) {
/*can not directly call this function which is non static
hello();
*/
//create an object of the class, then call the fucntion with the object
Day5eMethods man = new Day5eMethods();
man.hello();
//Static method- you do not need to create object of the class, you can call directly
heli();
/* -creating static class inside class
-there is no object of Hi class to call the method
-HI is for reference to find which method to call
*/
Hi.heolloStatic();
}
//Non static method
void hello() {
// system is a class name. println is static method. so you are able to method
System.out.println("manoj");
}
static void heli() {
System.out.println("i am static: No need to create object for static method");
}
}
class Hi {
//static method
static void heolloStatic() {
System.out.println("No need to create object for static method");
}
}
package classTutorial;
public class Day5MethodInside {
public static void main(String[] args) {
print("hi i am hungry");
printNumber(12344);
add(6,8);
}
//string passing value
static void print(String s){
System.out.println(s);
}
static void printNumber(int n){
System.out.println(n);
}
static void add(int a, int b){
int sum = a + b;
System.out.println(sum);
}
}
// move all the preivious programs in to functions
*******************************************************************************************************************************
6th class
*******************************************************************************************************************************
Anything starts from capital is class. anything starts from small with () its method. and others are variables eg sum is variable....
package classTutorial;
// class name always starts with capital letter
//varialbe and methods start with small letter
//rest of camel case
public class Day6 {
/*
class - anything which starts from capital is a class
eg:System, String,Class name
method: anything which starts from small and have bracket called method eg. add(), print()
other than that is variable.
*/
public static void main(String[] args) {
int s = additionOfTwoNumber(6,8);
System.out.println(s);
}
//Method can take multiple inputs but can return only one value
//always give a meaningful name to function
// so that even without looking at the body of function
// you should be able to figure out what it does
static int additionOfTwoNumber(int a, int b) {
int sum = a + b;
return sum;
}
}
package classTutorial;
public class Day6ClassObject {
public static void main(String[] args) {
/*object oriented language - any language has encapsulation, inheritance, and.. called
class - definition of any real intitiy
object - which real world, exibits all property
eg Human, has legs , eyes .all these are property of human.
human is entity of class
*/
// p1 & p2 are the objects .
// ( p1 creates [Point p1 ] variale, new Point() -creates the object of p1)
// p1 and p2 variable points same object Point().
//
Point p1 = new Point();
System.out.println("x : " + p1.getX() + " y: " + p1.getY());
Point p2 = new Point(10);
System.out.println("x : " + p2.getX() + " y: " + p2.getY());
}
}
/*Access modifier:
public - anyone
private- only class member can access
default - if you do not write any things then its default
protected - comes on inheritance. only inheritance members can access
*/
// class is the definition
class Point{
// class memeber
// private means can not access outside block
private int x, y;
//can access by using getter and setter
//constructor -default constructor strats capital
//constructor is used to assigned the intial value of your variables
public Point(){
x = 5;
y =5;
System.out.println(" Default constructor called");
}
public Point( int a){
x = a;
y =a;
System.out.println("single paramenter constructor called");
}
// constructor overridding
public Point( int a, int b){
x = a;
y =b;
System.out.println("single paramenter constructor called");
}
// getter
public int getX(){
return x;
}
//setter
public void setX(int x){
// this refers to the current class
// thus this.x is the variable inside class
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
/*
Default constructor called
x : 5 y: 5
single paramenter constructor called
x : 10 y: 10
*/
*******************************************************************************************************************************
7th class
*******************************************************************************************************************************
Package - its kind of folder. package things of silar things.separated by dot . eg com.facebook.chat.service
Method overloading
Inheritance
Method overriding
Abstract classes
Interfaces
Packages -
you can access object ..
import like specifying address of a class
one can import the classes whic are publick
one can not import a classs which is not public.
default specifiers are accesible only inside thier on package.
package com.facebook.chat.day7;
import classTutorial.Day6ClassObject;
/*
you can access object ..
import like specifying address of a class
one can import the classes whic are public
one can not import a classs which is not public.
default specifiers are accesible only inside thier own package.
*/
public class ChatBotService {
Day6ClassObject m1 = new Day6ClassObject();
}
package com.facebook.chat.day7;
public class Math {
//method overloading
public static int add(int a, int b) {
return a + b;
}
// type or number of parameters can change
// method name and the return type should be same
public static int add(String s1, String s) {
return s.length() + s1.length();
}
public static int add(int a, int b, int c) {
return a + b + c;
}
public static int add(int a, int b, int c, int d) {
return a + b + c + d;
}
}
package com.facebook.chat.day7;
// inheritance
public class Day7Inherit {
public static void main(String[] args) {
B b1 = new B();
b1.a = 5;
b1.b = 6;
b1.printA();
b1.printB();
}
}
class A {
int a;
void printA() {
System.out.println("A: " + a);
}
}
// class B can extend all the non private properties of Class A
class B extends A {
int b;
void printB() {
System.out.println("B: " + b);
}
}
/*
A: 5
B: 6
*/
*******************************************************************************************************************************
8th class: 4/04/2020 Day 5
*******************************************************************************************************************************
package com.facebook.chat.day7;
// first call the constructor of parents call
// and exeecute the child class constructor
// first call the constructor and call the method
public class Day8 {
public static void main(String[] args) {
D b1 = new D();
b1.print();
}
}
class C {
private int a;
// default Constructor
public C(){
System.out.println("Inside C constructor default ");
a = 5;
}
//inside constructor
public C(int a){
System.out.println("Inside C constructor");
this.a = a;
}
void print() {
System.out.println("A: " + a);
}
}
class D extends C {
private int b;
//creating constructor
public D(){
System.out.println("Inside D constructor default ");
b = 10;
}
// constructor creating inside constructor
public D(int b){
super(15); // super calls the parameterize constructor
System.out.println("Inside D constructor ");
this.b = b;
}
//method overridding
void print() {
// super keyword calls the base class
super.print();
System.out.println("B: " + b);
}
}
/*
Inside C constructor default
Inside D constructor default
A: 5
B: 10
*/
super / this keyword
upcasting /downcasting/ typecasting/ inheritance
package com.facebook.chat.day7;
// first call the constructor of parents call
// and exeecute the child class constructor
// first call the constructor and call the method
public class Day8 {
public static void main(String[] args) {
//upcasting
C a1 = new E();
a1.print();
// Down casting is forcefully, you can downcast if it is object of E,if it is not object of E , it won't be fit in. does not work.
// it can only point to an object of E or its childern, C can point object of E
//Rememeber object and referecne can only poiont on its own object or its childern object.
//class reference can point only on its point object or its own childern
//checking before writting code
if (a1 instanceof E){
// downcasting
E c1 = (E) a1;//typecast
c1.hello();
}
// a1.hello();// this will not work. variable C does not understand because
//hello() method is not written on class C
}
}
class C {
private int a;
// default Constructor
public C() {
System.out.println("Inside C constructor default ");
a = 5;
}
//inside constructor
public C(int a) {
System.out.println("Inside C constructor");
this.a = a;
}
void print() {
System.out.println("A: " + a);
}
}
class D extends C {
private int b;
//creating constructor
public D() {
System.out.println("Inside D constructor default ");
b = 10;
}
// constructor creating inside constructor
public D(int b) {
super(15); // super calls the parameterize constructor
System.out.println("Inside D constructor ");
this.b = b;
}
//method overridding
void print() {
// super keyword calls the base class
super.print();
System.out.println("B: " + b);
}
}
class E extends D {
private int c;
public E() {
super(56);
System.out.println("Inside E constructor");
this.c = 40;
}
void print() {
super.print();
System.out.println("C :" + c);
}
void hello(){
System.out.println("hello");
}
}
// class extends only one class
// upcasting and downcasting
/*
Inside C constructor
Inside D constructor
Inside E constructor
A: 15
B: 56
C :40
*/
*******************************************************************************************************************************
9th class
package com.facebook.chat.day7;
public class Day9AbstractClassExapmple {
//Abstract classes is a incomplete class - it inherits only one class
public static void main(String[] args) {
Shape s = new Square();
System.out.println("Area is : " + s.area());
System.out.println("Volume is : " + s.volume());
}
}
abstract class Shape{
public final int a = 15; // can initialize the variable only once and can not change the value
abstract int area(); // methods are defined are always public
int volume(){
return 0;
}
}// you may or may not give the definition of the method
// can not creae object of abstract class because the definition of class is incomplete
//is a relationships
class Square extends Shape {
int s =5;
int area(){
return s*s;
}
int volume(){
return 0;
}
}
class Rectangle extends Shape{
int a,b;
int area(){
return a+b;
}
int volume(){
return 0;
}
}
package day9;
//interface you can implement two interface
public class Day9InterfaceExample {
public static void main(String[] args) {
ShapeArea sa = new Square();
System.out.println(sa.area());
ShapeVolume sv = new Square();
System.out.println(sv.volume());
}
}
interface ShapeArea{
int area();
int volume();
}
interface ShapeVolume{
int volume();// method inside interface are always public
}
abstract class Shape{
abstract void hello();
public int area(){
return 55;
}
}
class Square extends Shape implements ShapeArea, ShapeVolume{
void hello(){
System.out.println("hello");
}
// public int area(){
// return 20;
// }
public int volume(){
return 50;
}
}
class Hey {
public void hey(){
}
}
class Hey1 extends Hey{
public void hey(){ //it should be public
}
}
*******************************************************************************************************************************
10th class:
*******************************************************************************************************************************
Exception handling - use Try catch block
How to handle multiple exception handling
package com.facebook.chat.day7;
public class Day10ExceptionHandling {
public static void main(String[] args) {
int a=5;
int b=1;
int c = 1;
int x[] = new int[2];
try {
c = a / b; // get exception in thread and stop the execution of complete
x[5]=10;
System.out.println("after exception");
} catch(ArithmeticException e){
// System.out.println("inside catch block");
c=0;
} catch (ArrayIndexOutOfBoundsException e){
System.out.println("Inside ArrayIndexOutOfBoundsException catch");
}
System.out.println(c);
}
}
package com.facebook.chat.day7;
public class Day10ExceptionHandling {
public static void main(String[] args) {
int a=5;
int b=1;
int c = 1;
int x[] = new int[2];
try {
c = a / b; // get exception in thread and stop the execution of complete
x[1]=10;
throw new NullPointerException(); // not message
// throw new Exception("hi");
// System.out.println("after exception");
} catch(ArithmeticException e){
// System.out.println("inside catch block");
c=0;
} catch (ArrayIndexOutOfBoundsException e){
System.out.println("Inside ArrayIndexOutOfBoundsException catch");
//put always in last. because it exception check before and throws this exception
} catch(Exception e){// third type of exception. it catches all types of exception
System.out.println("Inside exception catch: " + e.getMessage());// print message
}
System.out.println(c);
}
}
package com.facebook.chat.day7;
//checked and unchecked exception
public class Day10ExcepitonHandlings {
public static void main(String[] args) throws MyException{// this handles exception.no need try catch blcok
try {
System.out.println(divide(5, 0));
}catch (Exception e){
System.out.println(e);
}
}
static int divide(int a, int b) throws MyException {
try {
if(b==0){
throw new NullPointerException();
}
int c = a/b;
return c;
} catch (ArithmeticException e){
System.out.println("inside arithmatic exception");
return 1;
}
}
}
// checked exception : handle all the time
// unchecked exception : you do not need to handle, not compulsory to handle
class MyException extends Exception{
public String toString(){
return "this is my exception";
}
}
// nobody handling :D
package com.facebook.chat.day7;
//checked and unchecked exception
public class Day10ExcepitonHandlings {
public static void main(String[] args) throws MyException{// this handles exception.no need try catch blcok
System.out.println(divide(5, 0));
}
static int divide(int a, int b) throws MyException {
if(b==0){
throw new MyException();
}
int c = a/b;
return c;
}
}
// checked exception : handle all the time
// unchecked exception : you do not need to handle, not compulsory to handle
class MyException extends Exception{
public String toString(){
return "this is my exception";
}
}
*******************************************************************************************************************************
11th class:
package Assignment2;
public class PrimeNumber {
public static void main(String[] args) {
int y = 5, flag = 0, i =2;
if(y==0||y==1){
System.out.println(y +" is not prime number");
}
for (i = 2; i < y; i++) {
if(y%i==0){
System.out.println(i +" is not prime number");
flag =1;
break;
}
}
if(flag ==0){
System.out.println(y + " " + "it is prime");
}
}
}
package com.facebook.chat.day7;
import java.util.Scanner;
public class Day11 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter any Number : ");
int inputFromUser = sc.nextInt();
int input2 = sc.nextInt();
System.out.print("you entered : " + inputFromUser + " And " + input2 );
}
}
*******************************************************************************************************************************
12th class: 4/05/2020 Day 6
Multi threading:
1. extend thread class
- multiple threads
- join
- m1.setPriority(Thread.MIN_Priority);
- Thread.currentThread().getName()
- Implements Runnable
Collection
package com.facebook.chat.day7;
public class Day12Multihtreading {
public static void main(String[] args) throws InterruptedException {
MyThread mythread1 = new MyThread("Manoj");
MyThread mythread2 = new MyThread("Manoj1");
mythread1.start();
mythread2.start();
// main thread holds until the current thread finish
mythread1.join();
mythread2.join();
System.out.println("Exiting is main thread: ");
}
}
class MyThread extends Thread{
public MyThread(String name){
super(name);
}
public void run(){
for (int i = 0; i < 10; i++) {
System.out.println(i + " : " + Thread.currentThread().getName());
try {
Thread.sleep(1000);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
}
package com.facebook.chat.day7;
public class Day12MultiThread {public static void main(String[] args) throws InterruptedException {
MyThread mythread1 = new MyThread("Manoj");
mythread1.setPriority(Thread.MIN_PRIORITY);
MyThread mythread2 = new MyThread("Manoj1");
mythread2.setPriority(Thread.MAX_PRIORITY);
mythread1.start();
mythread2.start();
// main thread holds until the current thread finish
mythread1.join();
mythread2.join();
//runnable threads
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable ,"Runnable thread");
thread.start();
System.out.println("Exiting is main thread: ");
}
}
class MyThread extends Thread{
public MyThread(String name){
super(name);
}
public void run(){
for (int i = 0; i < 10000; i++) {
// System.out.println(i + " : " + Thread.currentThread().getName());
}
System.out.println("Finished: " + Thread.currentThread().getName());
}
}
class MyRunnable implements Runnable{
@Override
public void run() {
System.out.println("This is inside Runnable! "+ Thread.currentThread().getName());
}
}
*******************************************************************************************************************************
14th class:
//spring boot tomcat..
Spring context
BeanFactory
ApplicationContext
injection
autowired
Spring managed bean
scope of beans
signleton
prototype
request
session
global
Request type
@get
@post
@delete
@put
*******************************************************************************************************************************
14th class: 4/05/2020 Day 6
How to create Rest project;
and add dependency ..Spring Web
Spring Web WEB
Build web, including RESTful, applications using Spring MVC. Uses Apache Tomcat as the default embedded container.
..........................
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import entity.Employee;
@RestController // is a child of component. there will be single object
public class HelloController {
@Autowired
private Employee e;
@GetMapping("/hello")
Employee hello() {
return e;
}
//post use for create
@PostMapping("/hello")
Employee hello1(@RequestBody Employee emp) {
e.setId(emp.getId());
e.setName(emp.getName());
return emp;
}
}
package entity;
import org.springframework.stereotype.Component;
@Component
public class Employee {
int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
server.port=8888
// dependency injection:
//class b is a dependency of a
class A{
@Autowired
B b;
}
- variable injection
- constructor injection
- setter injection
@Component - spring managed bean
A a1 = new A();
a1.b
Spring Context
BeanFactory
ApplicationContext
Injection
Autowired
Constructor based injection
Profiles
local
dev
test
production
Spring managed bean
Request type
@get @post @delete @put
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import entity.Employee;
@RestController // is a child of component. there will be single object
public class HelloController {
@Autowired // dependency injection. controller need employee so dependency injection
private Employee e;
@GetMapping("/hello")
Employee hello() {
return e;
}
//post use for create
@PostMapping("/hello")
Employee hello1(@RequestBody Employee emp) {
e.setName(emp.getName());
e.setName(emp.getName());
return emp;
}
}
package entity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Employee {
String name;
// or @Autowired
Date dob;
@Autowired // employee need dob so dependency injection
public Employee(Date dob) {
this.name = "";
this.dob = dob;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDob() {
return dob;
}
// or @Autowired
public void setDob(Date dob) {
this.dob = dob;
}
}
package entity;
public class Date {
int month;
int day;
int year;
public Date() {
this.month =2;
this.day=12;
this.year=2020;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
@Override
public String toString() {
return "Date{" +
"month=" + month +
", day=" + day +
", year=" + year +
'}';
}
}
application.properties
server.port=8081
*******************************************************************************************************************************
19th class:
static blocks execute first then constructor execute finally void method executes .
Bas b = new Bas(); // create object of the class ,then call the function with object
interface shapeVol{
int vol(); // methods inside interface are always public
}
abstract class shape{
public final int a = 15; // can initialize the variable only once and can not change the value
abstract int area(); // methods are defined are always public
// you may or may not give the defination of method but you can not create object of abstract class,because the defination of class is incomplete
}
sprint project
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import entity.Employee;
import service.EmployeeService;
@RestController // is a child of component. there will be single object
public class HelloController {
@Autowired
private EmployeeService employeeService; // creating object of Employeeservice
@GetMapping("/employee/{id}")
Employee employee(@PathVariable("id") int id ) {
//this will get me the employee
return employeeService.getEmployee(id);
}
@PostMapping ("/employee")
Employee saveEmployee(@RequestBody Employee emp) {
//this will insert a new employee
employeeService.insertEmployee(emp);
return emp;
}
@PutMapping ("/employee")
Employee UpdateEmployee(@RequestBody Employee emp) {
//this will update the employee
employeeService.updateEmployee(emp);
return emp;
}
@DeleteMapping ("/employee/{id}")
Employee deleteEmployee(@PathVariable ("id") int id) {
//this will delete the employee
return employeeService.deleteEmployee(id);
}
}
package entity;
public class Date {
int month;
int day;
int year;
public Date() {
this.month =2;
this.day=12;
this.year=2020;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
@Override
public String toString() {
return "Date{" +
"month=" + month +
", day=" + day +
", year=" + year +
'}';
}
}
package entity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Employee {
String name;
int id;
// or @Autowired
Date dob;
public Employee(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Autowired // employee need dob so dependency injection
public Employee(Date dob) {
this.name = "";
this.dob = dob;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getDob() {
return dob;
}
// or @Autowired
public void setDob(Date dob) {
this.dob = dob;
}
}
package service;
import entity.Employee;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class EmployeeService {
// writting bussiness logic
List<Employee>employees= new ArrayList<>();
public void insertEmployee(Employee e){
employees.add(e);
}
public void updateEmployee(Employee e){
Employee olderEmployee = employees.get(e.getId());
olderEmployee.setName(e.getName());
olderEmployee.setDob(e.getDob());
}
public Employee deleteEmployee(int id ){
Employee olderEmployee = employees.get(id);
employees.remove(id);
return olderEmployee;
}
public Employee getEmployee (int id){
return employees.get(id);
}
}
*******************************************************************************************************************************
20th class:
*******************************************************************************************************************************
Connected Database JPA on sql server.
download dependency MySql connector, Rest web service, JPA
search : spring jpa integration properties
Application-properties;
server.port=8181
spring.datasource.url=jdbc:mysql://localhost:3306/demo
spring.datasource.username=root
spring.datasource.password=1234
# The SQL dialect makes Hibernate generate better SQL fo rthe chosen database
spring.jpa.show-sql = true
spring.jpa.generate.ddl: true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation: true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL55Dialect
spring.datasource.platform = mysql
spring.mvc.view.prefix=/jsp/
spring.mvc.view.suffix=.jsp
POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import entity.Employee;
import service.EmployeeService;
@RestController // is a child of component. there will be single object
public class HelloController {
@Autowired
private EmployeeService employeeService; // creating object of Employeeservice
@GetMapping("/employee/{id}")
Employee employee(@PathVariable("id") int id ) {
//this will get me the employee
return employeeService.getEmployee(id);
}
@PostMapping ("/employee")
Employee saveEmployee(@RequestBody Employee emp) {
//this will insert a new employee
employeeService.insertEmployee(emp);
return emp;
}
@PutMapping ("/employee")
Employee UpdateEmployee(@RequestBody Employee emp) {
//this will update the employee
employeeService.updateEmployee(emp);
return emp;
}
@DeleteMapping ("/employee/{id}")
Employee deleteEmployee(@PathVariable ("id") int id) {
//this will delete the employee
return employeeService.deleteEmployee(id);
}
}
package entity;
public class Date {
int month;
int day;
int year;
public Date() {
this.month =2;
this.day=12;
this.year=2020;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
@Override
public String toString() {
return "Date{" +
"month=" + month +
", day=" + day +
", year=" + year +
'}';
}
}
package entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity(name = "employee")
public class Employee {
@Column(name = "name")
String name;
@Id
@Column(name = "id")
int id;
@Column(name = "city")
String city;
public Employee() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
package service;
import entity.Employee;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class EmployeeService {
// writting bussiness logic
List<Employee>employees= new ArrayList<>();
public void insertEmployee(Employee e){
employees.add(e);
}
public void updateEmployee(Employee e){
Employee olderEmployee = employees.get(e.getId());
olderEmployee.setName(e.getName());
olderEmployee.setId(e.getId());
olderEmployee.setCity(e.getCity());
}
public Employee deleteEmployee(int id ){
Employee olderEmployee = employees.get(id);
employees.remove(id);
return olderEmployee;
}
public Employee getEmployee (int id){
return employees.get(id);
}
}
*******************************************************************************************************************************
20th class: 4/06/2020 Day 7
controller --- Rest layer
service-- business logic
repository - talks to db
adding data on database server from postman
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import entity.Employee;
import service.EmployeeService;
@RestController // is a child of component. there will be single object
public class HelloController {
@Autowired
private EmployeeService employeeService; // creating object of Employeeservice
@GetMapping("/employee/{id}")
Employee employee(@PathVariable("id") int id ) {
//this will get me the employee
return employeeService.getEmployee(id);
}
@PostMapping ("/employee")
Employee saveEmployee(@RequestBody Employee emp) {
//this will insert a new employee
employeeService.insertEmployee(emp);
return emp;
}
@PutMapping ("/employee")
Employee UpdateEmployee(@RequestBody Employee emp) {
//this will update the employee
employeeService.updateEmployee(emp);
return emp;
}
@DeleteMapping ("/employee/{id}")
Employee deleteEmployee(@PathVariable ("id") int id) {
//this will delete the employee
return employeeService.deleteEmployee(id);
}
}
package service;
import entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import repository.EmployeeRepository;
@Service
public class EmployeeService {
@Autowired
private EmployeeRepository employeeRepository;
public void insertEmployee(Employee e) {
employeeRepository.save(e);
}
public void updateEmployee(Employee e) {
Employee old = employeeRepository.findById(e.getId()).get();
old.setName(e.getName());
old.setCity(e.getCity());
employeeRepository.save(old);
}
public Employee deleteEmployee(int id) {
Employee old = employeeRepository.findById(id).get();
employeeRepository.deleteById(id);
return old;
}
public Employee getEmployee(int id) {
return employeeRepository.findById(id).get();
}
}
package repository;
import entity.Employee;
import org.springframework.data.repository.CrudRepository;
public interface EmployeeRepository extends CrudRepository<Employee,Integer> {
}
package service;
import entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import repository.EmployeeRepository;
@Service
public class EmployeeService {
@Autowired
private EmployeeRepository employeeRepository;
public void insertEmployee(Employee e) {
employeeRepository.save(e);
}
public void updateEmployee(Employee e) {
Employee old = employeeRepository.findById(e.getId()).get();
old.setName(e.getName());
old.setCity(e.getCity());
employeeRepository.save(old);
}
public Employee deleteEmployee(int id) {
Employee old = employeeRepository.findById(id).get();
employeeRepository.deleteById(id);
return old;
}
public Employee getEmployee(int id) {
return employeeRepository.findById(id).get();
}
}
package entity;
public class Date {
int month;
int day;
int year;
public Date() {
this.month =2;
this.day=12;
this.year=2020;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
@Override
public String toString() {
return "Date{" +
"month=" + month +
", day=" + day +
", year=" + year +
'}';
}
}
package entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity(name = "employee")
public class Employee {
@Column(name = "name")
String name;
@Id
@Column(name = "id")
int id;
@Column(name = "city")
String city;
public Employee() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
*******************************************************************************************************************************
22th class: 4/06/2020 Day 7
download postgresql server and postbird
PostgreSQL Driver SQL dependcy
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.12</version>
</dependency>
*******************************************************************************************************************************
23th class: 4/07/2020 Day 8
*******************************************************************************************************************************
Debug and Important Sql find city and otherss..
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import entity.Employee;
import service.EmployeeService;
import java.util.List;
@RestController // is a child of component. there will be single object
public class HelloController {
@Autowired
private EmployeeService employeeService; // creating object of Employeeservice
@GetMapping("/employee/{id}")
Employee employee(@PathVariable("id") int id ) {
//this will get me the employee
return employeeService.getEmployee(id);
}
@GetMapping("/employee/name/{name}")
List<Employee> getEmployeename(@PathVariable("name") String name ) {
//this will get me the employee
return employeeService.findByName(name);
}
@GetMapping("/employee/city/{city}")
List<Employee> getEmployeeCity(@PathVariable("city") String city ) {
//this will get me the employee
return employeeService.findByCity(city);
}
@GetMapping("/employee/{name}/{city}")
List<Employee> getEmployeeByNameCity( @PathVariable("name") String name,
@PathVariable("city") String city ) {
//this will get me the employee
return employeeService.findByNameCity(name,city);
}
@PostMapping ("/employee")
Employee saveEmployee(@RequestBody Employee emp) {
//this will insert a new employee
employeeService.insertEmployee(emp);
return emp;
}
@PutMapping ("/employee")
Employee UpdateEmployee(@RequestBody Employee emp) {
//this will update the employee
employeeService.updateEmployee(emp);
return emp;
}
@DeleteMapping ("/employee/{id}")
Employee deleteEmployee(@PathVariable ("id") int id) {
//this will delete the employee
return employeeService.deleteEmployee(id);
}
}
package entity;
public class Date {
int month;
int day;
int year;
public Date() {
this.month =2;
this.day=12;
this.year=2020;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
@Override
public String toString() {
return "Date{" +
"month=" + month +
", day=" + day +
", year=" + year +
'}';
}
}
package entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity(name = "employee")
public class Employee {
@Column(name = "name")
String name;
@Id
@Column(name = "id")
int id;
@Column(name = "city")
String city;
public Employee() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
package repository;
import entity.Employee;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface EmployeeRepository extends CrudRepository<Employee,Integer> {
List<Employee> findByName(String name);
@Query("SELECT e FROM Employee e WHERE e.name= :n and e.city = city")
List<Employee>findByNameCity(@Param("n") String n,
@Param("c") String c);
List<Employee> findByCity(String city);
}
package service;
import entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import repository.EmployeeRepository;
import java.util.List;
@Service
public class EmployeeService {
@Autowired
private EmployeeRepository employeeRepository;
public void insertEmployee(Employee e) {
employeeRepository.save(e);
}
//finding name
public List<Employee>findByName(String name){
return employeeRepository.findByName(name);
}
public void updateEmployee(Employee e) {
Employee old = employeeRepository.findById(e.getId()).get();
old.setName(e.getName());
old.setCity(e.getCity());
employeeRepository.save(old);
}
public Employee deleteEmployee(int id) {
Employee old = employeeRepository.findById(id).get();
employeeRepository.deleteById(id);
return old;
}
public Employee getEmployee(int id) {
return employeeRepository.findById(id).get();
}
//finding city
public List<Employee>findByCity(String city){
return employeeRepository.findByCity(city);
}
public List<Employee>findByNameCity(String name, String city){
return employeeRepository.findByNameCity(name,city);
}
}
server.port=8181
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url:jdbc:postgresql://localhost:5432/demo
spring.datasource.username:postgres
spring.datasource.password:1234
#The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.show-sql:true
spring.jpa.generate-ddl:true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation:true
spring.jpa.properties.hibernate.dialect:org.hibernate.dialect.PostgreSQLDialect
# for my sql server
#spring.datasource.url=jdbc:mysql://localhost:3306/demo
#spring.datasource.username=root
#spring.datasource.password=1234
# The SQL dialect makes Hibernate generate better SQL fo rthe chosen database
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#spring.jpa.show-sql = true
#spring.jpa.generate.ddl: true
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation: true
#spring.jpa.hibernate.ddl-auto = update
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL55Dialect
#spring.datasource.platform = mysql
#spring.mvc.view.prefix=/jsp/
#spring.mvc.view.suffix=.jsp
REFERENCES:
- https://www.tutorialspoint.com/java/index.htm
- Interface interview question: https://javaconceptoftheday.com/interfaces-in-java/
- SpringbootProject Create: https://start.spring.io/
- JPA MY sqlconnect: https://mkyong.com/spring-boot/spring-boot-spring-data-jpa-mysql-example/
- DB - install postgres : https://www.2ndquadrant.com/en/resources/postgresql-installer-2ndquadrant/
- Donload Postbird- https://www.electronjs.org/apps/postbird
- user name : postgres and password: 1234
- Free training institute: https://www.techeinstein.com/courses/
- Basic to advanced Micro service spring project: password: 111111
No comments:
Post a Comment