Java Core And Advanced Java

  1. What is the use of garbage collection in Java? The use of garbage collection in Java is to recognize and remove objects that are no more required by a program and are unnecessary consuming the program resources that could be freed and reused by other objects. An object in Java is subject to garbage collection when it turns inaccessible to the Java program in which it is initiated. 2. What are Lambda Expressions? Lambda Expressions, often called lambdas, are a new feature introduced with Java 8. They provide an easier way to work with interfaces that have only got one method, and they are often used in places where the programmer use anonymous classes. 3.What do you understand by thread in Java? A thread is a single sequential flow of control within a process where each process can contain two or more "threads". In Java, a thread is created and coordinated by the  java.lang.Thread class . 4.Write a Program to Swap Two Numbers. import java.util.*; class  SwapDemo { static