Question: Which of the following operations is a terminal operation in Java 8 Stream API?
Options:
Java By Trilochan – Learn Core Java, Java 8+, Collections, OOP, Multithreading, Spring Boot with Micro Services and Java Interview Questions with practical examples, coding solutions and interview preparation tips.
Question: Which of the following operations is a terminal operation in Java 8 Stream API?
Options:
JAVA with Silan Software
@SpringBootApplication annotation represent that the corresponding application is a spring boot application. It is working for three annotations like @Configuration, @EnableAutoConfiguration, and @ComponentScan.
@Configuration : It is a class level annotation indicating that an object is a source of bean definitions. @Configuration classes declare beans through @Bean annotated method.
@EnableAutoConfiguration : It enables to spring boot to auto-configure the application context. So it automatically creates and registers beans based on both the included jar files in the class path and the beans defined by us.
@ComponentScan : It is used for auto detecting and registering spring managed components like beans, controllers, repository, services etc.
JAVA with Silan Software
First Spring Boot Application in STS
pom.xml
<?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>3.3.3</version>
<relativePath/> <!--
lookup parent from repository -->
</parent>
<groupId>com.iter</groupId>
<artifactId>SpringBootFirstExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SpringBootFirstExample</name>
<description>My First Spring Boot
Example</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
TestController.java
package com.soa.controller;
import
org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("/hello")
public String display()
{
return "Welcome to
Java Spring Boot";
}
}
//JAVA program to find the reverse of a string value and check whether the given string is palindrome or not
import java.util.*;
class ReverseString
{
public static void main(String[] args)
{
String str,rev="";
int l;
Scanner s=new Scanner(System.in);
System.out.println("enter the string value:");
str=s.nextLine();
l=str.length();
for(int i=l-1;i>=0;i--)
{
rev=rev+str.charAt(i);
}
System.out.println("The reverse is:"+rev);
if(str.equals(rev))
{
System.out.println("palindrome");
}
else
{
System.out.println("not palindrome");
}
}
}
Output :
Optional in JAVA 8:
Optional is a built in class present in java.util package also called as container class specifically used to represent optional values that exist or do not exist.
The main advantage is to avoid null. Here there is no NullPointerException will arise at the run time in the form of result.
Note: For getting JAVA, Python, Machine Learning, Deep Learning tutorial in detail, follow:
www.pythontpoints.com
-----------------------------Thank You----------------------------
Regards:
Trilochan Tarai | Associate Manager, Delivery, Majesco India
+91-9439202111
JAVA 8 newly Features:
1. Lambda Expression
2. Functional Interface
3. Method References
4. Stream API
5. Date Time API
6. Method References
7. Optional class present in java.util package
8. Nashorn : Highly improved JavaScript engine which enables the execution of JavaScript in JAVA.
-------------Thank You-----------------
Regards:
Trilochan Tarai | Associate Manager, Delivery, Majesco India
+91-9439202111
@RequestMapping Annotation:
This is one of the basic
annotations in Spring that maps HTTP requests with methods. This is used to map
the request into the specific method in Spring.
The method is run every time an end-user makes
an HTTP
request. The mapping can also
be done at the method or class level.
@RequestMapping("/hello")
public class HelloController()
{
@RequestMapping("/helloworld")
public String show()
{
return "JAVA means Silan Software";
}
@RequestMapping("/helloall")
public String display()
{
return "javabytrilochan";
}
}
From here, the /hello is assigned on the class level. And each method has
separate mappings and this allows to have a prefix before creating the mapping.
Regards:
Trilochan Tarai
Associate Manager-Senior Lead Engineer,
Majesco India
+91-9439202111
HashMap vs. Hashtable:
Both HashMap and Hashtable are two implementation
class of Map interface which contains pair. In a pair, one is key and one is
value.
There are many differences between HashMap and
Hashtable.
|
HashMap Introduced in 1.2 version HashMap is not synchronized, that means it is not in thread safe. HashMap allows one null key and multiple null values. HashMap is faster. We can traverse HashMap by Iterator. |
Hashtable Introduced in 1.0 version, that’s why it is called as legacy. Hashtable is synchronized, that means it is thread safe. Hashtable not allowed any null key or value. Hashtable is slow. We can traverse Hashtable by Enumerator and Iterator. |
Predicate in JAVA 8:
A predicate is a built in functional interface present in java.util.function package. It is specifically used for code management and unit testing. It contains many built in methods which is as follows:
test(T t): It evaluates the predicate on the value passed to this function as the argument and returning a boolean value(true / false).
TestExample.java
import java.util.function.Predicate;
class TestExample
{
public static void main(String[] args)
{
Predicate<Integer> greater_than = x -> (x > 100);
// calling test method of the predicate
System.out.println(greater_than.test(200));
}
}