-
Notifications
You must be signed in to change notification settings - Fork 1
Exception vs Error
public class
Throwableimplements Serializable
- public class
Exceptionextends Throwable - Can be handle by the program - public class Error extends Throwable - Can't be handle by the program
checked Exception are checked at compile time.
The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions
Checked exceptions need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.
public class IOException extends Exception
un-checked Exception are checked at run time
RuntimeException and its subclasses are unchecked exceptions.
Unchecked exceptions do not need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.
« Passed at runtime
public class RuntimeException extends Exception
==============================================================================
com.sun.org.apache.bcel.internal.classfile.ClassFormatException
ClassFormatException extends RuntimeException
==============================================================================
java.io
FileNotFoundException extends IOException
EOFException extends IOException
==============================================================================
java.lang
String passed null and accession methods:
NullPointerException extends RuntimeException
UnModifiable Map:
UnsupportedOperationException extends RuntimeException
ConcurrentModificationException
Accessing array with index greter than of its size:
ArrayIndexOutOfBoundsException extends (IndexOutOfBoundsException extends RuntimeException)
StringIndexOutOfBoundsException
ArrayStoreException extends RuntimeException
Buffer get filled need to flush:
BufferOverflowException extends RuntimeException
On Reflection API - May the class not available in jar OR Unable to Cast
ClassCastException extends RuntimeException
ClassNotFoundException extends (ReflectiveOperationException extends Exception)
NoSuchFieldException
value non-ZERO/ZERO
ArithmeticException extends RuntimeException
VirtualMachineError extends Error
StackOverflowError extends VirtualMachineError
Thrown when a stack overflow occurs because an application recurses too deeply.
OutOfMemoryError extends VirtualMachineError
Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory,
and no more memory could be made available by the garbage collector.
Heap memory is the run time data area from which the memory for all java class instances and arrays is allocated.
The heap can be of fixed size or variable size depending on the garbage collection strategy. Maximum heap size can
be set using –Xmx option. By default, the maximum heap size is set to 64 MB.
LinkageError extends Error
NoClassDefFoundError extends LinkageError
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class
(as part of a normal method call or as part of creating a new instance using the new expression) and no definition
of the class could be found.
« The searched-for class definition existed when the currently executing class was compiled,
but the definition can no longer be found.
UnknownError extends (VirtualMachineError extends Error)
ClassCircularityError extends (LinkageError extends Error)
ClassFormatError extends LinkageError
ThreadDeath extends Error
An instance of ThreadDeath is thrown in the victim thread when the (deprecated) Thread.stop() method is invoked.
In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behavior. Basic, Refactoring Techniques
Method signature: It consists of method name and parameter list (number/type/order of the parameters). methodName(parametersList y). An instance method in a subclass with the same signature and return type as an instance method in the super-class overrides the super-class's method.
Java OOP concepts
Class - Collection of a common features of a group of object [static/instance Fields, blocks and Methods]
Object - Instance of a class (instance fields)
Abstraction - Process of hiding complex info and providing required info like API, Marker Interfaces ...
Encapsulation(Security) - Class Binding up with data members(fields) and member functions.
Inheritance (Reusability by placing common code in single class)
1. Multilevel - {A -> B -> C} 2. Multiple - Diamond problem {A <- (B) -> C} [Java not supports] 3. Cyclic {A <-> B} [Java not supports]
* Is-A Relation - Class A extends B
* Hash-A Relation - Class A { B obj = new B(); } - (Composition/Aggregation)
Polymorphism (Flexibility) 1. Compile-Time Overloading 2. Runtime Overriding [Greek - "many forms"]
int[] arr = {1,2,3}; int arrLength = arr.length; // Fixed length of sequential blocks to hold same data type
String str = "Yash"; int strLength = str.length(); // Immutable Object value can't be changed.
List<?> collections = new ArrayList<String>(); int collectionGroupSize = collections.size();
Map<?, ?> mapEntry = new HashMap<String, String>();
Set<?> keySet = mapEntry.keySet(); // Set of Key's
Set<?> entrySet = mapEntry.entrySet(); // Set of Entries [Key, Value]
// Immutable Objects once created they can't be modified. final class Integer/String/Employee
Integer val = Integer.valueOf("100"); String str2 = String.valueOf(100); // Immutable classes
final class Employee { // All Wrapper classes, java.util.UUID, java.io.File ...
private final String empName; // Field as Final(values can be assigned only once) Only getter functions.
public Employee(String name) { this.empName = name; }
} Native Java Code for Hashtable.h, Hashtable.cpp
SQL API.
You can check your current JDK and JRE versions on your command prompt respectively,
- JDK
javac -version [C:\Program Files\Java\jdk1.8.0_121\bin]o/p:javac 1.8.0_121 - JRE
java -version[C:\Program Files\Java\jdk1.8.0_121\bin]o/P:java version "1.8.0_102"
JAVA_HOME - Must be set to JDK otherwise maven projects leads to compilation error. [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? C:\Softwares\OpenJDK\, 7-zip
Fatal error compiling: invalid target release: JRE and JDK must be of same version
1.8.0.XXX
Disable TLS 1.0 and 1.1
security-libs/javax.net.ssl: TLS 1.0 and 1.1 are versions of the TLS protocol that are no longer considered secure and have been superseded by more secure and modern versions (TLS 1.2 and 1.3).
Core Java
-
Java Programming Language Basics
- Object, Class, Encapsulation, Interface, Inheritance, Polymorphism (Method Overloading, Overriding)
- JVM Architecture, Memory Areas
- JVM Class Loader SubSystem
- Core Java Interview Questions & Programs
- Interview Concepts
Stack Posts
- Comparable vs Comparator
- Collections and Arrays
-
String, StringBuffer, and StringBuilder
- String reverse
- Remove single char
- File data to String
- Unicode equality check Spacing entities
- split(String regex, int limit)
- Longest String of an array
-
Object Serialization
- Interface's Serializable vs Externalizable
- Transient Keyword
-
implements Runnablevsextends Thread - JSON
- Files,
Logging API- Append text to Existing file
- Counting number of words in a file
- Properties
- Properties with reference key