Java Interview Programs @javainterviewprograms Channel on Telegram

Java Interview Programs

@javainterviewprograms


Here you will all important program that are asked in the interview

Java Interview Programs (English)

Are you a Java developer looking to ace your next job interview? Look no further than 'Java Interview Programs' Telegram channel! This channel, with the username @javainterviewprograms, is dedicated to providing you with all the important programming questions and solutions that are commonly asked during Java interviews. Whether you are a beginner or an experienced developer, this channel is your one-stop destination to prepare for those tough technical interviews

Who is it for? This channel is for Java developers of all levels who are preparing for job interviews. Whether you are a fresh graduate looking for your first job in the tech industry or a seasoned professional aiming for a career advancement, 'Java Interview Programs' has got you covered

What is it? 'Java Interview Programs' is a treasure trove of programming questions and solutions that are specifically tailored to help you succeed in Java interviews. From basic programming concepts to advanced data structures and algorithms, this channel covers a wide range of topics that are essential for any Java developer to master

So, why wait? Join 'Java Interview Programs' Telegram channel today and start preparing for your next interview with confidence! Remember, success in your job interview starts with solid preparation, and this channel is here to support you every step of the way.

Java Interview Programs

19 Oct, 15:28


import java.util.Arrays;
import java.util.LinkedHashSet;

public class ArrayExample
{
public static void main(String[] args) throws CloneNotSupportedException
{
//Array with duplicate elements
Integer[] numbers = new Integer[] {1,2,3,4,5,1,3,5};

//This array has duplicate elements
System.out.println( Arrays.toString(numbers) );

//Create set from array elements
LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>( Arrays.asList(numbers) );

//Get back the array without duplicates
Integer[] numbersWithoutDuplicates = linkedHashSet.toArray(new Integer[] {});

//Verify the array content
System.out.println( Arrays.toString(numbersWithoutDuplicates) );
}
}

Java Interview Programs

13 Oct, 11:42


https://www.journaldev.com/16928/java-string

Java Interview Programs

11 Oct, 15:12


https://javatutoring.com/java-programs/

Java Interview Programs

11 Oct, 15:11


https://javatutoring.com/prime-number-java-program/

Java Interview Programs

10 Sep, 16:15


What is a Lambda expression in Java ?



A Lambda expression represents an Anonymous method.



Anonymous method concept is similar to that of an Anonymous class… the difference being it implements a functional interface.



Functional interface is a new interface concept in Java 8. A functional interface can only declare one abstract method.



Lambda expressions allow the programmer to pass code in a concise manner making the code more clearer and flexible.


Lambda syntax



A lambda expression contains:

A parameter list
An arrow symbol(->)
Body of the lambda containing statements



The syntax for Lambda expressions is:

(parameters) -> {statements;}


How to write simple methods as lambda expression



Here is a simple method that displays a message “Hello World”.


1
2
3
4
5


public void hello(){
System.out.println("Hello World");
}


To convert this method to a lambda expression, remove the access specifier “public”, return type “void” and method name “hello” and write it as :
1
2
3


() -> {System.out.println("Hello World");}




Here is another method example that adds two numbers and returns their sum :


1
2
3
4
5


int add(int x, int y){
return x+y;
}




This method can be converted to lambda expression as :


1
2
3


(int x, int y) -> {return x+y;}



Important points about lambda expressions



Here are some notable points regarding lambda expressions :


1 ) A lambda expression can have zero or more parameters.



Here is an example of lambda expression with zero parameters:


1
2
3


() -> {System.out.println("Hello World");}




Here is an example of lambda expression with two parameters:


1
2
3


(int x, int y) -> {return x+y;}




This lambda expression accepts two integer parameters and returns their sum.


2) If the type of the parameters can be decided by the compiler, then we can ignore adding them in the lambda expression.


1
2
3
4
5


(int x, int y) -> {return x+y;} // type mentioned

(x,y) -> {return x+y;}; // type ingored



3) If there is only one parameter, the parenthesis of parameter can be omitted.



Here are some examples :
1
2
3
4
5
6
7


x -> {return x+10;}

String s -> s.toUpperCase()

String s -> System.out.println(s)



4) If the body has just one expression, the return keyword and curly braces can be omitted as show below:


1
2
3


(int x, int y) -> x + y




If the return type of parameters is omitted, the compiler determines default parameter types.


1
2
3
4
5


(x,y) -> x+y

(str, i) -> str.substring(i)



5) A lambda can also have empty parameters


1
2
3
4
5


() -> {return “Hello”;}

() -> System.out.println(“Hello”)



6) A lambda can also have empty parameter as well as empty body


1
2
3


() -> {}




This represents a valid lambda expression that takes no parameters and returns void.


How to call a lambda expression ?



Once a lambda expression is written, it can be called and executed like a method.



For calling a lambda expression, we should create a functional interface.



Here is an example that uses functional interface to execute lambda expression :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16



public class FuntionalInterfaceDemo {

interface MyInter{
void hello();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyInter infVar = () -> {System.out.println("Hello World");};

infVar.hello();
}

}




Refer more details on functional interface and executing lambda expressions in the following article:



Running lambda expression with Functional Interface

Java Interview Programs

23 Aug, 10:38


class FibonacciExample2
{
static int n1=0,n2=1,n3=0;
static void printFibonacci(int count)
{
if(count>0)
{
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3);
printFibonacci(count-1);
}
}
public static void main(String args[])
{
int count=10;
System.out.print(n1+" "+n2);
//printing 0 and 1
printFibonacci(count-2);
//n-2 because 2 numbers are already printed
}
}