Posts

Showing posts from November, 2023

what is the default server in spring boot?

 what is the default server in spring boot? Ans :- tomcat server is default server in spring boot  and it runs on port 8080.

How to Change server port in Spring Boot?

How to Change server port in Spring Boot? Ans :- open sts-> open springBoot Project-> open package src/main/resources-> application.properties-> server.port=8090

I want to remove duplicate elements on the list how can you do that.

 TCS Interview Question Q. I want to remove duplicate elements on the list how can you do that. SOLUTION:- package i1; import java.util.HashSet; import java.util.Set; public class RemoveDuplicateUsingSet { public static void main(String[] args) { Set<Integer> s=new HashSet<>(); s.add(1); s.add(2); s.add(2); s.add(3); s.add(4); s.add(5); s.add(7); s.add(7);                 System.out.println("Set :"+s); }                 }

How to achieve abstraction?

 Q. How to achieve abstraction ? Ans :- we can achieve abstraction by using abstract classes and Interfaces. Abstraction in java can be achieved in two ways: Using abstract classes:- Abstract classes achieve partial abstraction as concrete methods can also be defined in them. Using Interfaces :- Interfaces achieve complete abstraction as only abstract methods can be defined in them.

How to Create springBoot Project using sts ide ?

 How to Create SpringBoot Project using sts ide ? Ans :- Open sts ->File -> new ->Spring boot starter project->Add dependency -> Finish 

How to Sort List of Employee by their name ? TCS Interview Question?

 Q. How to Sort List of Employee by their name ? Where we have fields like id, name and age. Ans:- Solution :- Employee.java package p4; public class Employee { private int id; private String name; private int age; 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; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Employee(int id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } } ************************************************************** EmployeeSortedByName.java package p4; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; public class EmployeeSortedByName { public static void main(String[] args) { List<Employee> list=new ArrayList...

Q. I have List of Employee, Where I want Salary of employee greater than 20,000 ?

 TCS Interview Question? Q. I have List of Employee, Where I want Salary of employee greater than 20,000 ? SOLUTION :- Employee.java package p2; public class Employee { private int id; private String name; private int salary; 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; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } public Employee(int id, String name, int salary) { super(); this.id = id; this.name = name; this.salary = salary; } } ******************************************************** Test.java package p2; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class Test { public static void main(String[] args) { List<Employee> list=new ArrayList<>(); list.add(new Empl...

How to Generate Setter & Getter using eclipse ide?

 How to Generate Setter & Getter using eclipse ide? Ans :- Open eclipse -> Right Click->Source->Generate Getters & Setters -> Select All ->Generate => Create Class Employee put some variable there Example :- package p3; public class Employee { private String name; private String id; private double salary; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } } ********************************************************************** Open eclipse -> Right Click->Source->Generate Getters & Setters -> Select All ->Generate Open eclipse -> Right Click->Source->Generate Getters & Setters -> Select All ->Generate

What are POJO classes in spring? What is the use of POJO Class, and How to create POJO classes.

TCS Interview Question  3+ What are POJO classes in spring? What is the use of POJO Class, and How to create POJO classes. POJO -  POJO stands for "plain old java object" .It is an Ordinary JAVA Object, not bound  by any special restriction other than those forced by the JAVA Language Specification and not requiring any class path. POJO's are used for increasing the readability and re-usability of a program. => The term POJO was introduced by Martin Flower (An American Software developer) in 2000. It is available in JAVA from the EJB 3.0 by sun microsystem. Generally, a POJO Class contains Variables and their Setters & Getters. => The POJO Classes Similar to beans as both are used to define the Objects to increase the readability and reusability . => The only difference between them ,that Bean Files have some restrictions but, the POJO files do not have any Special restrictions. What is the use of  POJO Classes:- => The POJO Class in JAVA is used to ...

How to find Sum,Min,Max of Integer using Java 8 stream?

HCL Interview Question? How to find Sum, Min, Max of Integer using Java 8 stream? Solution:- package p3; import java.util.Arrays; import java.util.List; public class SumMinMaxOfInteger {   public static void main(String[] args) {     List<Integer> list=Arrays.asList(10,40,50);     Integer sum=list.stream().mapToInt(i->i).sum();     System.out.println("Sum of elements:"+sum);          Integer min=list.stream().mapToInt(i->i).min().getAsInt();     System.out.println("Min of elements:"+min);          Integer max=list.stream().mapToInt(i->i).max().getAsInt();     System.out.println("Max of Integer:"+max);        }  } *********************************************************** O/P:-  Sum of elements:100 Min of elements:10 Max of Integer:50