Core Java - Interview Questions and Answers for 'Core Java' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q631. What are the different operators in Java ?Core Java
Ans. && - AND
|| - OR
! - LOGICAL NOT

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     operators      Basic


 Q632. Write a Program to check if a number is perfect or notCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       int number = 7;
       boolean perfectNumber = true;
       for(int x=2;x<number;x++){
          if(number % x == 0){
             perfectNumber = false;
          }
       }
      
       if(perfectNumber){
          System.out.println("Perfect Number");
       } else {
          System.out.println("Not a Perfect Number");
       }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q633. Write a Program to print all perfect numbers from 1 to 100Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
      for(int number=1;number < 100;number++){
          boolean perfectNumber = true;
          for(int x=2;x<number;x++){
             if(number % x == 0){
                perfectNumber = false;
             }
          }
         
          if(perfectNumber){
             System.out.println(number);
          }
       }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q634. What is a method reference in Java ?Core Java
Ans. Introduced with java 8 , Method References help us to point to methods by their name.

A method references is described using :: symbol

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     method reference  java 8  lambda expressions


 Q635. Write a Program to print index of first capital character in a string.Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly do excellence, then, is not an Act but a habit";
       int count = 1;
       for(Character c: str.toCharArray()){
          if(Character.isUpperCase(c)){
             break;
          } else {
             count++;
          }
       }
      
       System.out.println(count);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q636. Write a Program to count number of capital characters in a StringCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "We are what we repeatedly do excellence, then, is not an Act but a habit";
       int count = 0;
       for(Character c: str.toCharArray()){
          if(Character.isUpperCase(c)){
             count++;
          }
       }
      
       System.out.println(count);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q637. Write a Program to count number of lower case characters in a StringCore Java
Ans. public class BuggyBread1 {
   public static void main(String args[]) {
       String str = "We are what we repeatedly do excellence, then, is not an Act but a habit";
       int count = 0;
       for(Character c: str.toCharArray()){
          if(Character.isLowerCase(c)){
             count++;
          }
       }
      
       System.out.println(count);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q638. Write a Program to print first word with a capital character in a StringCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly do excellence, then, is not an act but a haBit";
       String wordWithCaptalChar = "";
      
       for(String word:str.split(" ")){
          if(!word.equals(word.toLowerCase())){
             wordWithCaptalChar = word;
          }
       }
      
       System.out.println(wordWithCaptalChar);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q639. Write a Program to print the word in a String starting with a capital characterCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
       String wordWithFirstCaptalChar = "";
      
       for(String word:str.split(" ")){
          if(Character.isUpperCase(word.charAt(0))){
             wordWithFirstCaptalChar = word;
          }
       }
      
       System.out.println(wordWithFirstCaptalChar);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q640. Write a Program to count number of words in a StringCore Java
Ans. public class BuggyBread1 {
   public static void main(String args[]) {
       String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
      
       System.out.println(str.split(" ").length);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q641. Write a Program to print duplicate words in a StringCore Java
Ans. public class BuggyBread {
public static void main(String args[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
Set<String> words = new HashSet();
for(String word:str.split(" ")){
if(words.contains(word)){
System.out.println(word);
} else {
words.add(word);
}
}
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q642. Write a Program to print words of a String starting with character wCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
       for(String word:str.split(" ")){
          if(word.startsWith("w")){
             System.out.println(word);
          }
       }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q643. Write a Program to print words of a String containing the specified String.

For example - Print all words having characters ha
Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
       for(String word:str.split(" ")){
          if(word.contains("ha")){
             System.out.println(word);
          }
       }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q644. Write a Program to print words in a string having length greater than 2 and third characters being pCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
       for(String word:str.split(" ")){
          if(word.length() > 2 && word.charAt(2) == 'p'){
             System.out.println(word);
          }
       }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q645. Write a Program to print words of a String having length greater than 2 and ending with itCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
       for(String word:str.split(" ")){
          if(word.length() > 2 && word.endsWith("it")){
             System.out.println(word);
          }
       }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q646. Write code to find second largest number in an array of integers.Core Java
Ans. int arr[]={1,3,5,6,4,8,9,2,10};
Arrays.sort();
System.out.println(arr[arr.length-1]);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     code  coding  find in array     Asked in 1 Companies


 Q647. Write a Program to find common words in 2 separate stringsCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str1 = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
       String str2 = "we are what we repeatedly Do is";
       String[] str1Words = str1.split(" ");
       String[] str2Words = str2.split(" ");
      
       Set str1WordsSet = new HashSet();
      
       for(String word:str1Words){
          str1WordsSet.add(word);
       }
      
       for(String word:str2Words){
          if(str1WordsSet.contains(word)){
             System.out.println(word);
          }
       }
      
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     String  coding  code


 Q648. Write a program to print count / no of common words in 2 separate stringsCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str1 = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
       String str2 = "we are what we repeatedly Do is";
       String[] str1Words = str1.split(" ");
       String[] str2Words = str2.split(" ");
      
       Set str1WordsSet = new HashSet();
      
       for(String word:str1Words){
          str1WordsSet.add(word);
       }
      
       int commonWordsCount = 0;
      
       for(String word:str2Words){
          if(str1WordsSet.contains(word)){
             commonWordsCount++;
          }
       }
      
       System.out.println(commonWordsCount);
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     String  coding  code


 Q649. Write a Program to remove duplicate words from the StringCore Java
Ans.
public class BuggyBread {
public static void main(String args[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
Set<String> wordSet = new LinkedHashSet(); // Using Linked Hash Set as we would like to retrieve words in the insertion order

for(String word: str.split(" ")){
wordSet.add(word);
}

for(String word: wordSet){
System.out.print(word);
System.out.print(" ");
}
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     String  coding  code     Asked in 1 Companies      basic


 Q650. Write a Program to display the words of a String in alpahbetical or Dictionary OrderCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       String str = "we are what we repeatedly do excellence then is not an act but a haBit";
       Set<String> wordSet = new TreeSet(); // Using Linked Hash Set as we would like to retrieve words in the insertion order
      
       for(String word: str.split(" ")){
          wordSet.add(word);
       }
      
       for(String word: wordSet){
          System.out.print(word);
          System.out.print(" ");
       }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     String  coding  code


 Q651. Write a program to print sum of numbers between the start and end number

For example - Passing start number as 2 and end number as 10, it should print 2+3+4+5+6+7+8+9+10 = 54
Core Java
Ans.
public class BuggyBread {
   public static void main(String args[]) {
       System.out.println(sum(2,10));
   }
   
   private static int sum(int start,int end){
      if(start > end){
         return 0;
      } else {
         return start + sum(start+1,end);
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     recursion


 Q652. Write a program using Recursion to print multiplication of numbers between the start and end number

For example - Passing start number as 2 and end number as 10, it should print 2*3*4*5*6*7*8*9*10 = 3628800
Core Java
Ans.
public class BuggyBread {
   public static void main(String args[]) {
       System.out.println(multiply(2,5));
   }
   
   private static int multiply(int start,int end){
      if(start > end){
         return 1;
      } else {
         return start * multiply(start+1,end);
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     recursion


 Q653. Write a Program to display numbers between 2 numbers using recursionCore Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       displayNumbersBetween(2,10);
   }
   
   private static void displayNumbersBetween(int start,int end){
      if(start > end){
         return ;
      } else {
         System.out.println(start);
         displayNumbersBetween(start+1,end);
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     recursion  code  coding


 Q654. Write a Program to print asterix like following using Recursion

**
***
****
*****
******
*******
********
*********
**********

Program should set the start and end index and then display this accordingly. For example the above pattern is for displayNumbersBetween(2,10) and following is for displayNumbersBetween(5,7)

*****
******
*******
Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
       displayNumbersBetween(5,7);
   }
   
   private static void displayNumbersBetween(int start,int end){
      if(start > end){
         return ;
      } else {
         for(int x=1;x<=start;x++){
            System.out.print("*");
         }
         System.out.println("");
         displayNumbersBetween(start+1,end);
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     recursion  code  coding


 Q655. Write a Program to print pattern like following

*
**
***
****
*****
******
*******
********
*********
**********
Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
      for(int x=1;x<=10;x++){
         for(int y=1;y<=x;y++){
            System.out.print("*");
         }
         
         System.out.println("");
      }   
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     coding  code


 Q656. Write a Program to print pattern like following

*_**_***_****_*****_***************
Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
      for(int x=1;x<=5;x++){
         for(int y=1;y<=x;y++){
            System.out.print("*");
         }
         
         System.out.print("_");
      }
      
      for(int x=5;x>=1;x--){
         for(int y=1;y<=x;y++){
            System.out.print("*");
         }
         
         System.out.print("");
      }   
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q657. Write a Program to print numbers like following

1
12
123
1234
12345
Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
      for(int x=1;x<=5;x++){
         for(int y=1;y<=x;y++){
            System.out.print(y);
         }
         
         System.out.println(" ");
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q658. Write a Program to print numbers like following

1
22
333
4444
55555
Core Java
Ans. public class BuggyBread {
   public static void main(String args[]) {
      for(int x=1;x<=5;x++){
         for(int y=1;y<=x;y++){
            System.out.print(x);
         }
         
         System.out.println(" ");
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     


 Q659. Difference between concurrentHashMap and HashTable ?Core Java
Ans. HashTable locks the complete collection to provide synchronization whereas ConcurrentHashMap only locks segments to achieve synchronization and hence better efficient and faster.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     concurrentHashMap  HashTable  Map  Collections     Asked in 2 Companies


 Q660. isnt the use of HashTable and ConcurrentHashMap the same, i.e providing synchronized map collection ?Core Java
Ans. Yes, they both aim at providing synchronized access to the Map collection. The only difference is in their implementation. ConcurrentHashMap came after HashTable and hence technically more efficient as it doesn't lock the complete map while accessing it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     HashTable  ConcurrentHashMap  map  Collections


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: