Wednesday, 10 August 2022

JAVA 8 Interview Question-2022 : What is Optional and why it is used ?

 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 Interview Questions-2022 : JAVA 8 new Features !

 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

Friday, 22 July 2022

What is @RequestMapping Annotation in JAVA Spring? : JAVA Interview Question-2022

 @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




Thursday, 21 July 2022

What is the difference between HashMap and Hashtable in JAVA ? : Mphasis JAVA Interview Question-2022

 

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.



Our Services:
JAVA Training  ||  JAVA Projects  ||  JAVA Internship  || JAVA Placements || Python Training  || AI & Machine Learning with Python Training  || Data Science Training
Call to : 0674-2361252

Wednesday, 20 July 2022

What is Predicate in JAVA 8 ? Mphasis Interview Question-2022

 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));  

    } 



Thursday, 2 April 2020

What is dependency injection in JAVA spring framework ?

Spring is an open source, light weight, and non-invasive framework which is specifically used to develop web and enterprise application. 

Dependency Injection is a process where the spring framework injecting dependency to a dependent object.

Dependency Injection is a software design pattern that implements inversion of control for resolving dependencies.




Our Services:
JAVA training ||  JAVA projects  ||  JAVA Internship  || Python training  || AI & Machine Learning training  ||  Data Science training

Call us: 0674-2361252

Tuesday, 23 July 2019

How to kill a thread in JAVA ??

Ans:

'Killing a thread' is not the right phrase to use. Here is one way we can implement graceful exit of the thread:
class TaskThread implements Runnable {

    boolean shouldStop;

    public TaskThread(boolean shouldStop) {
        this.shouldStop = shouldStop;
    }

    @Override
    public void run() {

        System.out.println("Thread has started");

        while (!shouldStop) {
            // do something
        }

        System.out.println("Thread has ended");

    }
public void stop() {
        shouldStop = true;
    }


}
public class ThreadStop
{
public static void main(String[] args)
{
System.out.println("Start");

// Start the thread
TaskThread task = new TaskThread(false);
Thread t = new Thread(task);
t.start();

  // Stop the thread
task.stop();

  System.out.println("End");

}
}