You should be able to identify how many objects are on the heap after a code statement
or block executes.
Thread[] threads = new Thread[10];
When the above code is executed , there will only be one object in the heap. That is a single array object that holds ten thread references. The thread objects are neither created or assigned to these reference variables.
Language Fundamentals - Arrays
An article on arrays in Java.
Tip 39
Characters are 16-bit unsigned integers.You can assign a number literal, assuming it will fit into the unsigned 16-bit range.
These are legal
char ex1 = 0x892;
char ex2 = 982;
char ex3 = (char) 70000;
char ex4 = (char) -98;
char ex5 = '\"';
char ex6 = '\n';
char ex7 = '\u004E';
char ex8 = 'a';
char ex9 = '@';
And the following are illegal
char ex1 = -29; // needs a cast
char ex2 = 70000 // needs a cast
These are legal
char ex1 = 0x892;
char ex2 = 982;
char ex3 = (char) 70000;
char ex4 = (char) -98;
char ex5 = '\"';
char ex6 = '\n';
char ex7 = '\u004E';
char ex8 = 'a';
char ex9 = '@';
And the following are illegal
char ex1 = -29; // needs a cast
char ex2 = 70000 // needs a cast
Tip 38
Local variables should be initialized. Otherwise the compiler will complain. Instance variables on the other hand will be initialized to the default values of their variable types automatically.
Tip 37
Array elements are always initialized with default values, regardless of where they are declared.
Storing Information with Java Arrays
A free tutorial on Java arrays.
Storing Information with Java Arrays
A free tutorial on Java arrays.
Tip 33
Interfaces are by default public and abstract. So are the methods in them. The variables in interfaces are by default public static and final.
Tip 32
| Modifier | Class | Variable | Method | Constructor | Free-Floating Block |
| public | yes | yes | yes | yes | no |
| protected | no | yes | yes | yes | no |
| default | yes | yes | yes | yes | yes |
| private | no | yes | yes | yes | no |
| final | yes | yes | yes | no | no |
| abstract | yes | no | yes | no | no |
| static | no | yes | yes | no | yes |
| native | no | no | yes | no | no |
| transient | no | yes | no | no | no |
| volatile | no | yes | no | no | no |
| synchronized | no | no | yes | no | yes |
| strictfp | yes | no | yes | no | no |
For further information refer the following
Java Modifier Summary
A good summarized explanation on Java Modifiers.
Tip 31
You cannot change the value of a transient variable.
For further information on transient variables refer the following
Declaring a Transient Variable
A brief explanation on how to use transient variables.
For further information on transient variables refer the following
Declaring a Transient Variable
A brief explanation on how to use transient variables.
Tip 29
Static method member variables are not allowed.
class inte {
public static void main(String[] args) {
static int b=3; <---------- Compiler Error
}
}
class inte {
public static void main(String[] args) {
static int b=3; <---------- Compiler Error
}
}
Tip 28
The abstract key word cannot be used with the following in methods
- final
- static
- private
- strictfp
- syncronized
The abstract key word cannot be used with the following in classes
- final
- final
- static
- private
- strictfp
- syncronized
The abstract key word cannot be used with the following in classes
- final
Tip 27
Tip 21
Member variables in a class are implicitly initialized to its default values. Method local variables are not.
Tip 19
Division by 0 results in an arithmetic exception for integers
Division by 0 results in negative or positive infinity values for floating point numbers.
Division by 0 results in negative or positive infinity values for floating point numbers.
Tip 18
Precedence levels of arithmetic operators
* Multiplication
% Modulous
/ Division
+ Addition
- Substraction
All the arithmetic operators ( + , - , *, %, /) are subjected to arithmetic promotions.
For further information on operators refer the following
Operators and Assignments
This article gives a detailed explanation on operators.
* Multiplication
% Modulous
/ Division
+ Addition
- Substraction
All the arithmetic operators ( + , - , *, %, /) are subjected to arithmetic promotions.
For further information on operators refer the following
Operators and Assignments
This article gives a detailed explanation on operators.
Tip 17
Arithmetic promotions on unary operators
+ -----------> Arithmetic promotions apply
- -----------> Arithmetic promotions apply
++ -----------> Arithmetic promotions don't apply
-- -----------> Arithmetic promotions don't apply
~ -----------> Arithmetic promotions apply
! -----------> Arithmetic promotions don't apply
+ -----------> Arithmetic promotions apply
- -----------> Arithmetic promotions apply
++ -----------> Arithmetic promotions don't apply
-- -----------> Arithmetic promotions don't apply
~ -----------> Arithmetic promotions apply
! -----------> Arithmetic promotions don't apply
Tip 16
Operator precedence levels are as follows
For further information on operators refer the following
Operators and Assignments
This article gives a detailed explanation on operators.
Unary | ++ -- + - ! ~ () |
| Arithmetic | * / % + - |
| Shift | << >> >>> |
| Comparison | == != |
| Bitwise | & ^ | |
| Short-circuit | && || |
| Ternary | ?: |
| Assignment | = "op=" |
For further information on operators refer the following
Operators and Assignments
This article gives a detailed explanation on operators.
Tip 15
Many operations are subjected to arithmetic promotions.
byte + byte -------> int
byte + short ------> int
short + short ------> int
char+ char --------> int
int + int -----------> int
int + long ---------> long
long + float -------> float
float + double-----> double
double + byte -----> double
Tip 14
It is not legal to give the array size of an array during declaration.
Eg: int arr [9]; // Illegal
The JVM does not allocate space to the array till you initialize it.
The follwing articles provide further information.
Java Arrays
A good introduction on arrays.
Eg: int arr [9]; // Illegal
The JVM does not allocate space to the array till you initialize it.
The follwing articles provide further information.
Java Arrays
A good introduction on arrays.
Tip 13
Some questions may have numbers where booleans are required. This type of code generates compiler errors.
For eg:
int x = 1;
if (x)
{
System.out.println("YES");
}
For eg:
int x = 1;
if (x)
{
System.out.println("YES");
}
Tip 11
All integers are implicitly int literals.
e.g: byte num = 10; <-- int literal within the range of byte
All floating point numbers are implicitly double literals.
e.g float num = 15.9 <-- Compiler Error : Possible loss of precision
float num = 15.9f <-- Compiles
e.g: byte num = 10; <-- int literal within the range of byte
All floating point numbers are implicitly double literals.
e.g float num = 15.9 <-- Compiler Error : Possible loss of precision
float num = 15.9f <-- Compiles
Tip 10
Octal and Hexadecimal literals are not case sensitive. An octal number can have upto 21 digits (excluding the leading 0) and a hexadecimal number can have upto 16 digits(excluding the leading 0x).
For eg: int num = 0x5 and int num = 0X5 are both legal
For eg: int num = 0x5 and int num = 0X5 are both legal
Tip 9
Integer numbers can be represented in 3 ways.
The following articles provide further information.
A Practical Guide to Binary, Decimal and Hexadecimal Numbers
A brief explanation on the Binary, Decimal and Hexadecimal numbering systems.
Number System
A good explanation on number systems with examples.
Octal Number System
A good article on octal number systems.
A Brief Explanation of Hexadecimal Numbers
A nice tutorial on hexadecimal numbers.
Hexadecimal Number System
A comprehensive explanation on hexadecimal numbers.
- decimal ( 10 base)
- octal ( 8 base)
- hexadecimal (16 base)
The following articles provide further information.
A Practical Guide to Binary, Decimal and Hexadecimal Numbers
A brief explanation on the Binary, Decimal and Hexadecimal numbering systems.
Number System
A good explanation on number systems with examples.
Octal Number System
A good article on octal number systems.
A Brief Explanation of Hexadecimal Numbers
A nice tutorial on hexadecimal numbers.
Hexadecimal Number System
A comprehensive explanation on hexadecimal numbers.
Tip 8
Char is an integral data type. It can be assigned to any number type which is large enough to hold 65535 (216-1)
The following articles provide further information.
Primitive Data Types
This article provides a comprehensive explanation about the primitive data types in Java.
The following articles provide further information.
Primitive Data Types
This article provides a comprehensive explanation about the primitive data types in Java.
Tip 7
All number types in Java are signed and have the following ranges.
byte 8 Bits (-27 to 27-1)
short 16 Bits (-215 to 215-1)
int 32 Bits (-231 to 231-1)
long 64 Bits (-263 to 263-1)
float 32 Bits
double 64 Bits
The following articles provide further information.
Primitive Data Types
This article provides a comprehensive explanation about the primitive data types in Java.
byte 8 Bits (-27 to 27-1)
short 16 Bits (-215 to 215-1)
int 32 Bits (-231 to 231-1)
long 64 Bits (-263 to 263-1)
float 32 Bits
double 64 Bits
The following articles provide further information.
Primitive Data Types
This article provides a comprehensive explanation about the primitive data types in Java.
Tip 6
Words similar to the actual keyword with minor differences will be given.
For eg: extend in place of extends
For eg: extend in place of extends
Tip 5
Null , False and True are actually Literals not keywords. But you cannot create identifiers with these words either.
You will not be asked to differentiate between keywords and reserved literals (true, false, null).
You will not be asked to differentiate between keywords and reserved literals (true, false, null).
Tip 4
There can be questions that use a keyword as the name of a method or variable.
For eg: Questions asking about logic problems in a piece of code, but the real problem will be that the code won't even compile because of the illegal use of the keyword.
For eg: Questions asking about logic problems in a piece of code, but the real problem will be that the code won't even compile because of the illegal use of the keyword.
Tip 3
This is an easy way to remember the 52 Keywords.
Reserved - const , goto (2)
Error Handling - try, catch, finally, throw, throws, assert (6)
Modifiers - private, public, protected, final, static, abstract, native, synchronized,
transcient , scritfp, volatile ( 11)
Constructs - if, else, while , for , do, return, switch, case, default, continue, break (11)
Other - class, package, implements, extends, import, interface, super, this, new, instanceof (10)
Literals - true, false, null (3)
Data & return types - int, short, byte, char, long, boolean, double, float, void (9)
The following articles provide further information
Java Language Keywords
This article lists all the Java keywords available.
PDF File - Java Language Keywords
This pdf file gives a comprehensive explanation about all the keywords including code examples.
Reserved - const , goto (2)
Error Handling - try, catch, finally, throw, throws, assert (6)
Modifiers - private, public, protected, final, static, abstract, native, synchronized,
transcient , scritfp, volatile ( 11)
Constructs - if, else, while , for , do, return, switch, case, default, continue, break (11)
Other - class, package, implements, extends, import, interface, super, this, new, instanceof (10)
Literals - true, false, null (3)
Data & return types - int, short, byte, char, long, boolean, double, float, void (9)
The following articles provide further information
Java Language Keywords
This article lists all the Java keywords available.
PDF File - Java Language Keywords
This pdf file gives a comprehensive explanation about all the keywords including code examples.
Subscribe to:
Posts (Atom)