Java Real Time Interview Questions Selenium WebDriver
- Find out the number is
odd or even
- Reverse Order of a String –
totalqa
- Palindrome of the string
- Fibonacci series
- Factorial of a number using Recursion
- Printing numbers from
1..10
using Recursion - Finding the duplicate characters in a String
- Reading and Writing to a File
- Counting the number of words in a file. Selenium
- Finding the random value of given range .. 100
- Conversion of String to Integer and Integer to String
- try/catch/finally try/finally try/catch/catch/finally
- final keywords methods,classes,variables.
- Sorting the numbers- Bubble Sorting
- Sorting the strings
- String Functions
- Difference between String and StringBuffer
- Difference between HashMap and HashTable
- Difference between List and Set
- Converting an String to Integer
- Converting an String to Double
- DataTypes
- Execution Flow of a Java Program
totalqa --> t-2 o -1 a-2 q-1
split(),equals(),contains(),trim(),equalsIgnoreCase(),length()
short,byte,int,long,double,float,boolean,char
Sorting the numbers- Bubble Sorting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
package javaassignments; public class BubbleSorting { public static void main(String[] args) { int a[]={50,20,80,10}; int temp; for(int i = 0 ; i< a.length;i++) { for(int j=i+1;j<a.length;j++) { if(a[i]>a[j]) { temp= a[i];//30 a[i]=a[j]; //10 a[j]=temp; //30 } } } //after sorting for(int i=0;i<a.length;i++) { System.out.println(a[i]); } } } |
Palindrome
A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package javaassignments; public class Palindrome { public static void main(String[] args) { int n = 121; int r=n%10; int count=0; System.out.println(r); while(n>0) { r=n%10; count=(count*10)+r; System.out.println("value of count" + count); n=n/10; } System.out.println(count); } } |
Conversion Examples: Converting an Integer to String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package javaassignments; public class ConversionStringToInteger { public static void main(String[] args) { /** * String is a class * String is immutable * String is a final Class cannot be extended */ String s= "1,23,507";//int 4 bytes long 8 bytes Integer i = Integer.parseInt(s.replace(",","")); System.out.println(i); s= i.toString(); System.out.println(s); //String & StringBuilder differences String s1 =" abc"; s1.concat("def"); System.out.println("value of s1"+s1 ); StringBuffer s2 = new StringBuffer("abc"); s2.append("def"); System.out.println("value of s2"+s2); } } |
Finding the duplicate characters in a String using HashMap
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class CountCharsInString { public static void main(String[] args) { String str ="totalqa"; Map<Character,Integer> map = new HashMap<Character,Integer>(); for(int i = 0;i<str.length();i++) { System.out.println(str.charAt(i)); if(map.get(str.charAt(i))==null) { map.put( str.charAt(i),1); } else { map.put(str.charAt(i),map.get(str.charAt(i))+1); } } System.out.println("size is " + map.size()); Set<Character> set = map.keySet(); Iterator<Character> it=set.iterator(); while(it.hasNext()) { Character ch= it.next(); System.out.println(ch + " -- "+map.get(ch)); } } } |
Hello, what does using recursion mean in #5 and #6? Thanks!
A recursion is mainly calling the method itself to solve the problem.
We will update you once answers are posted.
Very useful website and the java points are crisp and easy to understand.
Please add simple logic for rest of the unanswered Java programs. It will be useful for interviews to remember simple logic.
Thanks for the comments. Will update it accordingly.
Hi will share , interview questions on string in java to clear tricky interviews
Really nice website to learn simple,please update some more examples
Good collection of real time interview questions will help to clear the interviews easily, example like the post above also can find Java latest updates to proceed further.