Best Cyber Monday Deals for Programmers

Hello Guys, I wanted to post this article a couple of days before but just couldn't manage to do it. Cyber Monday is almost over but there are still a couple of great deals for programmers who are running, particularly from PluaralSight and Udemy, two of the best online learning places.  If you want to invest some money in your learning and upgrade this is the best time to do so because prices have come down drastically.

Here are the two of such deals which I have also taken advantage to renew my subscription and add some good courses on my existing collection.


1. Save up to $150 on PluralSight

I wanted to let you know about a pretty sweet deal that PluralSight is running right now.

For the first time ever, they've knocked down the price on their PluralSight Premium plan by $150.

The Premium plan includes the entire PluralSight course library, plus their new certification practice exams, interactive courses, and practice projects to help reinforce what you're learning.

This new plan adds a lot of value—and with this promotion—at a great price too.

They've also knocked $100 off their regular annual plan.

Every serious developer must have a PluralSight subscription.  It's like the Netflix for Software developers.

=> Click here to save up to $150 on PluralSight

All the best with your learning

2. 

10 Example of String in Java



1. String IndexOf Example
2. String SubString Example
3. String Matches Example
4. String Length Example
5. String Empty Check Example

How to replace characters in String

How to remove whitespace from String in Java

How to find length of String in Java

How to check if String is Empty in Java

How to create SubString from String in Java

How to Split String in Java

How to check if String contais a word

How to

arraylist string example in java

java object string example

java string split example

java string to inputstream example

java string to int example

java string length example

java string to double example

java switch string example


10 points about synchronized in Java



1. Synchronized can only be applied to methods and code block, you can not make a variable, a class or an interface synchronized in Java.

2. When a thread enters a synchronized block or method, it acquire lock on the object method has been called. Similarly when thread exits the block, both normally or abruptly due to any error, it relinquish the lock.

3. Synchronized keyword not only provide mutual exclusion, but also provides visibility guarantee. Memory barriers are updated when thread enter or exits synchronized block or method. 

10 points about Exception in Java



1. There are two kinds of exception in Java, checked and unchecked exception. Any exception, which is subclass of java.lang.Exception but not inherited from java.lang.RuntimeException is known as checked Exception. On the other hand those inherited from RuntimeException are called unchecked exception.

2. Checked exceptions follow special symanatic rules in Java, they are literally checked by compiler during compile time.

3. All Exception are inherited from Throwable class.

4. Though Error are not inherited from RuntimeException they are also unchecked.

Why Constructor Injection is better than Setter Injection

There is no doubt that dependency injection is good, and offer several benefits. When it comes to inject dependency, there are two main ways, by using constructor and by using setter methods.


Constructor injection makes dependencies obvious
enforces order of initialization
makes wiring easy
supports testable code
more readable
enforce completeness


CreditCardProcessor ccp = new CreditCardProcessor();

OfflineQueue oq = new OfflineQueue()


Database db = new Database();

IS-A vs HAS-A Relationship Example in Java


IS-A means two classes are part of same inheritance hierarchy, while HAS-A means two classes are not part of same inheritance hierarchy but class A is composed using class B and uses it to provide certain functionality. 

Java Interface and Abstract class Interview Questions


---------------------------------------
What is Abstract class?
What is interface?
Difference between Abstract class and inteface?
Can we make a class abstract without abstract method?
Can we make a class final and abstract?
Can we declare constructor in abstract class in Java?
Can an interface extend more than one interface in Java?
Can a class extend more than one class in Java?

Can we have non abstract method inside interface?
What is default method of Java 8?

Difference between SOAP and REST Style Web Service in Java

SOAP and REST are two ways to create web services in Java world, here are couple of key differences between REST and SOAP in Java




Top 50 Core Java Interview Questions with Answers


1)  How Java achieves platform independence? (answer)



2)  What is ClassLoader in Java? (answer)



3)  Write a Java program to check if a number is Even or Odd? (answer)



4)  Difference between ArrayList and HashSet in Java? (answer)



5)  What is double checked locking in Singleton? (answer)



6)  How do you create thread-safe Singleton in Java? (answer)



7)  When to use volatile variable in Java? (answer)



8)  When to use a transient variable in Java? (answer)



9)  Difference between transient and volatile variable in Java? (answer)



10) Difference between Serializable and Externalizable in Java? (answer)



11) Can we override a private method in Java? (answer)



12) Difference between Hashtable and HashMap in Java? (answer)



13) Difference between List and Set in Java? (answer)



14) Difference between ArrayList and Vector in Java



15) Difference between Hashtable and ConcurrentHashMap in Java? (answer)



16) How does ConcurrentHashMap achieve scalability? (answer)



17) Which two methods you will override for an Object to be used as Key in HashMap? (answer)



18) Difference between wait and sleep in Java? (answer)



19) Difference between notify and notifyAll in Java? (answer)



20) Why you override hashcode, along with equals() in Java? (answer)



21) What is load factor of HashMap means? (answer)



22) Difference between ArrayList and LinkedList in Java? (answer)



23) Difference between CountDownLatch and CyclicBarrier in Java? (answer)



24) When do you use Runnable vs Thread in Java? (answer)



25) What is the meaning of Enum being type-safe in Java? (answer)



26) How does Autoboxing of Integer work in Java? (answer)



27) Difference between PATH and Classpath in Java? (answer)



28) Difference between method overloading and overriding in Java? (answer)



29) How do you prevent a class from being sub-classed in Java? (answer)



30) How do you restrict your class from being used by your client? (answer)



31) Difference between StringBuilder and StringBuffer in Java? (answer)



32) Difference between Polymorphism and Inheritance in Java? (answer)



33) Can we override static method in Java? (answer)



34) Can we access private method in Java? (answer)



35) Difference between interface and abstract class in Java? (answer)



36) Difference between DOM and SAX parser in Java? (answer)



37) Difference between throw and throws keyword in Java? (answer)



38) Difference between fail-safe and fail-fast iterators in Java? (answer)



39) Difference between Iterator and Enumeration in Java? (answer)



40) What is identity HashMap in Java? (answer)



41) What is String pool in Java? (answer)



42) Can a Serializable class contain a non serializable field in Java? (answer)



43) Difference between this and super in Java? (answer)



44) Difference between Comparator and Comparable in Java? (answer)



45) Difference between java.util.Date and java.sql.Date in Java? (answer)



46) Why wait and notify method are declared in Object class in Java? (answer)



47) Why Java doesn't support multiple inheritances? (answer)



48) Difference between checked and unchecked Exception in Java? (answer)



49) Difference between Error and Exception in Java? (answer)



50) Difference between race condition and deadlock in Java? (answer)

10 points about JPA Entity Class for Hibernate Java developers.

JPA Entity class is in core of JPA specification and its one of the most important thing a Java developer should know, while working with JPA implementations like Hibernate. Many Java programmers either not aware of these rules and best practices or doesn't pay enough attention while creating JPA entity class to end up with same mistakes e.g. equals and hashcode not working, issues with access type etc. This motivates me to hund down and write these rules


The entity class must have a no-arg constructor. It may have other constructors as well. The no-arg constructor must be public or protected.
The entity class must a be top-level class. An enum or interface must not not be designated as an entity.
The entity class must not be final. No methods or persistent instance variables of the entity class may be final.
If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.
Both abstract and concrete classes can be entities. Entities may extend non-entity classes as well as entity classes, and non-entity classes may extend entity classes.

http://stackoverflow.com/questions/6033905/create-the-perfect-jpa-entity

Further Learning
Introduction To Hibernate
Spring with JPA and Hibernate
Introduction to Spring MVC
Java Web Fundamentals by Kevin Jones

XML Interview questions and answers for programmer

XML Interview questions and answers for programmer
---------------------------------------------------
What is XML ?
Difference between DTD and XML Schema?
What is Xpath ?
What is XSLT?
What is element and attribute in XML?
What is meaning of well formed XML ?
What is benefit of using XML ?
What is XML namespace? Why it's important?
Difference between DOM and SAX parser ?
What is a CDATA section in XML?
What is SOAP and how does it relate to XML?
What is XML data Binding ?
What is XML binding ? How to you bind XML document into Java objects?
What is XML Parsing? Which XML parsers have you used ?
What is difference between DOM and SAX parsers?
What is XPATH ? Can you run XPATh expression in Java ? How?
Does Java supports XSLT? How will you do XSLT transformation in Java?
How to write xsl stylesheet to remove an attribute from xml document?
Which Java open source library have you used for XML processing?
What is xml beans? have you used it?
Which packages are related to XML functionalities in Java?
What is difference between DTD and Schema?
What are xml namespaces? how do you resolve conflicts?
What are the issues you faced while doing XML processing in Java? 

XPath Example in Java

10 Example of XPATH
------------------------
package test;

import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
  * Simple Java program to execute XPATH expression and retrieve value from XML documents
  */
public class XPathExample {

    public static void main(String[] args){
        try {
            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(true);
         
            DocumentBuilder builder = domFactory.newDocumentBuilder();
            Document doc = builder.parse("Books.xml");
         
         
            XPath xpath = XPathFactory.newInstance().newXPath();
         
            XPathExpression expr = xpath.compile("bookstore/book[@category='COOKING']/title/text() | bookstore/book[@category='WEB']/title/text()");

         
            Object result = expr.evaluate(doc, XPathConstants.NODESET);
         
         
            NodeList nodes = (NodeList) result;
            System.out.println("Result: " + nodes);
            for (int i = 0; i < nodes.getLength(); i++) {
                System.out.println(nodes.item(i).getNodeValue());
            }
         
        }catch (XPathExpressionException ex) {
            ex.printStackTrace();
        } catch (SAXException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ParserConfigurationException ex) {
            ex.printStackTrace();
        }
    }
}

That's all about how to use XPath in Java. 

Top 10 Reasons to do Java Certification like OCPJP and OCAJP



1. To Learn Java Better


2. Hiring advantages


3. To do well on Java written test

4. To do well on Java interviews


5. To Earn more - better Packages

6. To get Recognized in your team and company

7. To gain confidence in your Java skill


8. Add some weight in your CV

9. Learning opportunity

10. Upgrading your Java skills

Difference between dependency injection and factory pattern?

Difference between dependency injection and factory pattern?
--------------------------------------------------------------
What is difference between factory pattern and dependency injection or difference between sprint IOC and factory pattern? are some of the frequently asked quesiton in Java irvs. Though both factory pattern and dependency injection might look similar, there is a fundamental difference between them. Factory pattern takes responsibility of creating object, while dependency injection inverse the process how an object gets his dependency, it transfer that responsibility to an external party e.g. Spring IOC transfer object creation and management functionality to the IOC container. In other words, If your use Factory pattern then your object has to retrieve dependency by himself, but in case of dependency injection, dependency will be injected to the object by container or whoever manages that object.

Advantages of Dependency Injection over Factory Pattern

1. Better decoupling of classes .

2. Better Unit testing . Now it is easier to inject mock implementation of the services into the object being tested.


You might also like.


In short, though both Factory pattern and DI helps object creation, DI is much better than Factory. With DI you get better decoupling of object and its dependency. Dependency injection also makes unit testing easier, which is very important to keep quality control in check. BTW, nothing comes free, in order to use dependency injection you need a container e.g. Spring IOC, while you can use Factory pattern by your own. You also need to provide configuraiton to initialize object and inject dependency, like one we use with Spring to initialize beans e.g. aplicatoin-Context.xml

Tricky Multithreading and Concurrency Questions from Java Interviews

1) Question on volatile variable

2) Can we make an Array volatile in Java?

3) Can you write code for double checked locking in Singleton?

4) What happens if the object your are synchronizing is null?

5) Why Iterator of ConcurrentHashMap doesn't throw ConcurrentModificationException?

6) What is Busy Spin waiting Strategy? What is benefit?

7) If start() calls run() they why not we call run() method directly?

8) Why you should call wait() and notify() method in loop and not on if block?

Few more questions
- If you are asked to write code for synchronizing between two threads or 100 threads? which code will be harder to write and why?

- Tell me three problems you usually face on concurrent environment.

- What happend if you add task into Fixed thread pool and worker queue is full?

- What happend if an exception is throw into a Thread?

JMSWMQ2020: Failed to connect to queue manager

JMSWMQ2020: Failed to connect to queue manager
-----------------------------------------------
Cause : reason code 2397 comes when SSL is enabled between MQ client and server but SSL handshake is not successful due to expired or mismatched certificates e.g. different signer.

Solution : add proper certificates in both MQ client and server. If you are using Java to connect to MQ then you also need to add correct certificates on keystore and truststore.

How to round floating point number in Java

How to round floating point number in Java
--------------------------------------------
Rounding real in full:

Just use the method Math.floor () to round the real to the nearest integer:


Double a = Math. floor ( 1 . 99 ); //  1.0
Unlike the method Math.ceil () allows a real round to the nearest integer:


Double a = Math. ceil ( 1 . 01 ); //  2.0
If one wishes to respect the standard rounding rule, using the nearest higher or lower depending on the value around the decimal part, simply add 0.5 to the passed value Math.floor () :


Double a = Math. floor ( 1 . 99 + 0 . 5 ); //  2.0


Double a = Math. floor ( 1 . 49 + 0 . 5 ); //  1.0


If the value of the fraction is less than [b] 0.5 [/ b], the value will be rounded to the nearest whole number.
If the value of the fraction is greater than or equal to [b] 0.5 [/ b], the value will be rounded to the next whole number.
Warning: could also use a cast to type int or long to "lose" the fractional part, but it can cause problems with large values ​​because the cast can lead to a loss of information by truncation. Round to a real 'n' decimals: You can also make a rounded 'n' decimals using the following code:


 Select
Double a =  1 . 6,666,666 ;
//  Round  the  value  was  10 ^ -2
a * =  100 . 0 ;
a = . Math floor (a + 0 . 5 );
a / =  100 . 0 ; //  1.67
For simplicity, this method can be used directly

public  static  double  floor ( double a, int n) {
double p = Math. pow ( 10 . 0 , n)
return . Math floor ((a * p) + 0 . 5 ) / p;
 }
Which is used as follows:

Double a =  floor ( 1 . 6,666,666 , 2 ); //  1.67
But be careful, however, one can obtain an incorrect result when approaching the maximum limit doubles (1e308 anyway). For more accurate results, it may be towards the class BigDecimal and methods setScale () . Rounding to display: In contrast, if the result is to convert to a string, it is best to turn to the class java.text.DecimalFormat

How to use BigDecimal to add or subtract float and double in Java

How to use BigDecimal to add or subtract float and double in Java
-------------------------------------------------------------------
How to make precision calculations correct with floats or doubles?

If you try this:

 Select

. System.out println ( 1 . 3 - 1 . 2 );
You get: 0.10000000000000009 instead of 0.1, as shown on your calculator. In fact, it is impossible to accurately represent 0.1 or any negative power of 10 using a float or a double. The best solution for this problem is to use the java.math.BigDecimal class. For example, it is used like this:

 Select
BigDecimal bd1 =  new  BigDecimal ( " 1.3 " );
BigDecimal bd2 =  new  BigDecimal ( " 1.2 " );
. System.out println (bd1. substract (bd2));
Please note, you want to represent numbers must be passed as Strings in the constructor

J2EE Interview Question and answers for Java programmer

J2EE Interview Question and answers for Java programmer
----------------------------------------------------------
What is J2EE or JEE ?
What does Servlet JSP do in J2EE architecture ?
Difference between Application Server and Web Server?
What does EJB perovides EJB ?
What are popular application server which is used to deploy J2EE application?
What is advantage of using J2EE ?
What is the difference between Session Bean and Entity Bean?
What is distributed transaction and 2 phase commint?
What is difference in Java and J2EE ?
Does spring part of J2EE specificatoin ?

Jakarta Struts Interview Questions and Answers in Java

Jakarta Struts Interview Questions and Answers in Java
-------------------------------------------------------
What is struts ?
What is difference between Struts 1.0 and Struts 2.0?
What is Action class in Struts ?
What is difference between DispatchAction and LookupDispathAction in Struts ?
What is ActionServlet ?
Which design pattern is used in Struts framework?
What is difference between ForwardAction and IncludeAction in Struts?
What is difference between ActionForm and DynaActionForm in Struts ?
How can we prevent duplicate form submission using Struts?
What is difference between reset() and validate() in Struts framework?
What is struts-config.xml in Struts framework?