Sunday, March 30, 2014
JAVA
- JVM- It stands for Java Virtual Machine. JVM is a kind of abstract machine that gives an idea of the time during which the byte code of java can be carried out. Loading a code, verifying the code, then executing the code and finally providing the runtime environment for the code are the four main tasks that JVM performs. JVM is dependent on many software and hardware platforms.
- JDK- It stands for Java Development Kit. It has physical existence and it contains JRE (Java Runtime Environment) and development tools like javac etc.
- JRE- It stands for Java Runtime Environment. JRE usually gives an idea of the java runtime environment. Some set of libraries (rt.jar) and some files that are used by JVM during the run time usually make up a JRE. JRE is basically an application of JVM and it also has physical existence.
Modifiers
JVM
Interpreter: takes only one instruction at a time for executionJust-in-time: takes a block of code at once and compile it before execute. so has plenty room for optimization
Rules for Method Overriding
- The argument list should be exactly the same as that of the overridden method.The return type should be the same or a subtype of the return type declared in the original overridden method in the superclass.The access level cannot be more restrictive than the overridden method's access level. For example: If the superclass method is declared public then the overridding method in the sub class cannot be either private or protected.Instance methods can be overridden only if they are inherited by the subclass.A method declared final cannot be overridden.A method declared static cannot be overridden but can be re-declared.If a method cannot be inherited, then it cannot be overridden.A subclass within the same package as the instance's superclass can override any superclass method that is not declared private or final.A subclass in a different package can only override the non-final methods declared public or protected.An overriding method can throw any uncheck exceptions, regardless of whether the overridden method throws exceptions or not. However, the overriding method should not throw checked exceptions that are new or broader than the ones declared by the overridden method. The overriding method can throw narrower or fewer exceptions than the overridden method.Constructors cannot be overridden.
For overloaded
1. Same Method Name
2. Same Return Type
3. Different patameters
4. Different access modifiers
5. Different Exceptions
For overriding
1. Same Method Name
2. Same Return Type if different then "The return type is incompatible with <ParentClass>.<ParentMethod>method()"
3. Same parameters if different then "The method bmethod(int) of type A must override or implement a supertype method"
4. same or greater access modifiers then "Cannot reduce the visibility of the inherited method from B"
5. same or Different Exceptions means child Exception
1. Opps
Encapsulation
Abstraction
Polymorphism
overriding
overloading
Inheritance
2. JVM
GIT vs Interpiter
Memory Locations
Class Loaders
Execution Engine
3. GC
Ways to eligible for GC
4. Collections
Queues vs Topic
Concurent Map / list/ set
5. Threads
Thread Local
Thread Pool
How many ways to create thread
Syncronized thread
Syncronized static thread
callable
Thread LifeCycle
wait
notify
notifyAll
Sleep
yeild
6. Exception Handling
7. Java version topics
java 1.5
Enum
Generic
ForEach
Queue
Annotations
Autoboxing Unboxing
Var args
Static imports
Covatiant Return types
java 1.6
Navigable Set/Map
java 1.7
Enhancements in HashMap
try with resources
Try with multiple catch
Switch can take string args
java 1.8
Lambda Expressions
Streams
Functional Interface
Interface changes with default / static methods
Java DateTime API(joda.org ==> joda api)
Method Reference / constructor refence by :: operator
predicate, function, consumer ==> predefined functional interfaces
1. Opps
Encapsulation
Abstraction
Polymorphism
overriding
overloading
Inheritance
2. JVM
GIT vs Interpiter
Memory Locations
Class Loaders
Execution Engine
3. GC
Ways to eligible for GC
4. Collections
Queues vs Topic
Concurent Map / list/ set
5. Threads
Thread Local
Thread Pool
How many ways to create thread
Syncronized thread
Syncronized static thread
callable
Thread LifeCycle
wait
notify
notifyAll
Sleep
yeild
6. Exception Handling
7. Java version topics
java 1.5
Enum
Generic
ForEach
Queue
Annotations
Autoboxing Unboxing
Var args
Static imports
Covatiant Return types
java 1.6
Navigable Set/Map
java 1.7
Enhancements in HashMap
try with resources
Try with multiple catch
Switch can take string args
java 1.8
Lambda Expressions
Streams
Functional Interface
Interface changes with default / static methods
Java DateTime API(joda.org ==> joda api)
Method Reference / constructor refence by :: operator
predicate, function, consumer ==> predefined functional interfaces
+------------------------+-------------------------------+----------------+
| Feature | Lombok | Records |
+------------------------+-------------------------------+----------------+
| Immutability | No | Yes |
| Extensibility | Yes | No |
| Boilerplate code | Reduces | Reduces |
| Readability | Can be more difficult to read | Easier to read |
| Robustness | Less robust | More robust |
| Third-Party dependency | Yes | No |
| IDE compatibility | Not easy | Easy |
+------------------------+-------------------------------+----------------+
| Feature | Lombok | Records |
+------------------------+-------------------------------+----------------+
| Immutability | No | Yes |
| Extensibility | Yes | No |
| Boilerplate code | Reduces | Reduces |
| Readability | Can be more difficult to read | Easier to read |
| Robustness | Less robust | More robust |
| Third-Party dependency | Yes | No |
| IDE compatibility | Not easy | Easy |
+------------------------+-------------------------------+----------------+
Important JVM Parameters
Go to start of metadata
Enabling JMX
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
Control Memory Usage
-Xms512m -Xmx1200m -Xss256k -XX:PermSize=256m -XX:MaxPermSize=512m
Large heaps

if 4G is max RAM then reduce the heap so with assumption that u have 4G RAM set the following:
-verbose:gc -Xss256k -Xmn512m -Xms3g -Xmx3g -XX:TargetSurviorRatio=80 -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+HeapDumpOnOutOfMemoryError -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=3002
-verbose:gc -Xss256k -Xmn512m -Xms3g -Xmx3g -XX:TargetSurviorRatio=80 -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintGCApplicationStoppedTime -XX:+HeapDumpOnOutOfMemoryError -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=3002
256K thread stack size optimization is related to the L2 processor cache size of 256K
ms : Initial heap memory , mx : max heap memory , ss: thread stack size (useful when you have lots of threads) , permsize : heap memory used for short lived objects , it is better to collect objects in the young generation instead of making them go through a old generation collection
Enable GC Statistics
-verbose:gc
-XX:-HeapDumpOnOutOfMemoryError
-XX:-PrintGCDetails
-XX:-PrintGCTimeStamps
-XX:-TraceClassUnloading <- useful if u need to trace classes getting unloaded due to memeory pressures
-XX:-HeapDumpOnOutOfMemoryError
-XX:-PrintGCDetails
-XX:-PrintGCTimeStamps
-XX:-TraceClassUnloading <- useful if u need to trace classes getting unloaded due to memeory pressures
Other GC Optimizations
-Dsun.rmi.dgc.server.gcInterval=900000 -Dsun.rmi.dgc.client.gcInterval=900000 | Trigger a GC every 15 minutes instead of the default 1 hour in JDK 6 |
-server | JVM in server mode |
-XX:+UseCompressedOops | on 64 bit JVMs memory is managed through 32 bit offsets. |
-XX:+OptimizeStringConcat | Useful in tomcat which has lots of string manipulations |
-XX:+DoEscapeAnalysis |
Helps compiler figuring out if synchonized block can be eliminate as in
local variables. Also figures out if object can be allocated on stack
|
Saturday, March 29, 2014
Java Annotations
- Annotations are introduced in java along with JDK 1.5, annotations are used to provide META data to the classes, variables, methods of java
- Annotations are given by SUN as replacement to the use of xml files in java
- Every annotations is internally an Interface, but the key words starts with @ symbol
- In hibernate annotations are given to replace hibernate mapping [ xml ] files
- hibernate borrowed annotations from java persistence API but hibernate it self doesn’t contain its own annotations
- At j2se level, sun has provided very limited set of annotations like @Override and @Deprecated …etc…
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import XXX.AbcImpl;
// This annotation can only be applied to class methods.
// @Target({ElementType.METHOD})
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, ElementType.TYPE })// Make this annotation accessible at runtime via reflection.
@Retention(RUNTIME)@Constraint(validatedBy = AbcImpl.class)
public @interface Abc {
public String message() default "{wc.def.notempty.on.trim}";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default {};
}
Now is annotated, so we can call this as a @Abc.
Subscribe to:
Posts (Atom)
Security Certificates
1. Cryptography Basics Understand Key Concepts : Encryption, decryption, hashing, and digital signatures. Key terms: confidentiality, inte...
-
Micro Service 12 Factor The Twelve-Factor App is a methodology for building software-as-a-service apps Codebase : One codebase tracked in v...
-
Key words Knowledge Factor Possession Factor Inherence Factor All individual factors are not secure, because if any factor comprimise. So,...
-
What is IAM rules. Lambda Pros / Cons [ColdStart Latency]. How many ways we can invoke a lambda SQS VS SNS S3 usage and different types of...