Java-Interview-Questions-&-Answers by BestOnlineTrainers (1) - PowerPoint PPT Presentation

About This Presentation
Title:

Java-Interview-Questions-&-Answers by BestOnlineTrainers (1)

Description:

Crack your Java interview by knowing all the questions that your interviewer may ask. Brush up your knowledge with this superb set of Java interview questions & answers prepared by BestOnlineTrainers – PowerPoint PPT presentation

Number of Views:2031

less

Transcript and Presenter's Notes

Title: Java-Interview-Questions-&-Answers by BestOnlineTrainers (1)


1
Java Interview Q A
  • By www.bestonlinetrainers.com

2
Q21 How are strings compared Using or
equals ()?
  • Answer
  • tests if references are equal and equals ()
    tests if values are equal. To check if two
    strings are the same object, equals() is always
    used.

Learn Java. Ask for a free demo
www.bestonlinetrainers.com
3
Q22 Char is preferred over String for security
sensitive information. Why?
  • Answer
  • Strings are immutable, that is once they are
    created, and they stay unchanged until Garbage
    Collector kicks in. Its elements can be
    explicitly changed with an array. Hence, security
    sensitive information like password will not be
    present anywhere in the system.

Learn Java. Ask for a free demo
www.bestonlinetrainers.com
4
Q23WCan string be used to switch statement?
  • Answer
  • String can be used to switch statement to
    version 7. From JDK 7, string can be used as
    switch condition. Before version 6, string cannot
    be used as switch condition .
  • view source
  • print?
  • 01.// java 7 only!
  • 02.switch (str.toLowerCase())
  • 03.case "a"
  • 04.value 1
  • 05.break
  • 06.case "b"
  • 07.value 2
  • 08.break
  • 09.

5
Q24Can string be converted to int?
  • Answer
  • If the HashCode() is not overridded , the
    object will not be recovered from the HashMap if
    used as key.
  • Yes .It can be .But its frequently used and
    ignored at times.
  • view source
  • print?
  • 1.int n Integer.parseInt("10")

6
Q25 How can a string be split with white space
characters?
  • Answer
  • String can be slit using regular expression.
    White space characters are represented as \s.
  • view source
  • print?
  • 1 .String strArray aString.split("\\s")

7
Q26 What does substring() method do ?
  • Answer
  • The existing String is represented by the
    substring() method which gives a window to an
    array of chars as in JDK 6.A new one is not
    created. An empty string needs to be added to
    create a new one.
  • print
  • ?
  • 1.str.substring(m,n) ""
  • This creates a new char array representing a new
    string. This method can help to code faster
    because the Garbage Collector collects the unused
    large string and the keeps the substring.

8
Q27 What is String vs StringBuilder vs
StringBuffer ?
  • Answer
  • In String vs StringBuilder, StringBuilder
    is mutable, that is it means it can be modified
    after its creation. In StringBuilder vs
    StringBuffer, StringBuffer is synchronized, that
    is it means it is thread-safe but would be slower
    than StringBuilder.

9
Q28 How is a string repeated ?
  • Answer
  • In Python, to repeat a string just multiple
    a number. In Java, the repeat() method of
    StringUtils from Apache Commons Lang package can
    be used.

10
Q29 In Java, what is the default value of byte
datatype?
  • Answer
  • 0 is the default value of byte datatype.

11
Q30 In a string how to count of occurrences of
a character?
  • Answer
  • StringUtils from apache commons lang can be
    used.
  • view source
  • print?
  • 1.int n StringUtils.countMatches("11112222",
    "1")
  • 2.System.out.println(n)

12
Want to learn Java?
  • Visit http//www.bestonlinetrainers.com/programm
    ing/java-training.html
  • Email info_at_bestonlinetrainers.com
  • Phone USA (1) 6783896789
  • UK (44)- 2032393637
  • India (91) 9246449191
  • Ask for a free demo TODAY http//www.bestonline
    trainers.com/demo/index.html
Write a Comment
User Comments (0)
About PowerShow.com