Posts

Showing posts from February, 2018

1.7 v Enhancements with respect to literals

Image
1.7 v Enhancements with respect to literals 1) Binary Literals :- For integral data types untill 1.6 v we can specify literal in the following ways. *Decimal *Octal *Hexa Decimal But from 1.7 v onwards we can specify literal value even in binary form also. Allowed digits are 0 & 1 Literal value should be prefixed with 0b or 0B. ex: int x = 0b111; or int x = 0B1111; 2) Usage of underscore symbol in numeric letter. From 1.7 v onwards we can use underscore symbols between digits of numeric literal. ex: double d = 1_23_456.7_8_9; The main advantage of this approach is to improve the readability of code. At the time of compilation these underscoe symbols will be removed automatically. 3) We can use more than 1 underscore symbols also between the digits. ex: double d = 1___3_4_56.78_9; valid 4)   We can use underscore symbols only between the digits. If we are using anywhere else, we will get compile time error. ex: double d = _1_2_3.4_5...

Boolean & Char Literals

Image
Boolean Literal Only allowed values for boolean data type are true/false. boolean b = true; boolean b = 0; CE: incompabitle type found int required boolean boolean b = True; CE: cannor find symbol variable true boolean b = "True";CE: incompabitle type found string required boolean Char Literal *We can specify char literal as single character within single quotes. char ch = 'a'; char ch = a;  CE: cannot find symbol . variable a in class Test. char ch = "a"; CE: incompatible type found string required char. char ch = 'ab'; CE1: unclosed char literal. CE2: unclosed char literal. CE3: not a java statement. * We can specify char literal as integral literal which represents UNICODE value of character & that integral literal can be specified either in decimal , octal or hexa-decimal forms but allowed range is  0 to 65535. char ch = 97; char ch = 'a'; char ch = 0xface; char ch = 0777; char ch = 6...

Floating Point Literals

Image
By default every floating point literal is of double type and hence we can't assign directly to the float variable. but we can specify floating point literal as float type by suffixed with f or F. eg:         float f = 123.456; CE: possible loss of precision fount double required float. double d = 123.456; float f = 123.456f; We can specify floating point literal as double type by suffixed with d or D. Ofcourse this convention is not required. double d = 123.456D;   valid float f = 123.456D;       CE: possible loss of precision fount double required float. double d = 123.456; valid double d = 0123.456; valid double d = 0x123.456; invalid   CE: malformed floating point literal. *We can specify floting point literals only in decimal form and we can't specify in octal & hexadecimal forms. INTERVIEW FAQ: double d = 0786; invalid double d = 0xFace; valid We can assign inte...

Literals

Image
A constant value which can be assigned to a variable is called Literal. eg: int x = 10; int - data type x - variable name   10 - constant value/ literal Integral Literals : For integral data types (byte, short, int, long) we can specify literal value in the following ways- 1) Decimal Literals (base 10) Allowed digits : 0 to 9 ex: int x = 10; 2) Octal Literals (base 8) Allowed digits : 0 to 7 Literal value should be prefixed with 0. eg: int x = 010; 3) Hexa-Decimal form (base 16) Allowed digit : 0 - 9 ,  a - f or A - F  (for extra digits a to f we can use both lower or upper case characters. This is one of very few areas where JAVA is not case sensitive). Literal value should be prefixed with 0x or 0X. eg : int x = 0x10; or int x = 0X10; These are only possible ways to specify literal value for integral data types. INTERVIEW FAQS. int x = 10;  valid int x = 07789; invalid   CE: integer number too large....

Data Types

Image
Why Java is strongly typed programming language ?  In java every variable and every expression has some type. Each and every data type is clearly defined. Every assignment should be checked by compiler for type compatibility. Because of above reasons we can concluded that java language is strongly typed programming language. Java is pure Object Oriented programming language or not ? Java is not considered as pure OOP language because several OOP feature are not satisfied by Java like operator overloading, multiple inheritence etc. Moreover we are depending on primitive data types, which are non objects. Primitive data types: 8   Numeric data types Integral data types    * byte, short, int, long 2. Floating point data types * float, double  Non Numeric data types              * char, boolean Except boolean and char remaining data types are considered as...

Identifiers

Image
Identifier : A name in java program is called identifier which can be used for identification purpose. It can be method name, variable name, class name or level name. Ex: class Test{ public static void main(String [] args){ int x = 10; } } Total identifiers   : Test, main, String (pre-defined java class), args, x --> 5 identifiers Rules for defining java identifers:  1) Only allowed symbols are  a to z, A to Z, 0 to 9, $, _ ex: total_number  -->  valid total# --> invalid if we use any other character we will get compile time error. 2) Identifier should not start with digit. ex:  123total --> invalid total123 --> valid 3) Java identifiers are case-sensitive.   Java language itself is case sensitive programming language. ex: int number; int Number; int NUMBER; * all are valid 4) There is no length limit for identifier but not recommended to take too lengthy identifier. 5) We ca...