Posts

Showing posts from October, 2023

What is @transactional annotation and Where we should be used @transactional annotation ?

 Interview Question from Capgemini ? Q. What is @transational annotation and Where we should be used @transactional annotation ? Ans : -  @transactional  annotation :- => The @transactional annotation is used metadata that specifies that an interface, Class or method must have transactional Semantics. Uses of  @transactional  annotation :- => we can use @transactional to wrap a method in a database transaction. => It allows us to set propagation, isolation timeout, read-only and rollback conditions for our transaction. we can also specify the transaction manager.

In this Array,I want only name which starts with “A” {"Apurva", "John", "Mike", "Arun", "Mohan", "Aparna" }?

 Interview Question? In this Array, I want only name which starts with “A”   {"Apurva", "John", "Mike", "Arun", "Mohan", "Aparna" }? Solution:- package p3; import java.util.Arrays; import java.util.stream.Collectors; import java.util.*; public class NameStartsWithA { public static void main(String[] args) { String[] abc= {"Apurva","John","Mike","Akansha","Aparna","Mohan"}; List<String> list=Arrays.asList(abc); List<String> startsWithA=list.stream().filter(i->i.startsWith("A")).collect(Collectors.toList()); System.out.println(startsWithA); } } ********************************************************* O/P:- [Apurva, Akansha , Aparna]

Interview Question? How to find square of each element in this Array {2,4,5,6,8} using map ?

 Q. How to find square of each element in this Array {2,4,5,6,8} Output : [4, 16, 25, 36, 64] Solution :- package p3; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class MapExample { public static void main(String[] args) { Integer[] abc={2,4,5,6,8}; List<Integer> list=Arrays.asList(abc); List<Integer> squareEle=list.stream().map(i->i*i).collect(Collectors.toList()); System.out.println(squareEle); for(Integer i:squareEle) { System.out.println(i); }   } } ******************************************************************** O/P:-  Output : [4, 16, 25, 36, 64]

What are the OOPS Concept in JAVA? Do you explain that Concept .

 Q. What are the OOPS Concept in JAVA? Do you explain that Concept . Ans :- OOPS stands for (Object oriented programming system) => The process of constructing programs using class-object concept is known as object-oriented programming. These  are OOPS Concepts- 1.Object 2.Class 3.Inheritance 4.Polymorphism 5.encapsulation 6.Abstraction. 1.Object-  => Object is a instance of a Class. => Object  is a storage releated  to a class holding instance member of a class. =>We use  "new " keyword in creating Objects. =>Object is created in Heap Area of JVM. =>Object will hold instance member of class. 2.Class:- => Class is a structured Layout generating Object. => Class is  a user defined datatype => Class is a Collection of variables, methods, blocks and constructor. 3.Inheritance:- => Inheritance in JAVA is a mechanism in which one object acquires all the properties and behavior of a parent object is known as Inheritance process....

HCl Interview Question 3+ experience ?

 HCL Interview Question ? What is the Output of this Program? Program: public class Test1 { public static void main(String[] args) { String str1=new String("Test"); String str2="TEST"; System.out.println(str1==str2); System.out.println(str1.equals(str2)); } } ********************************************************** O/P :-  false             false

How to Find Second Highest Value Using JAVA 8?

 Interview Question? Interview Question Capgemini? Q. Write a Logic Second Highest Value ,take a Array take 5 or 6 elements and in that Array I want Second Highest Value? Solution:- package p3; import java.util.Arrays; import java.util.List; public class SecondHighestValue { public static void main(String[] args) { Integer[] numbers= {10,50,40,30}; List<Integer> list=Arrays.asList(numbers); Integer secondHighest=list.stream() .distinct().sorted((a,b)->b-a).skip(1).findFirst().orElse(null); System.out.println("The Second Highest Number is :"+secondHighest); } } ************************************************************* O/P:- The Second Highest Number is :40

How to print this ? HCL L1 interview Question for 3+ experiance

How to print this ? 1 1 2 1 2 3 1 2 3 4 Solution:- package p3; public class ABC { public static void main(String[] args) { int n=4; //number of Rows for(int i=1;i<=n;i++) { for(int j=1;j<=i;j++) { System.out.print(" "+j); } System.out.println(" "); } } } ******************************************************************* O/P:-  1   1 2   1 2 3   1 2 3 4 

How to find Two digit element in this Array int[] abc= {2,1,3,44,52,23}; using For-Loop.

 Interview Question?  Now Out of this Array  int[]  abc = {2,1,3,44,52,23}; I want you to write a Logic to print only number having 2 digits using for Loop. Solution : package p3; public class ArrayTwoDigitCount { public static void main(String[] args) { int[] abc= {2,1,3,44,52,23}; for(int i: abc) { if(i>=10 && i<=99) { System.out.println("Two-digit-elements :"+i); } } } } **************************************************************** O/P: Two-digit-elements :44 Two-digit-elements :52 Two-digit-elements :23

How to find two-digit-elements using java8 stream?

 Interview Question? Now out of this Array int [] abc= {2,1,3,44,52,23} I want to write a Logic to print only number having 2 digits using java8. Solution : package p3; import java.util.Arrays; public class ArrayTwoDigitEleFound8 { public static void main(String[] args) { int[] abc= {2,1,3,44,52,23}; Arrays.stream(abc).filter(i->i>=10 && i<=100).forEach(System.out::println); } } ********************************************************************** O/P : 44          52          23

How to find Count of element using stream?

Interview Question ? How to find Count of element using stream? Solution :- package p2; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class CountOfElement { public static void main(String[] args) { List<Integer> list=Arrays.asList(1,1,2,3,3,5,5,7,8,9,9); Map<Integer,Long> map=list.stream().collect(Collectors.groupingBy(i->i,Collectors.counting())); System.out.println(map); map=map.entrySet().stream().filter(e->e.getValue()>1).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); System.out.println(map); } } **************************************************************  

What is the Difference between Collection and Collections ?

 Interview Question What is the Difference between Collection and Collections ? Ans :- 1.Collection<E> 2.Collections 1.Collection<E>  => Collection <E> is an interface from java.util package and which is the root of Java Collection<E> Framework. 2.Collections : => “Collections” is a Class from java.util package and provides a sort() method to perform the sorting process on List<E> Object. ******************************************************

How to find Min value of Integer using Java8 feature ?

 Interview Question How to find Min value of Integer using Java8 feature ? Solution : package p2; import java.util.ArrayList; import java.util.List; public class MinOfInteger { public static void main(String[] args) { List<Integer> list=new ArrayList<>(); list.add(1); list.add(10); list.add(21); list.add(13); list.add(15); Integer min=list.stream().mapToInt(i->i).min().getAsInt(); System.out.println(min); } } **************************************************************************** O/P : 1

How to Find MAX value Of Integer by using Java 8 feature?

 Interview Question How to Find MAX value Of Integer by using Java 8 feature? Solution : package p2; import java.util.Arrays; import java.util.List; public class MaxOfInteger { public static void main(String[] args) { List<Integer> list=Arrays.asList(10,15,25,50); Integer max=list.stream().mapToInt(i->i).max().getAsInt(); System.out.println(max); } } ******************************************************************** O/P : 50

How to find Sum Of Integers

 Interview Question for 2+ experienced How to find Sum Of Integers Solution : package p2; import java.util.List; import java.util.Arrays; public class SumOfInteger { public static void main(String[] args) { List<Integer> list=Arrays.asList(10,30,20);     Integer sum=list.stream().mapToInt(i->i).sum();     System.out.println(sum); } } ****************************************************************** O/P : 60

How to remove duplicate element by using Java 8 feature?

 How to remove duplicate element by using Java 8 feature? Example : import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class DuplicateElement { public static void main(String[] args) { List<Integer> list=Arrays.asList(1,1,2,3,3,3,5); list=list.stream().distinct().collect(Collectors.toList()); System.out.println(list); } } **************************************************************************** OutPut : [1, 2, 3, 5]

What are the new features included in JAVA8 ?

 Interview Question What are the new features included in JAVA8 ? Ans :- some features which are included in JAVA8 are as follows- 1. Lambda Expression. 2.Stream API 3.Default methods &  Static Methods in Interface 4.Optional 5.Functional Interface 6.Method References 7.DATE and API 1. Lambda Expression :- Lambda expression is an Anonymous function, without name return type  and having one Lambda Symbol (->) => The Process of declaring method without method name is Known as LambdaExpression,and which is also known as Anonymous method. 2.Stream API :- A stream is a Sequence of object that Supports various methods,Which Can be pipeLined to Produce the desired result. 5.Functional Interface:- functional interfaces are those interfaces which can have only one abstract method  and it can have any number of default  and Concrete methods.so it work as SAM(single abstract method) 6.Method References:- The process in which abstract method of Functional Interfac...

How to Create Map Object ? Create Map Object put some element on it and iterate one by one .

Interview Question How to Create Map Object ? Create Map Object put some element on it and iterate one by one . package p2; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class MapExample { public static void main(String[] args) { Map<Integer,String> map =new HashMap<>(); map.put(1, "Shaily"); map.put(2, "Pooja"); map.put(3, "Anju"); map.put(4, "Sushma"); for(Entry<Integer, String> v1:map.entrySet()) { System.out.println(v1.getKey()+""+v1.getValue()); } } }  

Interview Question Q. If we have Employee List and in the List have Id, name ,salary then ,I want Salary is greater than 20000 by using Java8 Feature.

 Interview Question Q. If we have Employee List and in the List have Id, name ,salary  then ,I want Salary is greater than 20000 by using Java8 Feature Ans :-  Test.java package p1; 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 Employee(1, "Asha", 70000)); list.add(new Employee(2,"Poorinima",15000)); list.add(new Employee(3,"Neeta",5000)); List<Employee> list1=list.stream().filter(i->i.getSalary()>20000).collect(Collectors.toList()); // System.out.println(list1); for(Employee e:list1) { System.out.println("Emp Salary:"+e.getSalary()); } } } package tcs; 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...

What is JAVA ?

What is JAVA ? JAVA is a Programming Language  and a Platform. Java is a High -level , Robust, Object-Oriented Programming System  and Secure Programming language. It was developed by Sun Microsystems in the year of 1995.James Gosling is non as father of JAVA,Before JAVA its name Was oak Since Oak was already a registered company so James Gosling and his team changed the name from oak to JAVA.