Java Full Stack Interview Questions
Java Full Stack Interview Questions
var a = NaN
var a = Number.NaN.
22. Explain Higher Order Functions in JavaScript?
Functions can be assigned to variables in the same way that strings or arrays can. They can be
passed into other functions as parameters or returned from them as well. A “higher-order
function” is a function that accepts functions as parameters and/or returns a function.
23. What are the rules to be followed for variable naming conventions in JavaScript?
Rules:
➢ JavaScript variable names are case sensitive. For example, Test and test are two
different variables.
➢ Don’t use any of the JavaScript reserved keywords as variable names. For example,
break or boolean variable names are not valid.
➢ JavaScript variable names should not start with a numeral (0-9). They must begin with
a letter or the underscore character. For example, 123name is an invalid variable name
but _123name or name123 is a valid one.
24.What are all the loops available in JavaScript?
JavaScript provides several types of loops to handle repeated tasks, such as:
➢ For loop
➢ While loop
➢ do.. while loop
➢ For…in loop
➢ For…of loop
25. What are the different types of errors available in JavaScript?
The three types of errors are:
➢ Load time Errors: come up when we load a web page with inappropriate syntax
Errors. They are generated dynamically.
➢ Run time Errors: are generated due to misuse of command inside an HTML
language.
➢ Logical Errors: occur due to the formation or writing off bad logic inside the
program.
26. Write a Java program to find the first non-repeated character in a string.
Program:
import java.util.LinkedHashMap;
import java.util.Map;
public class FirstNonRepeatedCharacter {
public static char firstNonRepeatedChar(String str) {
Map<Character, Integer> charCountMap = new LinkedHashMap<>();
for (char c : str.toCharArray()) {
charCountMap.put(c, charCountMap.getOrDefault(c, 0) + 1);
}
for (Map.Entry<Character, Integer> entry : charCountMap.entrySet()) {
if (entry.getValue() == 1) {
return entry.getKey();
}
}
throw new RuntimeException(No non-repeated character found);
}