четверг, 25 сентября 2014 г.

java memory model


explain java memory model heap stack method area frames java interview

From Java Code to Java Heap: Understanding the Memory Usage of Your Application

The JVM and Java Garbage Collection - OLL Live (Recorded Webcast Event)

Understanding Java Garbage Collection and what you can do about it

java concurrency


Multithreading in Java Part 1 | Introduction to Threads in Java | Java tutorial by Java9s

Multithreading in Java Part 2 | Thread States | Java Tutorials by Java9s

Thread Safety and code synchronization in java | Multithreading in Java part 3

Multithreading Interview Question In Java

java interview questions


Core Java Interview Questions And Answers

Exception Handling in Java - Checked and Unchecked Exceptions

hash code


HashCode and its purpose

equals() and hashCode() in Java with an Example

hashcode equals method java interview question and answer

Difference between == and equals method in JAVA

java clone


Java jdk 7 tutorial 19 clone method

Object Clone: Deep vs. Shallow Copy

Java Clone - Advanced topic

Object Class Hash Code and Clone on 05 09 2012

среда, 24 сентября 2014 г.

java serialization

[video main]

How java serialization works internally, Object Serialization algorithm

Learn Java Tutorial for Beginners, Part 46: Serialization

Сериализация в Java - Serialization #1 - Advanced Java

Сериализация в XML - Serialization #2 - Advanced Java

Сериализация в JSON - Serialization #3 - Advanced Java

Программирование на Java для начинающих #18(Serialization)

[video additional]

Serialization and performance (Sergey Morenets, Ukraine)

[articles main]

Сериализация в Java [ru]

Java Object Serialization Specification

Top 10 Java Serialization Interview Questions and Answers

Java object serialization - Tutorial

The Java serialization algorithm revealed

[articles additional]

5 things you didn't know about ... Java Object Serialization

How to Serialize an Object in Java
7 steps

Изучите секреты Java Serialization API [ru]

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialised - converted into a replica of the original object.

пятница, 19 сентября 2014 г.

When to use Singleton pattern?

Patterns I Hate #1: Singleton

Singleton Pattern

Use your singletons wisely

Difference between Singleton Pattern vs Static Class in Java

10 Singleton Pattern Interview questions in Java - Answered

Why Enum Singleton are better in Java

Singleton Pattern – Positive and Negative Aspects

This entry inaugurates a new series on patterns that I hate. Hate is a strong word, perhaps a better name would be “patterns that I’ve frequently seen lead to ruin”. But that seemed too long.
Anyhow, the singleton pattern is the hands-down #1 pattern that can lead me to froth at the mouth. When a programmer first stumbles on GoF, Singleton seems to be the pattern that they first latch on to because it’s so easy to understand (just one class). Novice programmers doing their first design will often break out subsystems and access them via singletons.
Why is Singleton evil?

When to use Object pool pattern?

Various pools - Thread pools, connection pools, EJB object pools - Flyweight is really about management of shared resources


You need to frequently create and destroy objects.

Objects are similar in size.

Allocating objects on the heap is slow or could lead to memory fragmentation.

Each object encapsulates a resource such as a database or network connection that is expensive to acquire and could be reused.

Basically, we'll use an object pool whenever there are several clients who needs the same stateless resource which is expensive to create.

When there are several clients who need the same resource at different times.

It is deprecated as a general technique, because - as you noticed - creation and destruction of short lived objects per se (i.e. memory allocation and GC) is extremely cheap in modern JVMs. So using a hand-written object pool for your run-of-the-mill objects is most likely slower, more complicated and more error-prone than plain new.*

It still has its uses though, for special objects whose creation is relatively costly, like DB / network connections, threads etc.

Examples of GoF Design Patterns in jdk

Pattern Proxy (Surrogate)

Proxy Design Pattern Tutorial (video)

Proxy Design Pattern Tutorial

The proxy design pattern allows you to provide an interface to other objects by creating a wrapper class as the proxy. The wrapper class, which is the proxy, can add additional functionality to the object of interest without changing the object's code. Below are some of the common examples in which the proxy pattern is used,

Adding security access to an existing object. The proxy will determine if the client can access the object of interest.
Simplifying the API of complex objects. The proxy can provide a simple API so that the client code does not have to deal with the complexity of the object of interest.
Providing interface for remote resources, such as web service or REST resources.
Coordinating expensive operations on remote resources by asking the remote resources to start the operation as soon as possible before accessing the resources.
Adding a thread-safe feature to an existing class without changing the existing class's code.
In short, the proxy is the object that is being called by the client to access the real object behind the scene.

When to use proxy pattern?

Remote Proxy – Represents an object locally which belongs to a different address space. Think of an ATM implementation, it will hold proxy objects for bank information that exists in the remote server.
( RMI, CORBA and Jini)

Virtual Proxy (Lazy Load Proxy) – In place of a complex or heavy object, use a skeleton representation. When an underlying image is huge in size, just represent it using a virtual proxy object and on demand load the real object. You feel that the real object is expensive in terms of instantiation and so without the real need we are not going to use the real object. Until the need arises we will use the virtual proxy.

Protection Proxy – Are you working on a MNC? If so, we might be well aware of the proxy server that provides us internet by restricting access to some sort of websites like public e-mail, social networking, data storage etc. The management feels that, it is better to block some content and provide only work related web pages. Proxy server does that job. This is a type of proxy design pattern.

A smart reference - a replacement for a bare pointer that performs additional actions when an object is accessed.
Provides additional actions whenever a target
object is referenced such as counting the number of references to the object

Adding a thread-safe feature to an existing class without changing the existing class's code.

Cache Proxy - Provides temporary storage of the results of expensive target
operations so that multiple clients can share the results

Firewall Proxy - Protects targets from bad clients (or vice versa)

java.rmi.*, the whole API actually.

Java Remote Method Invocation (RMI)

In java RMI an object on one machine (executing in one JVM) called a client can invoke methods on an object in another machine (another JVM) the second object is called a remote object. The proxy (also called a stub) resides on the client machine and the client invokes the proxy in as if it is invoking the object itself (remember that the proxy implements the same interface that RealSubject implements). The proxy itself will handle communication to the remote object, invoke the method on that remote object, and would return the result if any to the client. The proxy in this case is a Remote proxy.

Adapter vs Proxy Design Pattern

Adapter design pattern provides a different interface from the real object and enables the client to use it to interact with the real object. But, proxy design pattern provides the same interface as in the real object.

Decorator vs Proxy Design Patter

Decorator design pattern adds behaviour at runtime to the real object. But, Proxy does not change the behaviour instead it controls the behaviour.

среда, 17 сентября 2014 г.

How to make code review?

The Helpful Tips

- Limit your review to the scope of the work. An effective review is laser-focused on the problem that is being worked on. Create follow-up action items (e.g., tickets) for any out-of-scope work that you think needs additional consideration.
- Make your review specific. Address specific lines, or components in your review. Avoid making general, sweeping statements.
- Make your review actionable. If it’s not immediately obvious how to implement the change you’ve requested, leave it out of your review.-
- Deliver your review in a timely manner. The longer you wait to give your review, the more the creator will have to draw from their memory on why certain decisions may have been made. I’ve started scheduling review times with one of my co-workers so that we can go through the work together. This isn’t always possible, or desirable, but it can be effective for small teams.
- As part of your review, be sure to acknowledge the time spent by the coder on the issue. Sometimes a three line change can take hours and hours of work. Take the time to be a human being and acknowledge the time that’s been spent on the issue.
- Be thankful. Especially on open source projects where contributors are generally not *required* to submit anything. And especially at work where co-workers are sometimes forced to work on parts of the project they genuinely hate. Take the time to say “thanks”. It can make all the difference.

Six Ways to Make Your Peer Code Reviews More Effective


- Over-the-shoulder – One developer looks over the author's shoulder as the latter walks through the code.
- Email pass-around – Source code management system emails code to reviewers automatically after checkin is made.
- Pair Programming – Two authors develop code together at the same workstation, such is common in Extreme Programming.
- Tool-assisted code review – Authors and reviewers use software tools, informal ones such as pastebins and IRC, or specialized tools designed for peer code review.

Four ways to a Practical Code Review

For your convenience, here are the 11 practices in a simple list that's easy to keep on file:
- Review fewer than 200–400 lines of code at a time.
- Aim for an inspection rate of fewer than 300–500 LOC per hour.
- Take enough time for a proper, slow review, but not more than 60–90 minutes.
- Be sure that authors annotate source code before the review begins.
- Establish quantifiable goals for code review and capture metrics so you can improve your processes.
- Use checklists, because they substantially improve results for both authors and reviewers.
- Verify that the defects are actually fixed.
- Foster a good code review culture in which finding defects is viewed positively.
- Beware of the Big Brother effect.
- Review at least part of the code, even if you can't do all of it, to benefit from The Ego Effect.
- Adopt lightweight, tool-assisted code reviews.

11 proven practices for more effective, efficient peer code review

Effective Code Reviews Without the Pain

What Makes a Good Code Review?

10 ways to be a faster code reviewer

Three tools that make Java code review painless and effective

How We Code Review

вторник, 16 сентября 2014 г.

среда, 10 сентября 2014 г.

Cloneable Interface in Java

1) Resources

Cloneable Interface in Java

Java Cloning Tutorial, Shallow Copy and Deep Copy

A guide to object cloning in java

How to implement Cloneable Interface

Implementing Cloneable interface

clone() and the Cloneable Interface in Java

How to implement cloning in java using Cloneable interface?

About Java cloneable

What is the use of cloneable interface in java?

Implementing the Cloneable Interface

How clone method works in Java