You are on page 1of 3

JAVA NOTES (COMPLETE REF & https://www.javatpoint.

com/java-tutorial)

1) About bytecode and JVM


https://www.geeksforgeeks.org/jvm-works-jvm-architecture/
https://www.youtube.com/watch?v=deXGenXXoaI
Get snapshots from notebook

2) JDK VS JRE VS JVM

3) WHY JAVA / Features of JAVA? (In Complete Ref P-2, Java Buzz words & https://www.javatpoint.com/features-of-java)

a) OPPS – give all oops concepts available in java


b) Secure –
i) No explicit pointer
ii) Java Programs run inside a virtual machine sandbox

c) Platform independent / Portable


d) Robust
i) Mem. management & exceptional handling
e) High performance -
i) Use of JIT to optimize the interpreting process.

4) C++ vs JAVA

5) Running JAVA PROGRAMMS (Practical)

6) JAVA OOPS (See OOPS File)


a) Encapsulation –
i) Class
ii) (A Part) Data hiding – using access specifiers
https://stackoverflow.com/questions/28612420/what-is-encapsulation-
exactly/28614407
b) Abstraction
i) Interface
ii) Abstract classes
c) Inheritance
d) Polymorphism
i) Method overloading
ii) Method overriding
7) NOTES FROM P 11 to P 33 are not made now (Except type conversion). MAKE THEM WHEN
YOU FIND TIME.

8) NULL

9) Type Casting / conversion


a) Implicit / Widening–
i) (when) Types are compatible.
(1) Compatible types -
(a) Both (destination/LHS & source/RHS) can be represented in numerical format
(integer or floating-point value) - apart from Boolean, every type is compatible
with other type because Boolean can’t be represented in a number format. So
int, byte, short, long, float, double, & char (char is compatible because it can be
represented in number form and all other types are numeric so all of them are
compatible with each other) are compatible with each other.
AND
(b) The destination type is larger than source type in terms of magnitude/range i.e.
there is not loss of magnitude – short or byte can’t be converted to char
implicitly because negative values can’t be represented in char (but this can be
done through explicit cast). Long can be converted to float because the range
(magnitude) of long fits into range of float or double. So, there may be loss of
precision (less bits) but there is no loss of magnitude.
ii) (from java docs) Which conversions can be performed implicitly in java -

Or
byte short Int float double
char

b) Explicit / narrowing -
i) (when) Types are incompatible due to destination type being smaller than source type.
ii) (how) in two ways the actual explicit conversion operation can take place -
(1) Modulo - If the integer’s value is larger than the range of a byte, it will be reduced
modulo (the remainder of an integer division by the) byte’s range. This is mostly
performed.
(2) Truncation – when a floating-point value is assigned to an integer (including char)
type.
(3) (NOTE) even after truncation, if the size of the whole number component is too
large to fit into the target integer type, then that value will be reduced modulo the
target type’s range. For example, consider –
byte b;
double d = 323.142;
System.out.println("\nConversion of double to byte.");
b = (byte) d;
System.out.println("d and b " + d + " " + b);
When d is converted to a byte, its fractional component is lost, and the value is
reduced modulo 256, which in this case is 67.
iii) (NOTE) If types are incompatible because they can’t be represented in numerical format,
then they can’t be converted in any way –
boolean a = true;
int b = (int) a; //error
boolean can’t be converted to int even though int (destination) is larger than boolean
(source) because boolean has a true or false value which, in java, is not represented in
numerical form. They are literals.

10) Automatic Type promotion in Expressions


a) (what) consider the below code -
byte a = 40;
byte b = 50;
byte c = 100;
int d = a * b / c;
The result of the intermediate term a * b easily exceeds the range of either of its byte
operands. To handle this kind of problem, Java automatically promotes each byte, short, or
char operand to int when evaluating an expression

b) Rules -
i) all byte, short, and char values are promoted to int (whether int is present in expression
or not).
ii) if one operand is a long, the whole expression is promoted to long.
iii) If one operand is a float, the entire expression is promoted to float.
iv) If any of the operands is double, the entire expression is promoted to double.

c) (NOTE) As useful as the automatic promotions are, they can cause confusing compile-time
errors. For example, this seemingly correct code causes a problem:
byte b = 50;
byte a = 2
b = b * a; // Error! Cannot assign an int to a byte!
The code is attempting to store 50 * 2, a perfectly valid byte value, back into a byte variable.
However, because the operands were automatically promoted to int (even though no int
alue was present) when the expression was evaluated, the result has also been promoted to
int. Thus, the result of the expression is now of type int, which cannot be assigned to a byte
without the use of a cast.

You might also like