Full Stack Java Corporate Trainer

Full Stack Java Corporate Trainer

Share

Offer job oriented full stack Java Training Core Java Adv Java Spring Hibernate Springboot Oracle

19/01/2021

Collectors

Collectors is a final class that extends Object class. It provides reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria etc..
import java.util.stream.Collectors;

import java.util.List;

import java.util.ArrayList;

class Product{

int id;

String name;

float price;



public Product(int id, String name, float price) {

this.id = id;

this.name = name;

this.price = price;

}

}

public class CollectorsExample {

public static void main(String[] args) {

List productsList = new ArrayList();

//Adding Products

productsList.add(new Product(1,"HP Laptop",25000f));

productsList.add(new Product(2,"Dell Laptop",30000f));

productsList.add(new Product(3,"Lenevo Laptop",28000f));

productsList.add(new Product(4,"Sony Laptop",28000f));

productsList.add(new Product(5,"Apple Laptop",90000f));

List productPriceList =

productsList.stream()

.map(x->x.price) // fetching price

.collect(Collectors.toList()); // collecting as list

System.out.println(productPriceList);

}

}

this.pr

18/01/2021

Default Methods

Java provides a facility to create default methods inside the interface. Methods which are defined inside the interface and tagged with default keyword are known as default methods. These methods are non-abstract methods and can have method body..
interface Sayable{

// Default method

default void say(){

System.out.println("Hello, this is default method");

}

// Abstract method

void sayMore(String msg);

}

public class DefaultMethods implements Sayable{

public void sayMore(String msg){ // implementing abstract method

System.out.println(msg);

}

public static void main(String[] args) {

DefaultMethods dm = new DefaultMethods();

dm.say(); // calling default method

dm.sayMore("Work is worship"); // calling abstract method



}

}

16/01/2021

Java Optional Class

Java introduced a new class Optional in jdk8. It is a public final class and used to deal with NullPointerException in Java application. You must import java.util package to use this class. It provides methods which are used to check the presence of value for particular variable.

25/11/2020

Java 8 Stream

Java provides a new additional package in Java 8 called java.util.stream. This package consists of classes, interfaces and enum to allows functional-style operations on the elements. You can use stream by importing java.util.stream package.

12/11/2020

Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications.
It is a Spring module that provides the RAD (Rapid Application Development) feature to the Spring Framework. It is used to create a stand-alone Spring-based application that you can just run because it needs minimal Spring configuration.

In short, Spring Boot is the combination of Spring Framework and Embedded Servers.

12/11/2020

Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications.
It is a Spring module that provides the RAD (Rapid Application Development) feature to the Spring Framework. It is used to create a stand-alone Spring-based application that you can just run because it needs minimal Spring configuration.
In short, Spring Boot is the combination of Spring Framework and Embedded Servers.

24/06/2020

Concurrency

Computer users take it for granted that their systems can do more than one thing at a time. They assume that they can continue to work in a word processor, while other applications download files, manage the print queue, and stream audio. Even a single application is often expected to do more than one thing at a time. For example, that streaming audio application must simultaneously read the digital audio off the network, decompress it, manage playback, and update its display. Even the word processor should always be ready to respond to keyboard and mouse events, no matter how busy it is reformatting text or updating the display. Software that can do such things is known as concurrent software.
The Java platform is designed from the ground up to support concurrent programming, with basic concurrency support in the Java programming language and the Java class libraries. Since version 5.0, the Java platform has also included high-level concurrency APIs. This lesson introduces the platform's basic concurrency support and summarizes some of the high-level APIs in the java.util.concurrent packages

21/06/2020

Lambda expressions :

A very new and exciting feature, Java 8 ship with it, is java lambda expressions. They are not unknown to many of us who have worked on advanced languages like scala.

In fact, if you look at history and try to find out any language improvement in Java in last 2 decades, you will not be able to recall many exciting things. Only few concurrent classes, generics and if you agree then annotations as well, are remarkable additions in java in last decade. Lambda expressions break this drought and feels like a pleasant gift.

16/06/2020

Eagerly Initialized Singleton

This is the simplest approach wherein the instance of the class is created at the time of class loading -
public class EagerSingleton { /** private constructor to prevent others from instantiating this class */ private EagerSingleton() {} /** Create an instance of the class at the time of class loading */ private static final EagerSingleton instance = new EagerSingleton(); /** Provide a global point of access to the instance */ public static EagerSingleton getInstance() { return instance; } }
The disadvantage of this approach is that the instance is created irrespective of whether it is accessed or not. This is fine if the object is simple and does not hold any system resources. But can have performance implications if it allocates a large amount of system resources and remains unused.

2. Eagerly Initialized Static Block Singleton

You can also create the one-off instance of the class in a static block. This works because the static block is executed only once at the time of class loading.
The advantage with static block initialization is that you can write your initialization logic or handle exceptions in the static block.
public class EagerStaticBlockSingleton { private static final EagerStaticBlockSingleton instance; /** Don't let anyone else instantiate this class */ private EagerStaticBlockSingleton() {} /** Create the one-and-only instance in a static block */ static { try { instance = new EagerStaticBlockSingleton(); } catch (Exception ex) { throw ex; } } /** Provide a public method to get the instance that we created */ public static EagerStaticBlockSingleton getInstance() { return instance; } }
Just like the previous solution, the instance is created whether or not it is needed by the application.

3. Lazily Initialized Singleton

Lazy initialization means delaying the initialization of something until the first time it is needed.

16/06/2020

Singleton design pattern is used when you want to have only one instance of a given class.
It is a creational design pattern wherein we deal with the creation of objects.

Motivation and Real world examples

In object-oriented design, It’s very important for some classes to have only one instance. That’s because they represent something unique, something that’s one of its kind.
Let’s see some real-world examples of Singletons from the Java language to understand what that means -

java.lang.Runtime: Java provides a Runtime class that represents the current runtime environment in which an application is running. The application can interface with its runtime environment using this class.
Since the Runtime environment is unique, There should only be one instance of this class.

java.awt.Desktop: The Desktop class allows Java applications to launch a URI or a file with the applications that are registered on the native Desktop like the user’s default browser, or mail client.
The native Desktop and the associated applications are one-of-a-kinds. So there must be only one instance of the Desktop class.

Implementing the Singleton Design Pattern

How do you ensure that a class has only one instance? Well, there are several ways of doing this in Java. But all of them are based on the following basic ideas:

Declare a private constructor to prevent others from instantiating the class.

Create the instance of the class either during class loading in a static field/block, or on-demand in a static method that first checks whether the instance exists or not and creates a new one only if it doesn’t exist.

Let’s see all the possible solutions with code samples one by one:

1. Eagerly Initialized Singleton

This is the simplest approach wherein the instance of the class is created at the time of class loading -
public class EagerSingleton { /** private constructor to prevent others from instantiating this class */ private EagerSingleton() {} /** Create an instance of the class at

Want your business to be the top-listed Gym/sports Facility in Pune?

Click here to claim your Sponsored Listing.

Location

Telephone

Website

Address


Pune

Opening Hours

9am - 5pm