Java - Interview Questions and Answers for 'Character' | 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 'Character' - 13 question(s) found - Order By Newest

 Q1. What is a stream and what are the types of Streams and classes of the Streams?Core Java
Admin
info@buggybread.com
Ans. A Stream is an abstraction that either produces or consumes information. There are two types of Streams :

Byte Streams: Provide a convenient means for handling input and output of bytes.

Character Streams: Provide a convenient means for handling input & output of characters.

Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream.

Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.

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

   Like      Discuss      Correct / Improve     java   file io   streams   byte stream   character stream


 Q2. 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


 Q3. 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


 Q4. 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


 Q5. What will be the output of following code ?

System.out.println((int)'a');

Ans. The ascii value of a i.e 97

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

   Like      Discuss      Correct / Improve     character  ascii


 Q6. What will be the output of

System.out.println((Integer)'a');

Ans. It will result in compilation error as primitive char cannot be casted to Integer object, alternatively we can cast it to primitive int like following

System.out.println((int)'a');

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

   Like      Discuss      Correct / Improve     character  ascii


 Q7. 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


 Q8. How can we check if a particular character is upper case in Java ?Core Java2017-07-29 09:58:48

Ans. 1. We can compare the ascii value of the character. Ascii for Capital case character is from 65 to 90.

2. We can compare to see if lowerCase of the character is not equal to character itself.

For example -

if character is 'a' the following code

new StringBuilder(char).toString().toLowerCase().equals(new StringBuilder(char)

will return true and hence char is lower case

if character is 'A' the following code

new StringBuilder(char).toString().toLowerCase().equals(new StringBuilder(char)

will return false and hence char is upper case

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

   Like      Discuss      Correct / Improve     check upper case character  character


 Q9. What are ascii values for capital and lower case alphabets ?Core Java2017-07-29 10:00:25

Ans. 65 to 90 for capital case alphabets

97 to 122 for lower case alphabets

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

   Like      Discuss      Correct / Improve     ascii  character  char



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. How can we convert a character or a character array into a String ?Core Java2017-07-30 15:57:10

Ans. String has an argument constructor that take char array as argument and creates a string.

There is no constructor available with String that takes in a character and creates a String. We can use StringBuilder which has a char argument constructor.

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

   Like      Discuss      Correct / Improve     character  char  char array  String  char to String  char array to String


 Q11. Write a Program to print ascii value of each character of a string

Ans. public static void main(String[] args) {
String str = "We are not in Kansas anymore";
for(char character: str.toCharArray()){
System.out.println((int)character);
}
}

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

   Like      Discuss      Correct / Improve     ascii  character


 Q12. Write a Program to replace characters in a String ( without using String replace method )2017-07-30 15:53:58

Ans. public class ReplaceCharacters{
   public static void main(String[] args){
      String str = "Hello BuggyBread";
      
      char[] charArray = str.toCharArray();
      int countCharacter = str.length();
      for(int count=0;count<countCharacter;count++){
         if(charArray[count] == 'g'){
            charArray[count] = 'd';
         }
      }
      String replacedString = new String(charArray).toString();
      
      System.out.println(replacedString);
   }
}

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

   Like      Discuss      Correct / Improve     string  replace characters in a string


 Q13. Write a Program to right shift single character in a string2017-08-24 20:12:56

Ans. public class RightShiftCharacter {
   public static void main(String args[]) {
      String str = "Hello";
      
      char[] charArray = str.toCharArray();
      
      for(int count=charArray.length-1;count>0;count--){
         charArray[count] = charArray[count-1];
      }
      
      String newString = new StringBuilder().append(charArray).toString();
      
      System.out.println(newString);      
   }
}

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

   Like      Discuss      Correct / Improve     string manipulation.right shift character




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: