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

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Coding' - 110 question(s) found - Order By Newest

next 100
 Q1. What will this code print ?

String a = new String ("TEST");
String b = new String ("TEST");
if(a == b) {
System.out.println ("TRUE");
} else {
System.out.println ("FALSE");
}
Core Java
Anonymous
Ans. FALSE. == operator compares object references, a and b are references to two different objects, hence the FALSE. .equals method is used to compare string object content.

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

   Like      Discuss      Correct / Improve     string   string class   java   ==   object references   coding      basic        frequent

Try 1 Question(s) Test


 Q2. How to find whether a given integer is odd or even without use of modules operator in java?Core Java
Admin
info@buggybread.com
Ans. public static void main(String ar[])
{
int n=5;
if((n/2)*2==n)
{
System.out.println("Even Number ");
}
else
{
System.out.println("Odd Number ");
}
}

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

   Like      Discuss      Correct / Improve     java   code   coding   tricky questions   interesting questions     Agnity  Amdocs  Asurion  Oodles Technologies        frequent


 Q3. What will be the output of following Code ?

class BuggyBread {
   public static void main(String[] args) {
      String s2 = "I am unique!";
      String s5 = "I am unique!";

      System.out.println(s2 == s5);
   }
}
Core Java
Admin
info@buggybread.com
Ans. true, due to String Pool, both will point to a same String object.

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

   Like      Discuss      Correct / Improve     java   code   coding   tricky questions   interesting questions   string   string pool   .equal   ==      intermediate        frequent


 Q4. What will be the output of following code ?
class BuggyBread2 {       
   private static int counter = 0;     
   void BuggyBread2() {        
      counter = 5;    
   }     
   
   BuggyBread2(int x){
      counter = x;    
   }        

   public static void main(String[] args) {        
      BuggyBread2 bg = new BuggyBread2();        
      System.out.println(counter);    
   } 
}
Core Java
Admin
info@buggybread.com
Ans.  Compile time error as it won't find the constructor matching BuggyBread2(). 
Compiler won't provide default no argument constructor as programmer has already defined one constructor. 
Compiler will treat user defined BuggyBread2() as a method, as return type ( void ) has been specified for that. 

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

   Like      Discuss      Correct / Improve     java   code   coding   tricky questions   interesting questions   default constructor   constructor

Try 3 Question(s) Test


 Q5. What will be the output of following code ?

public static void main(String[] args){
String name = null;
File file = new File("/folder", name);
System.out.print(file.exists());
}
Admin
info@buggybread.com
Ans. NullPointerException at line:

"File file = new File("/folder", name);"

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code


 Q6. What will be the output of following code ?

public static void main(String[] args){
   String parent = null;
   File file = new File(parent, "myfile.txt");
   try {
      file.createNewFile();
   } catch (IOException e) {
      e.printStackTrace();
   }
}
Admin
info@buggybread.com
Ans.  It will create the file myfile.txt in the current directory.

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code


 Q7. What will be the output of this code ?

Set mySet = new HashSet();
mySet.add("4567");
mySet.add("5678");
mySet.add("6789");
for(String s: mySet){
System.out.println(s);
}
admin
info@buggybread.com
Ans. It will print 4567,5678 and 6789 but Order cannot be predicted.

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

   Like      Discuss      Correct / Improve     java   collections   set   hashset   coding   code

Try 1 Question(s) Test


 Q8. What will be the output of this code ?

Set mySet = new HashSet();
mySet.add("4567");
mySet.add("5678");
mySet.add("6789");
System.out.println(s.get(0));
admin
info@buggybread.com
Ans. This will give compile time error as we cannot retrieve the element from a specified index using Set. Set doesn't maintain elements in any order.

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

   Like      Discuss      Correct / Improve     java   collections   set   hashset   coding   code

Try 1 Question(s) Test


 Q9. Write an algorithm / Java Program to show duplicates in an array of n elements?Algorithm2017-01-19 15:37:26

Ans. int duplicateArray[] = { 1, 2, 2, 3, 4, 5, 6, 8, 9}
Set unique = new HashSet();
for (int i = 0; i < duplicateArray.length; i) {
if (unique.contains(duplicateArray[i])) {
System.out.println(duplicateArray[i]);
} else {
unique.add(duplicateArray[i]);
}
}

Complexity O(n) = nHashSet contains and add has O(n) = 1

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

   Like      Discuss      Correct / Improve     coding  code     Deloitte



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?
Anonymous
Ans. Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

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

   Like      Discuss      Correct / Improve     character coding   ascii   unicode   utf

Try 1 Question(s) Test


 Q11. What is unicode ?Core Java
Anonymous
Ans. A way of encoding characters as binary numbers. The Unicode character set includes
characters used in many languages, not just English. Unicode is the character set that is
used internally by Java.

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

   Like      Discuss      Correct / Improve     java   character encoding   unicode   architecture


 Q12. Write a program to print the index of the first non repeated character in a java stringCore Java2017-01-27 18:30:21

Ans. public class BuggyBread1{
public static void main (String args[]) {
   String str = "hheello world";
   char[] charArray = str.toCharArray();
   char selectedChar = 'a';
   for(char char1: charArray){
      if(!str.contains(Character.toString(char1).concat(Character.toString(char1)))){
         selectedChar = char1;
         break;
      }
   }
   System.out.println(str.indexOf(Character.toString(selectedChar)));
}
}

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

   Like      Discuss      Correct / Improve     string  code  coding     Audible  Bluewolf  WorkDay  Symantec  Rubicon  Amazon  Expedia  A9.com  Google


 Q13. Write a Program to add 1-100, 101-200, 201-300 in different threads and then sum the numbers ?Core Java2016-11-30 20:51:58

Ans. public class TotalUsingThreads extends Thread{
   
   private static List<TotalUsingThreads> collector = new ArrayList<TotalUsingThreads>();
   
   private int startFrom = 0;
   
   private Integer threadTotal = null;
   
   Test(int startFrom){
      this.startFrom = startFrom;
   }
   
   
   public static void main(String[] args) throws InterruptedException{
      int totalSum = 0;
      
      // Create all the threads and set the count starting point for all of them
      for(int count=0;count<10;count++){
         TotalUsingThreads newThread = new TotalUsingThreads(count*100);
         newThread.start();
         collector.add(newThread);
      }
      
      boolean allCollected = false;
      
      
      // Make sure that all thread totals are collected and all threads have completed their tasks
      while(!allCollected){
         for(int count=0;count<10;count++){
            if(collector.get(count).threadTotal == null){
               Thread.sleep(100);
               break;
            }
         }
         allCollected = true;
      }
      
      // sum totals of all threads
      for(int count=0;count<10;count++){
         totalSum += collector.get(count).threadTotal;
      }
      
      System.out.println(totalSum);
      
      
   }
   
   public void run(){
      threadTotal = 0;
      for(int count=startFrom;count<startFrom+100;count++){
       threadTotal += count;   
      }
   }
}

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

   Like      Discuss      Correct / Improve     coding  code  threads  multithreading     AQUA Equities


 Q14. Write a method to convert binary to a number ?Core Java
Admin
info@buggybread.com
Ans.
convert(int binaryInt) {
   int sumValue=0;
   int multiple = 1;
   while(binaryInt > 0){
      binaryDigit = binaryInt%10;
      binaryInt = binaryInt /10;
      sumValue = sumValue + (binaryDigit * multiple);
      multiple = multiple * 2;
   }
   return sumValue;
}

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

   Like      Discuss      Correct / Improve     java   binary   interesting question   coding


 Q15. What will be the output of the following code ?

String s1 = "Buggy Bread";
String s2 = "Buggy Bread";
if(s1 == s2)
   System.out.println("equal 1");
String n1 = new String("Buggy Bread");
String n2 = new String("Buggy Bread");
if(n1 == n2)
   System.out.println("equal 2");
Core Java
Admin
info@buggybread.com
Ans. equal 1

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

   Like      Discuss      Correct / Improve     java   string class   string   string pool   code   coding      basic        frequent


 Q16. what will be the output of this code ?

public static void main(String[] args){
   StringBuffer s1=new StringBuffer("Buggy");                       
   test(s1);                    
   System.out.println(s1);              
}       

private static void test(StringBuffer s){      
   s.append("Bread");   
}
Core Java
Admin
info@buggybread.com
Ans.  BuggyBread

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

   Like      Discuss      Correct / Improve     java   code   coding   stringbuffer   string   method calling   pass by reference


 Q17. what will be the output of this code ?

public static void main(String[] args)    {          
   String s1=new String("Buggy");                         
   test(s1);                    
   System.out.println(s1);              
}       

private static void test(StringBuffer s){      
   s.append("Bread");   
}
Core Java
Admin
info@buggybread.com
Ans.  Buggy

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

   Like      Discuss      Correct / Improve     java   code   coding   stringbuffer   string   method calling   pass by reference


 Q18. what will be the output of this code ?

public static void main(String[] args)    {          
   StringBuffer s1=new StringBuffer("Buggy");                         
   test(s1);                    
   System.out.println(s1);              
}       

private static void test(StringBuffer s){      
   s=new StringBuffer("Bread");   
}
Core Java
Admin
info@buggybread.com
Ans.  Buggy

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

   Like      Discuss      Correct / Improve     java   code   coding   stringbuffer   string   method calling   pass by reference


 Q19. what will be the output ?

class Animal {
public void eat() throws Exception {
}
}

class Dog2 extends Animal {
public void eat(){}
public static void main(){
Animal an = new Dog2();
an.eat();
}
}
Core Java
Admin
info@buggybread.com
Ans. Compile Time Error: Unhandled exception type Exception

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

   Like      Discuss      Correct / Improve     java   code   coding   overridding   late binding   exception handling   abstract class   abstract methods



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. What will the following code print when executed on Windows ?

public static void main(String[] args){
   String parent = null;
   File file = new File("/file.txt");
   System.out.println(file.getPath());
   System.out.println(file.getAbsolutePath());
   try {
      System.out.println(file.getCanonicalPath());
   } catch (IOException e) {
      e.printStackTrace();
   }
}
Admin
info@buggybread.com
Ans.  file.txtC:file.txtC:file.txt

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code


 Q21. What will be the output of following code ?

public static void main(String[] args){
   String child = null;
   File file = new File("/folder", child);
   try {
      file.createNewFile();
   } catch (IOException e) {
      e.printStackTrace();
   }
}
Admin
info@buggybread.com
Ans.  NullPointerException at line:File file = new File("/folder", child);

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code


 Q22. What will be the output of following code, assuming that currently we are in c:Project ? 

public static void main(String[] args){
      String child = null;
      File file = new File("../file.txt");
      System.out.println(file.getPath());
      System.out.println(file.getAbsolutePath());
      try {
         System.out.println(file.getCanonicalPath());
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }
Admin
info@buggybread.com
Ans. ..file.txt
C:WorkspaceProject..file.txt
C:Workspacefile.txt

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code


 Q23. Which of the following code is correct ?

a.


FileWriter fileWriter = new FileWriter("../file.txt");
File file = new File(fileWriter );
BufferedWriter bufferedOutputWriter = new BufferedWriter(fileWriter);

b.

BufferedWriter bufferedOutputWriter = new BufferedWriter("../file.txt");
File file = new File(bufferedOutputWriter );
FileWriter fileWriter = new FileWriter(file);


c.

File file = new File("../file.txt");
FileWriter fileWriter = new FileWriter(file);
BufferedWriter bufferedOutputWriter = new BufferedWriter(fileWriter);

d.

File file = new File("../file.txt");
BufferedWriter bufferedOutputWriter = new BufferedWriter(file);
FileWriter fileWriter = new FileWriter(bufferedOutputWriter );
Admin
info@buggybread.com
Ans. c.

File file = new File("../file.txt");
FileWriter fileWriter = new FileWriter(file);
BufferedWriter bufferedOutputWriter = new BufferedWriter(fileWriter);

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   filewriter   bufferedwriter   scjp   ocjp


 Q24. Which exception should be handled in the following code ?

File file = new File("../file.txt");
FileWriter fileWriter = new FileWriter(file);
Admin
info@buggybread.com
Ans. IOException

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   exception   ioexception


 Q25. Which exceptions should be handled with the following code ?

FileOutputStream fileOutputStream = new FileOutputStream(new File("newFile.txt"));
Admin
info@buggybread.com
Ans. FileNotFoundException

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   scjp   ocjp   filenotfoundexception   fileoutputstream


 Q26. Will this code compile fine ?

ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
Core Java
Admin
info@buggybread.com
Ans. Yes.

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   objectoutputstream   fileoutputstream   yesno


 Q27. What is the problem with this code ?

class BuggyBread1 {

   private BuggyBread2 buggybread2;

   public static void main(String[] args){
      try {
         BuggyBread1 buggybread1 = new BuggyBread1();
         ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
         objectOutputStream.writeObject(buggybread1);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
Core Java
Admin
info@buggybread.com
Ans. Though we are trying to serialize BuggyBread1 object but we haven't declared the class to implement Serializable.

This will throw java.io.NotSerializableException upon execution.

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   serialization   notserializableexception   exception


 Q28. Will this code run fine if BuggyBread2 doesn't implement Serializable interface ?

class BuggyBread1 implements Serializable{
   private BuggyBread2 buggybread2 = new BuggyBread2();

   public static void main(String[] args){
      try {
         BuggyBread1 buggybread1 = new BuggyBread1();
         ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
         objectOutputStream.writeObject(buggybread1);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
Core Java
Admin
info@buggybread.com
Ans.  No, It will throw java.io.NotSerializableException.

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   serialization   notserializableexception   exception


 Q29. Will this code work fine if BuggyBread2 doesn't implement Serializable ?

class BuggyBread1 extends BuggyBread2 implements Serializable{
   private int x = 5;

   public static void main(String[] args){
      try {
         BuggyBread1 buggybread1 = new BuggyBread1();
         ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
         objectOutputStream.writeObject(buggybread1);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}
Core Java
Admin
info@buggybread.com
Ans.  Yes.

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

   Like      Discuss      Correct / Improve     java   io   file   fileio   coding   code   serialization   yesno



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. What will the following code print ?

java.util.Calendar c = java.util.Calendar.getInstance();
c.add(Calendar.MONTH, 5);
System.out.println(c.getTime());
Core Java
Admin
info@buggybread.com
Ans. Date and Time after 5 months from now.

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

   Like      Discuss      Correct / Improve     java   date   calendar   scjp   ocjp   coding   code


 Q31. What's wrong with this code ?

public static void main(String[] args) {
String regex = "(\\w+)*";
String s = "Java is a programming language.";

Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(s);
while (matcher.next()) {
System.out.println("The e-mail id is: " + matcher.group());
}
}
Core Java
Admin
info@buggybread.com
Ans. matcher.find() should have been used instead of matcher.next() within while.

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

   Like      Discuss      Correct / Improve     java   regex   pattern.matcher   java.util   coding   code


 Q32. Write a program to see if the number is perfect number or not ?Core Java
Admin
info@buggybread.com
Ans. http://www.c4learn.com/c-programs/program-to-check-whether-number-is.html

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

   Like      Discuss      Correct / Improve     java   at&t   coding


 Q33. What will be the output of this code ?

Set mySet = new TreeSet();
mySet.add("4567");
mySet.add("5678");
mySet.add("6789");
for(String s: mySet){
System.out.println(s);
}
admin
info@buggybread.com
Ans. 4567
5678
6789

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

   Like      Discuss      Correct / Improve     java   collections   set   treeset   coding   code


 Q34. public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}

public class Test {
Set mySet = new HashSet();
mySet.add(Day.MONDAY);
mySet.add(Day.SUNDAY);
mySet.add(Day.SATURDAY);

for(Day d: mySet){
System.out.println(d);
}
}
admin
info@buggybread.com
Ans. SUNDAY
MONDAY
SATURDAY

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

   Like      Discuss      Correct / Improve     enum   set   collections   hashset   coding   code

Try 3 Question(s) Test


 Q35. What will be the output of the following code ?

enum Day {
   MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY
}

public class BuggyBread1{
   public static void main (String args[]) {
      Set mySet = new HashSet();
      mySet.add(Day.SATURDAY);
      mySet.add(Day.WEDNESDAY);
      mySet.add(Day.FRIDAY);
      mySet.add(Day.WEDNESDAY);
      for(Day d: mySet){
         System.out.println(d);
      }
   }
}
Admin
info@buggybread.com
Ans. FRIDAY , SATURDAY and WEDNESDAY will be printed but the order cannot be determined.

Only one FRIDAY will be printed as Set doesn't allow duplicates. Order cannot be determined as HashSet doesn't maintain elements in a particular order. 

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

   Like      Discuss      Correct / Improve     java   code   coding   enum   set   hashset

Try 3 Question(s) Test


 Q36. What will be the output of the following code ?

enum Day {
MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY
}

public class BuggyBread1{
public static void main (String args[]) {
Set mySet = new TreeSet();
mySet.add(Day.SATURDAY);
mySet.add(Day.WEDNESDAY);
mySet.add(Day.FRIDAY);
mySet.add(Day.WEDNESDAY);
for(Day d: mySet){
System.out.println(d);
}
}
}
Core Java
Admin
info@buggybread.com
Ans. WEDNESDAY
FRIDAY
SATURDAY

Only one FRIDAY will be printed as Set doesn't allow duplicates.Elements will be printed in the order in which constants are declared in the Enum. TreeSet maintains the elements in the ascending order which is identified by the defined compareTo method. compareTo method in Enum has been defined such that the constant declared later are greater than the constants declared prior.

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

   Like      Discuss      Correct / Improve     java   code   coding   enum   set   treeset   advanced

Try 3 Question(s) Test


 Q37. public class BuggyBread1{

public static void main (String args[]) {
Set<String> mySet = new TreeSet<String>();
mySet.add(""1"");
mySet.add(""2"");
mySet.add(""111"");
for(String d: mySet){
System.out.println(d);
}
}
}
Core Java
Admin
info@buggybread.com
Ans. 1
111
2

TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in String has been defined such that it results in the natural alphabetic Order. Here the elements in the TreeSet are of String and not of Integer. In String Natural Order, 111 comes before 2 as ascii of 1st character first determines the order.

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

   Like      Discuss      Correct / Improve     java   code   coding   set   treeset   string   integer


 Q38. public class BuggyBread1{

public static void main (String args[]) {
Set<Integer> mySet = new TreeSet<Integer>();
mySet.add(1);
mySet.add(2);
mySet.add(111);
for(Integer d: mySet){
System.out.println(d);
}
}
}
Core Java
Admin
info@buggybread.com
Ans. 1
2
111

TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in Integer has been defined such that it results in the natural numerical Order.

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

   Like      Discuss      Correct / Improve     java   code   coding   set   treeset


 Q39. Will this Code compile ?

abstract public class BuggyBread1{
abstract public void test(){};
}
Core Java
Admin
info@buggybread.com
Ans. No. This will give a compilation error saying "Abstract methods do not specify a body".

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

   Like      Discuss      Correct / Improve     java   abstract classes   abstract methods   java compilation error   java coding   java code   coding   yes-no



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. Write program for input: I am a boy, output: I1 am2 a1 boy3?
Admin
info@buggybread.com
Ans. public static void main (String args[]) {
String inputStr = "I am a boy, output: I1 am2 a1 boy3";

String splitStr[] = inputStr.split(" ");

String outputStr = new String();

for(String str1: splitStr){
outputStr += str1 + str1.length() + " ";
}

System.out.println(outputStr);
}

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

   Like      Discuss      Correct / Improve     java   coding


 Q41. What is the difference between out.println(a+b); and out.println (a+" " +b); in Java? with a=2 and b=1Core Java
Admin
info@buggybread.com
Ans. First will give the ouput as 3 and the second will give output as 2 1

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

   Like      Discuss      Correct / Improve     java   system.out.println   coding


 Q42. How many elements will be there in TreeSet after the last line and Why ?

TreeSet set = new TreeSet();
set .add(new String("abc"));
set .add(new String("abc"));
Core Java
Admin
info@buggybread.com
Ans. One.

As we haven't specified the type of TreeSet, it being evaluated with the first element insertion. Once it's identified that it's of type String and as no comparator has been defined, the comparison is done using the String compareTo method. String compareTo method compares the elements by the content / value.

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

   Like      Discuss      Correct / Improve     java   set   treeset   string   compareto   coding   code


 Q43. What will the following code result ?

List> intList = new ArrayList>();

intList.add(Optional.empty());
intList.add(Optional.of(2));
intList.add(Optional.of(3));
intList.add(Optional.of(4));

System.out.println(intList.get(null));
admin
info@buggybread.com
Ans. Compile time error at last line as the get method expect argument of type native int.

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

   Like      Discuss      Correct / Improve     arraylist   list   coding   collections


 Q44. What will the following code result ? Will it compile ?

List> intList = new ArrayList>();

intList.add(Optional.empty());
intList.add(Optional.of(2));
intList.add(Optional.of(3));
intList.add(Optional.of(4));

System.out.println(intList.get((Integer)null));
admin
info@buggybread.com
Ans. Yes but the last line will throw NullPointerException upon execution.

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

   Like      Discuss      Correct / Improve     collections   arraylist   list   coding


 Q45. What will be the output ?Integer a = 10, b =10;Integer c = 10, d = 1000;System.out.println(a == b);System.out.println(c ==d);Core Java
admin
info@buggybread.com
Ans. truefalse

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

   Like      Discuss      Correct / Improve     java   coding   equality   object equality


 Q46. How many bits are used to represent Unicode ?

a. 8 bits
b. 16 bits
c. 24 bits
d. 32 bits
Anonymous
Ans. 16 bits

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

   Like      Discuss      Correct / Improve     java   character coding   character encoding


 Q47. Print natural numbers sequentially with two threads.Core Java

Ans. http://stackoverflow.com/questions/18799591/print-natural-sequence-with-help-of-2-threads1-is-printing-even-and-2nd-is-pri

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

   Like      Discuss      Correct / Improve     print natural numbers with two threads   multithreading   multi threading   threads   code   coding   makemytrip.com


 Q48. Find the repeating number using O(n) time and constant space.Algorithm

Ans. http://www.geeksforgeeks.org/find-duplicates-in-on-time-and-constant-extra-space/

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

   Like      Discuss      Correct / Improve     algorithm   program   code   coding  makemytrip.com


 Q49. Write a method to convert all elements of a set to lower case.Core Java

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+convert+all+elements+of+a+collection&category=code

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

   Like      Discuss      Correct / Improve     code  coding  string  String.toLowerCase  set  collections



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q50. Write code for singleton classDesign

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=singleton+class&category=code

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

   Like      Discuss      Correct / Improve     singleton  code  coding  design pattern     ECI Telecom      Intermediate        frequent


 Q51. Write a program / method to input few numbers and then print the sum.

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=946

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

   Like      Discuss      Correct / Improve     code  coding  scanner      basic


Very frequently asked to fresh graduates.
 Q52. Write a program to Generate prime numbers till a given numberCore Java

 This question was recently asked at 'NSEiT,RT logic,Misys,Accenture'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     generate prime numbers  code  coding     NSEiT  RT logic  Misys  Accenture      basic        frequent


 Q53. Write a program to calculate factorial of a number using recursionCore Java

Ans.

public class Factorial {
   public static void main(String[] args){
      int x = 5;
      
      System.out.println(calculateFactorial(x));
   
   }
   
   private static int calculateFactorial(int x){
      if(x==1){
         return 1;
      }
      return x * calculateFactorial(x-1);
   }
}

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

   Like      Discuss      Correct / Improve     factorial  calculate factorial  code  coding  recursion     Mahindra Comviva      basic


 Q54. Write code for the usage of Builder Design Pattern

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=964

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

   Like      Discuss      Correct / Improve     builder design pattern  builder pattern  code  coding      intermediate


 Q55. Write code for constructor overloadingCore Java

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=965

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

   Like      Discuss      Correct / Improve     constructor overloading  code  coding     Capgemini  Paxcel Technologies      basic


 Q56. Write code to check if an integer is odd or even using ternary operator

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=963

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

   Like      Discuss      Correct / Improve     ternary operator  code  coding


 Q57. Write code to sort elements of a set

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=952

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

   Like      Discuss      Correct / Improve     set  collections  sorting  treeset  code  coding


 Q58. In the following code , how many methods needs to be implemented in Class B ?

public interface A{
   public void method1();
   public void method2();
   public void method3();
}

abstract class B implements A{
}
Core Java

Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract.

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

   Like      Discuss      Correct / Improve     interfaces  abstract classes  code  coding

Try 2 Question(s) Test


 Q59. What will the following code print ?

Integer a = 100, b =100;
Integer c = 1000, d = 1000;
System.out.println(a == b);
System.out.println(c ==d);
Core Java

Ans. false
false

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

   Like      Discuss      Correct / Improve     object equality  code  coding        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q60. What is the problem with following code ?

public static void main(String[] args) {
int x = 5;
return x*2;

int y = 10;
return y*2;

}
2016-07-12 10:33:39

Ans. There are many problems with the code

1. The method returns void and hence we cannot return any integer value.

2. We cannot return more than one value from a method.

3. The code after 1st Return statement is unreachable.

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

   Like      Discuss      Correct / Improve     coding  code


 Q61. Write a Java Program to check Armstrong Number ?Core Java2016-11-24 08:40:05

Ans. http://www.programmingsimplified.com/java/source-code/java-program-armstrong-number

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

   Like      Discuss      Correct / Improve     program  code  coding  armstrong number     IBM


 Q62. How would you count the number of words in a string consisting of uneven number of spaces between words( not dictionary words)? With and without library functions.Core Java2016-11-30 20:46:12

 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  coding     Amazon


 Q63. Implement the following method ?

int findMax(int[] items)
Core Java2016-12-01 16:04:18

Ans. int findMax(int[] items){
   int maxNumber = 0;
   for(int x:items){
      if(x > maxNumber){
         maxNumber = x;
      }
   }
      
   return maxNumber;
}

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

   Like      Discuss      Correct / Improve     coding  code  find max number in an array     Nextlabs


 Q64. Write a Program to print the positive and negative numbers separetlyCore Java2016-12-18 16:53:56

 This question was recently asked at 'Infoview Technologies'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  program  coding     Infoview Technologies


 Q65. Write a program to print all even numbers first and then all odd numbers till 100. For example the output should be
2
4
6
8
...... 100
and then
1
3
5
7
...... 99

using only 1 for loop ? Is it possible with just one loop ?
Core Java2017-01-27 18:20:39

Ans. Yes , It can be done using single for loop

public class BuggyBread{
public static void main (String args[]) {
   int x = 50;
   for(int i=1;i <= 100;i++){
      if(i<=50){
         System.out.println(i*2);
      } else {
         System.out.println(i-x);
         x = x - 1;
      }
   }
}
}

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

   Like      Discuss      Correct / Improve     code  coding     IntelliSwift


 Q66. Given two files with list of words, write a program to show the common words in both filesCore Java2017-01-28 11:31:20

 This question was recently asked at 'Google'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     file handling  file io  code  coding     Google


 Q67. Provide an implementation for Producer / Consumer using threads.Core Java2016-12-23 20:09:26

Ans. https://www.tutorialspoint.com/javaexamples/thread_procon.htm

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

   Like      Discuss      Correct / Improve     coding  code     NIIT


Frequently asked in high end product companies.
 Q68. Write code for LRU CacheCore Java2017-01-10 10:15:17

 This question was recently asked at 'United Health Group (UHG),Google,Zenefits,Amazon,Microsoft,SurveyMonkey,LinkedIn,Sanpdeal,MarkMonitor'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     cache  LRU cache  coding  code     United Health Group (UHG)  Google  Zenefits  Amazon  Microsoft  SurveyMonkey  LinkedIn  Sanpdeal  MarkMonitor      intermediate


 Q69. Trim a string without using String library methodCore Java2017-01-11 15:44:10

 This question was recently asked at 'Ariba'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  coding.string  trim a string     Ariba



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Usually asked to entry level software developers.
  Q70. Write a program to swap two variables without using thirdCore Java2017-01-19 15:38:34

Ans. public static void main(String[] args) {
   int num1 = 1;   
   int num2 = 2;
   num1 = num1^num2;
   num2 = num1^num2;
   num1 = num1^num2;
   System.out.print("num1 = " + num1 +", num2 = "+num2);
}

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

   Like      Discuss      Correct / Improve     code  coding     Deloitte  Colgate Palmolive  Tech Mahindra  SAP  Broadcom  Tata Consultancy (TCS)  Wipro  Gemalto  Time op  Nse Tech  Client Network Services  Monte Carlo  BrainMobi Technologies  Nokia  Minted LLC  Societe Generale  MetricStream  Sapient Global  HighRadius  Mindtree  Robert Bosch  Cypress Semiconductor  Tesco  NTT Data  Tejora Technologies  Saggezza  Elegant Microweb  AMD  Advanced Micro Devices  Tricon Infotech  Odessa Technologies  Aditi  Max Secure Software India  NetSuite  Volante Technologies  Subex Limited  Plintron Global Technology Solutions      basic        frequent


 Q71. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
   public static void main(String[] args){
      System.out.println(BaseInterface.i);
   }
}

What will be the output upon executing main and Why ?
Core Java2017-01-26 13:42:29

Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work.


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

   Like      Discuss      Correct / Improve     interfaces  coding  code  extending interfaces  diamond interfaces     Bank Of America      intermediate


 Q72. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
int i=10;   

public static void main(String[] args){
      System.out.println(new Class().i);
   }
}

What will be the output upon executing main and Why ?
Core Java2017-01-26 13:43:11

Ans. 10

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

   Like      Discuss      Correct / Improve     interfaces  coding  code      intermediate


 Q73. Write a class / program that takes few numbers from the input and then output the average ?Core Java2017-01-27 14:26:00

Ans. public class Class{
   public static void main(String[] args){
      List<Integer> collector = new ArrayList();

      Scanner scanner = new Scanner(System.in);
      int x = scanner.nextInt();
      while(x != 0){
         collector.add(x);
         x = scanner.nextInt();
      }
      System.out.println(collector.stream().collect(Collectors.averagingInt(p->((Integer)p))));
   }
}

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

   Like      Discuss      Correct / Improve     coding  code  collector  streams  Collectors.average     Raytheon


 Q74. Write a program to check is a string is substring of another ?Core Java2017-01-27 14:32:44

Ans. public class Class{
   public static void main(String[] args){
      String string1 = "Hello I am Jack. I live in United States. I live in california state.";

      String string2 = "I live in";

      if(string1.indexOf(string2) >= -1){
         System.out.println("string2 is sub string of string1");
      } else {
         System.out.println("string2 is not sub string of string1");
      }
   }
}

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

   Like      Discuss      Correct / Improve     string  coding  code


 Q75. Write a Program to check number of occurrences of one string within another ? Core Java2017-01-27 14:44:07

Ans. public class Class{
   public static void main(String[] args){
      String string1 = "Hello I am Jack. I live in United States. I live in california state.";

      String string2 = "I live in";

      int startIndex = 0;
      int endIndex = string1.length()-1;

      int countNoOfOccurences = 0;

      String remainingString = string1;

      while(startIndex < endIndex){
         if(remainingString.indexOf(string2) != -1){
            countNoOfOccurences++;
            startIndex = remainingString.indexOf(string2) + string2.length();
            remainingString = remainingString.substring(startIndex);
         } else {
            break;
         }
      }

      System.out.println(countNoOfOccurences);
   }
}

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

   Like      Discuss      Correct / Improve     string  code  coding     Google  Zoho


 Q76. Write a Program to check if string is a Colidrome ?
(Colidrome is a word that has n alphabets followed by the reverse of the n alphabets, for ex - mallom)
Core Java2017-01-27 14:53:14

Ans.
public class Class {
   public static void main(String[] args) {
      String str = "mallam";
      String firstHalf = str.substring(0, str.length() / 2);
      String secondHalf = str.substring(str.length() / 2);

      if (firstHalf.equals(new StringBuilder(secondHalf).reverse().toString())) {
         System.out.println("It's a Colidrome");
      } else {
         System.out.println("It's not a Colidrome");
      }
   }
}

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

   Like      Discuss      Correct / Improve     Colidrome  String  Code  Coding     Maventic


 Q77. Write a program in Java that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buz. For numbers which are multiples of both three and five print FizzBuzzCore Java2017-01-27 14:59:04

Ans. public class Class{
public static void main(String[] args){
for(int i=1;i<= 100;i++){
if(i%3 == 0){
if(i%5 == 0){
System.out.println("FizzBuzz");
}
System.out.println("Fizz");
} else if(i%5 == 0){
System.out.println("Buzz");
} else {
System.out.println(i);
}

}
}
}

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

   Like      Discuss      Correct / Improve     code  coding     Motorola Mobility  Lenovo


 Q78. Write a Program to print count of each character in a String.Core Java2017-01-27 20:32:20

Ans. public class BuggyBread {
public static void main(String args[]) {
Map<Character, Integer> countMap = new HashMap();
String str = "hello world";
for (char character : str.toCharArray()) {
if (countMap.containsKey(character)) {
countMap.put(character, countMap.get(character) + 1);
} else {
countMap.put(character, 1);
}
}
System.out.println(countMap);
}
}

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

   Like      Discuss      Correct / Improve     String  Code  Coding  Character     Compro Technologies


 Q79. Write a Program to only print characters that have occured more than once in a StringCore Java2017-01-27 20:37:26

Ans. public class BuggyBread{
public static void main (String args[]) {
Set<Character> set = new HashSet();
Set<Character> setWithDuplicateChar = new HashSet();
String str = "hello world";
for(char character: str.toCharArray()){
if(set.contains(character)){
setWithDuplicateChar.add(character);
} else {
set.add(character);
}
}

System.out.println(setWithDuplicateChar);
}
}

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

   Like      Discuss      Correct / Improve     String  Code  Coding



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q80. Write a program for 0 and cross games? Core Java2017-03-27 08:48:50

 This question was recently asked at 'Compro Technologies'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code.coding.0 and cross game     Compro Technologies


 Q81. Write code to find second largest number in an array of integers.Core Java2017-07-10 14:31:32

 This question was recently asked at 'HCL Technologies'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  coding  find in array     HCL Technologies


 Q82. Write a Program to find common words in 2 separate stringsCore Java2017-01-29 17:29:52

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


 Q83. Write a program to print count / no of common words in 2 separate stringsCore Java2017-01-29 17:31:39

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


 Q84. Write a Program to remove duplicate words from the StringCore Java2017-01-29 17:36:31

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     Microsoft      basic


 Q85. Write a Program to display the words of a String in alpahbetical or Dictionary OrderCore Java2017-01-29 17:38:02

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


 Q86. Write a Program to display numbers between 2 numbers using recursionCore Java2017-01-29 18:08:13

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


 Q87. 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 Java2017-01-29 18:12:47

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


 Q88. Write a Program to print pattern like following

*
**
***
****
*****
******
*******
********
*********
**********
Core Java2017-01-29 18:15:23

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


 Q89. Write a Program to validate an email addressCore Java2017-01-30 11:12:30

Ans. public class Class{
public static void main(String[] args){
String str = "xyz@123.com";

if(!str.contains("@") && !str.contains(".") && (str.indexOf('.') < str.indexOf('@'))){
System.out.println("Not a Valid Email Address");
}
}
}

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

   Like      Discuss      Correct / Improve     validate an email address  coding  code     Webyog



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q90. Write a Program to validate if a particular character occurs after another in a stringCore Java2017-01-30 11:13:29

Ans. public class Class{
   public static void main(String[] args){
      String str = "xyz123.co@m";
      
      if(str.indexOf('.') < str.indexOf('@')){
         System.out.println("Not a Valid Email Address");
      }
   }
}

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

   Like      Discuss      Correct / Improve     string  string.indexOf  coding  code


 Q91. How to find the median number in an array of integers ?Core Java2017-02-02 18:04:41

Ans.

Arrays.sort(numArray);
double median;
if (numArray.length % 2 == 0)
   median = ((double)numArray[numArray.length/2] (double)numArray[numArray.length/2 - 1])/2;
else
   median = (double) numArray[numArray.length-1/2];

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

   Like      Discuss      Correct / Improve     coding     Delphix  Mastercard


 Q92. Write a Java program to print 10 random numbers between 1 to 100?Core Java2017-02-03 08:26:09

 This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     coding  code


 Q93. Write a method / program that will determine if the parenthesis are balanced in a given string.Core Java2017-02-03 13:13:55

 This question was recently asked at 'Jetbro,Booking.com,Cloudera,UrjaNet,Wissen Infotech,ThoughtWorks,Capital One,Experian,Remaxys,MongoDB,One.com,Lime Brokerage,Netcracker Technology,Ooyala'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     string  code  coding     Jetbro  Booking.com  Cloudera  UrjaNet  Wissen Infotech  ThoughtWorks  Capital One  Experian  Remaxys  MongoDB  One.com  Lime Brokerage  Netcracker Technology  Ooyala


 Q94. Given array of integers, find first two numbers that adds up to 10.Core Java2017-03-03 14:27:38

 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     Code  Coding     Amazon


 Q95. Write a program to reverse words of a sentence.Core Java2017-03-03 14:30:14

 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  Coding     Amazon


 Q96. Implement stack using generics in Java.Data Structure2017-04-18 09:23:44

 This question was recently asked at 'Bind Software Innovations'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     oding  cod     Bind Software Innovations


 Q97. How can you extract integers from string values and add (sum it up) all the extracted integers? e.g "James34long4island322in3rdAvenue" ---> 34 4 322 3 = 363Core Java2017-05-01 09:30:15

 This question was recently asked at 'Horizon Solutions'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     coding  code     Horizon Solutions


 Q98. Write a Program to convert a binary to number ?Core Java2017-05-04 15:11:08

 This question was recently asked at 'Trustwave'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  coding     Trustwave      basic


 Q99. Given a string with multiple opening and closing brackets, determine if the string is valid or not ( to see if the string has all closing brackets for each opening bracket ) ?Core Java2017-05-07 20:10:10

 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  coding     Amazon



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q100. Write a method, that compare two numbers and return the bigger one ?Core Java2017-06-11 12:36:13

 This question was recently asked at 'NetStar Inc'.This question is still unanswered. Can you please provide an answer.


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

   Like      Discuss      Correct / Improve     code  program  coding     NetStar Inc      basic


next 100


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

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:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: