Answer on Question#48923 - Programming – Java
Q1) What are the keywords that java supports? Describe the data types available in java programming language.
Answer:
Keywords:
abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictly, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while.
The keywords goto and const are reserved but aren't used.
Java supports two data types:
- primitive data types
- object(reference) data types
There are 8 primitive data types that can be divided in 4 groups:
- Integers:
byte (is a smallest 8-bit integer data type with the minimum value of – 127 and with the maximum value of 128)
short (is a 16-bit integer data type (from –32,768 to 32,767))
int (is a 32-bit integer data type (from –2,147,483,648 to 2,147,483,647))
long (is a 64-bit integer data type (from –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807))- Real Numbers:
float (is a 32-bit single-precision real number data type with a floating point)
double (is a 64-bit double-precision real number data type with a floating point)- Characters:
char (is a 16-bit Unicode character data type (from 0 to 65536))- Booleans:
boolean (this type represents one bit of information and it stores only two values: true or false)Object data types are used for creating of reference variables via constructors of the classes. These variables cannot be changed (they're used to access objects).
Q2) Describe StringBuffer class in java. List all the functions relevant to it and explain any five of them.
Answer:
Unlike String, class StringBuffer represents the character sequence that can be changed. It is the ability to insert characters and substrings in the middle or at the end of the StringBuffer object.
Functions (methods):
length (), capacity (), ensureCapacity (), setLength (), charAt (), setCharAt (), getChars (), append (), insert (), reverse (), delete (), deleteCharAt (), replace (), substring (), appendCodePoint (), codePointAt (), codePointBefore (), codePointCount (), indexOf (), lastIndexOf (), offsetByCodePoints (), subsequence (), trimeToSize ().
Method length () returns the current length (int) of the object:
int length ().
Method capacity () returns the current amount (int) of allocated memory:
int capacity ().
Method append () combines string representation of any other type to the end of the calling object and returns its:
StringBuffer append (Object/primitive type).
Method reverse () returns a StringBuffer object with the reverse sequence of characters relative to the caller:
StringBuffer reverse ().
Method delete () removes characters from StringBuffer:
StringBuffer delete (int a, int b), where a is the initial index, b is the finite index.http://www.AssignmentExpert.com/
Comments