Java Developers

Java Developers Java developer is a place to share the knowledge and take some communication. By that way we learn together, and improve our skills. Why not?

Good article
02/07/2020

Good article

“What is important is seldom urgent and what is urgent is seldom important.” — Dwight D. Eisenhower

11/21/2018

=)

11/18/2018

LOCK
- A synchronized method is a shorthand for a synchronized block that spans an entire method body, and whose lock is the object on which the method is being invoked
- Synchronization is not just about mutual exclusion, it has some significant and subtle aspect: guarantees memory visibility and prevent the compiler to reorder operations and cache values in registers
- Synchronizing both the getter and setter are required, synchronizing only the setter would not be sufficient.
- Synchronization guarantee both visibility and atomicity but volatile variables can only guarantee visibility.

Notes:
- Synchronized methods can make individual operations atomic but additional locking is required when multiple operations are combined into a compound action
- Avoid holding locks during lengthy computations or operations at risk of not completing quickly such as network or console I/O
- It is not safe to use shared mutable long and double variables in multithreaded programs unless they are declared volatile or guarded by a lock.

02/07/2018

THREAD SAFETY
Prevent define a transformation of an action in terms of it's previous state (like check-then-act and read-modify-write) in concurrency environment. Compound actions on a shared state must always be atomic to ensure state consistency.

12/03/2017

STRING COMPARE
Use CONSTANT.equals(VARIABLE) instead of VARIABLE.equals(CONSTANT) to avoid NullPointerException

06/13/2017

met requirement :).

05/25/2017

EXTENDS OR IMPLEMENT
- class B should extends class A only if an “is-a” relationship exists between the two classes (B is really an A), if not, it is often the case that B should contain a private instance of A and expose a simple API(composition relationship)
- Prefer interface to define an contract and specify the behaviour of a particular data type, by implements that contract the class implementing "has-a" capability, use interface as reference type make increase API flexibility

01/17/2017

OVERRIDDEN METHOD
- An object that is a member of one of the subclass types. When the program invokes a method defined in the superclass, the method that gets called is actually the subclass method that overrides the superclass version.
- Overridden methods are alien methods and we have no control over it, so don't invoke them on constructor, clone method, or synchronized region...

01/14/2017

AUTOBOXING AND UNBOXING
Autoboxing and unboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. These features let developers write cleaner code, making it easier to read.
1) Remember, they make blur but do not erase the distinction between primitive types and reference types.
2) There are performance costs and unnecessary object creations (boxing) associated with boxing and unboxing, specially when use it in inner loop, even if it is done automatically.
3)
- When you mix primitives and boxed primitives in a single operation, the boxed primitive is auto unboxed.
- When you try to apply operates only support for primitive types (such as remainder, unary plus, ...) to boxed primitives the boxed primitive is auto unboxed, but the == operator can be apply to both of them and it's almost always wrong to boxed primitives.
4) If your program tries to auto unbox null, it will throw a NullPointerException at runtime.

As this example:
Integer num1 = new Integer(25);
Integer num2 = new Integer(25);
System.out.println(num1 < num2 ? -1 : (num1 == num2 ? 0 : 1));

In first test (num1 < num2) does auto unbox (because < operator only support for primitive type) works fine and return false. Second test performs an identity comparison on the two object references (num1 and num2) will return false and print unexpected result is 1 to console.

Finally, autoboxing and unboxing reduces the verbosity, but not the danger, of using boxed primitives. Avoid them when unnecessary.

12/23/2016

FINAL VARIABLE
- Declare final a variable don't make it can't be change. If a final variable holds a reference to an object then the state of the object may be changed by operations on the object
- The compiler makes final variable prevent assignment operators since the second times so the variable will always refer to only one object when it's initialized

Address

Java, TX

Opening Hours

Monday 8am - 5pm
Tuesday 8am - 5pm
Wednesday 8am - 5pm
Thursday 8am - 5pm
Friday 8am - 5pm

Website

Alerts

Be the first to know and let us send you an email when Java Developers posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Contact The Organization

Send a message to Java Developers:

Share

Category