Monday, July 31, 2017

Top 7 JQuery Selectors Examples to find elements in DOM - ID, Class, Element, Descendent, Child, Multiple and Pseudo Selector

jQuery selectors are like CSS Selectors, which allows you to find or select an element from the DOM tree. When HTML pages loaded in a browser like Chrome, Firefox, or Internet Explorer, the browser creates a tree-like structure is known as Document Object Model or DOM. JavaScript and jQuery allow you to play with this DOM i.e. selecting elements from DOM, traversing through DOM, going from one element to another, selecting a list of elements from DOM, adding or removing elements from DOM, etc. In order to apply most of the jQuery function, available in the jQuery object, we first need to select HTML elements or tags, on which we want to apply those functions, jQuery selector allows you to choose those elements.

How to Create Read Only List, Map and Set in Java – UnModifiable Collection Example

Read-only List, Map and Set in Java
A read-only List means a List where you can not perform modification operations like add, remove or set. You can only read from the List by using get method or by using Iterator of List, This kind of List is good for a certain requirement where parameters are final and can not be changed. In Java, you can use Collections.unModifiableList() method to create read-only List , Collections.unmodifiableSet() for creating read-only Set like read-only HashSet and similarly creating a read-only Map in Java, as shown in below example. Any modification in the read-only List will result in java.lang.UnSupportedOperationException in Java.  

Sunday, July 30, 2017

How to Load Resources from Classpath in Java with Example

Classpath in Java is not only used to load .class files, but also can be used to load resources e.g. properties file, images, icons, thumbnails, or any binary content. Java provides API to read these resources as InputStream or URL. Suppose, you have a properties file inside config folder of your project, and you want to load that properties file, how do you do that? Similarly, you have icons and thumbnails for your web applications on icons directory of your project, how do you load them? The answer is by using java.lang.Class' getResource() and getResourceAsStream() method. These method accepts the path of resource as String and returns URL and InputStream respectively.

Saturday, July 29, 2017

How to sort a Map by keys in Java 8 - Example Tutorial

In the last article, I have shown you how to sort a Map by values in Java 8, and in this tutorial, you will learn how to sort a Map by keys lik a HashMap, ConcurrentHashMap, LinkedHashmap, or even Hashtable. Theoretically, you cannot sort a Map because it doesn't provide any ordering guarantee. For example, when you iterate over a HashMap, you don't know in which order entries will be traversed because HashMap doesn't provide any ordering. Then, how can you sort a Map which doesn't support order? Well, you can't and that's why you only sort entries of HashMap but you don't store the result back into HasMap or any other Map which doesn't support ordering. If you do so, then sorting will be lost.

Friday, July 28, 2017

What is CountDownLatch in Java - Concurrency Example Tutorial

What is CountDownLatch in Java
CountDownLatch in Java is a kind of synchronizer which allows one Thread to wait for one or more Threads before starts processing. This is a very crucial requirement and often needed in server-side core Java application and having this functionality built-in as CountDownLatch greatly simplifies the development. CountDownLatch in Java is introduced on Java 5 along with other concurrent utilities like CyclicBarrier, Semaphore, ConcurrentHashMap and BlockingQueue in java.util.concurrent package. In this Java concurrency tutorial we will what is CountDownLatch in Java, How CountDownLatch works in Java, an example of CountDownLatch in Java, and finally some worth noting points about this concurrent utility.

Default, Defender or Extension Method of Java 8 with Example

Java 8 now allows you to add non-abstract method implementations to interfaces by utilizing the default and static keyword. Methods with default keyword are known as default methods or defender methods in Java. Before Java 8, it was virtually impossible to change an interface once published. Any change e.g. the addition of a new method would have broken all clients. That's why when Java 8 decided to switch to internal iterator implementation using forEach() method, they face a daunting challenge of breaking all implementation of Iterable interface. Since backward compatibility is a top priority for Java engineers, and it wasn't practical to break all clients, they came up with the idea of the default method.

What is CyclicBarrier Example in Java 5 – Concurrency Tutorial

What is CyclicBarrier in Java
CyclicBarrier in Java is a synchronizer introduced in JDK 5 on java.util.Concurrent package along with other concurrent utility like Counting Semaphore, BlockingQueue, ConcurrentHashMap etc. CyclicBarrier is similar to CountDownLatch which we have seen in the last article  What is CountDownLatch in Java and allows multiple threads to wait for each other (barrier) before proceeding. The difference between CountDownLatch and CyclicBarrier is an also very popular multi-threading interview question in Java. CyclicBarrier is a natural requirement for a concurrent program because it can be used to perform the final part of the task once individual tasks are completed.

Thursday, July 27, 2017

How to Calculate Difference between two Dates in Java (In Days)

If you are not running on Java 8, then there are two ways to calculate the difference between two dates in Java in days, either by using standard JDK classes e.g. java.util.Date and java.util.Calendar or by using the joda-time library. Unfortunately, Java's old Date and Calendar API is buggy and not intuitive, so many of us by default use Joda for all date and time arithmetic. In this example, you will learn how to find  the number of days between today and any date entered by a user using Joda, as well as without using any third party library. When I first time face this problem, I thought what's a big deal about finding the difference between dates? If you can convert Date to milliseconds then finding a number of days, months or years are just a matter of simple arithmetic, but I was WRONG. I was not thinking about real world date and time nuisance like leap seconds, leap years, and daylight saving time.

Tuesday, July 25, 2017

When a class is loaded and initialized in JVM - Java

Understanding when a class is loaded and initialized in JVM is one of the fundamental concepts of Java programming language. Thanks to Java language specification we have everything clearly documented and explained, but many Java programmer still doesn't know when a class is loaded or when a class is initialized in Java. Classloading and initialization seems confusing and complex to many beginners and its true until having some experience in belt its not always easy to get into subtle details of How JVM works in Java. In this Java tutorial, we will see when class loading occurs in Java and when and how class and interface are initialized in Java.

java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver - Cause and Solution

java.sql.SQLException: No suitable driver found for 
There are two ways to connect Microsoft SQL Server from Java program, either by using Microsoft's official JDBC driver (sqljdbc4.jar) or by using jTDS driver (jtds.jar). This error comes when your supplied database URL didn't match with the JDBC driver present in the CLASSPATH. Many programmers who usually use jtds.jar, make a mistake while using sqljdbc4.jar by adding "microsoft" in JDBC URL. That makes URL invalid and JDBC API throws "java.sql.SQLException: No suitable driver: sqljdbc4.jar" error.

Monday, July 24, 2017

File Upload Example in Java using Servlet, JSP and Apache Commons FileUpload - Tutorial

Uploading Files to the server using Servlet and JSP is a common task in Java web application. Before coding your Servlet or JSP to handle file upload request, you need to know a little bit about File upload support in HTML and HTTP protocol. If you want your user to choose files from the file system and upload it to the server then you need to use <input type="file"/>. This will enable us to choose any file from the file system and upload to a server. Next thing is that the form method should be HTTP POST with enctype as multipart/form-data, which makes file data available in parts inside the request body. Now in order to read those file parts and create a File inside Servlet can be done by using ServletOutputStream.

Sunday, July 23, 2017

3 Ways to Read File line by line in Java 8? Examples

Java 8 has added a new method called lines() in Files class which can be used to read a file line by line in Java. The beauty of this method is that it reads all lines from a file as Stream of String, which is populated lazily as the stream is consumed. So, if you have a huge file and you only read the first 100 lines then the rest of the lines will not be loaded into memory, which results in better performance. This is slightly different from than Files.readAllLines() method (which reads all lines into a List) because this method reads the file lazily, only when a terminal operation is called on Stream e.g. forEach(), count(), etc. By using count() method you can actually count a number of lines in files or number of empty lines by filtering empty lines.

How to read file line by line in Java - BufferedReader Scanner Example Tutorial

Line by Line reading in Java using BufferedReader and Scanner
There are multiple ways to read file line by line in Java. Most simple example of reading file line by line is using BufferedReader which provides method readLine() for reading file. Apart from generics, enum and varargs Java 1.5  has also introduced several new class in Java API one of the utility class is Scanner, which can also be used to read any file line by line in Java. Though BufferedReader is available in Java from JDK 1.1,  java.util.Scanner provides more utility methods compared to BufferedReader. Scanner has method like hasNextLine() and nextLine() to facilitate line by line reading of file's contents. nextLine() returns String similar to  readLine() but the scanner has more utility methods like nextInt(), nextLong() which can be used to directly read numbers from a file instead of converting String to Integer or other Number classes.

Java ArrayList and HashMap Performance Improvement in JDK 7

For a long time, one reason for me to update to the newer Java version was always bug fix and performance improvement. Apart from major changes like Generics in Java 1.5 and Lambdas in Java 8, there are so many small improvements, performance optimization which just goes under the radar, one of such change is creating empty ArrayList and HashMap with size zero in JDK 1.7.0_40 update. Many Java developer doesn't even know about these changes, part of the blame lies on Java developers like me, as I hardly read release notes of minor Java updates. Some times these changes are done as part of bug fixes and other times as minor optimization, but given the popularity of ArrayList and HashMap in Java application impact of this simple Java optimization is huge.

How to Create Thread Pool in Java using Executor Framework - Example Tutorial

Java 1.5 introduced a Thread pool in Java in the form of an Executor framework, which allows Java programmers to decouple submission of a task to the execution of the task. If you are doing server-side programming in Java than the Thread pool is an important concept to maintain scalability, robustness, and stability of the system. For those, who are not familiar with thread pool in Java or concept of thread pool here is a one-liner, Thread pool in Java is a pool of worker threads, which is ready to perform any task given to them, mostly in the form of implementation of Runnable or Callable interface.

Saturday, July 22, 2017

Top 50 Java Programs from Coding Interviews

Coding is an integral part of any programming job interviews, and Java development interviews are no exception. I would even suggest you should never hire anyone without testing their coding skill, coding is also an art, and more often than a good code is an excellent developer as well. If you look at tech giants like Amazon, Facebook, and Google they thoroughly test the coding skill of any developer they hire, notably Amazon who first send online coding exercises to filter Java programmers who can code. This online test usually gives you requirements and ask you to write a program in a limited time, usually 2 to 3 hours. The application should meet the output provided by the exercise itself. These type of tasks are very tough to crack if you don't have excellent coding skill.

How to use Java 1. 7 Multiple Catch Block with example - JDK 7 tutorial

As the release of JDK 7 approaching General Availability (GA) on 2011/07/28, I thought to have a look on language enhancement as part of project coin, also called as Small language enhancements or JSR 334. Though there are not any major changes like Enum or Generics of Java 1.5,  but they are still very useful, in terms of simplifying your day to day programming task. Some of the interesting changes are allowing String in Switch cases, inclusion of fork-join framework in JDK itself , type inference using a diamond operator, automatic resource management using  try with resource feature, and ability to catch multiple Exception in the single catch block .

Arithmetic overflow error converting numeric to data type numeric in SQL Server

This error comes when you try to store an out-of-range floating point value into a numeric variable. For example, if your NUMERIC or DECIMAL variable is defined as NUMERIC(5,2) than the maximum value it can hold is 999.99, if you try to store something like 1000.00 then it will throw "Arithmetic overflow error converting numeric to data type numeric". One of the common reasons for this error is the ignorance and misunderstanding of the NUMERIC data type. For example, many SQL Server DBAs and developers think that a NUMERIC(5,2) variable can hold a 7 digit floating point number where 5 digit is before the decimal and 2 digits are after the decimal. This is wrong.

Friday, July 21, 2017

How to Read XML File as String in Java? 3 Examples

Suppose you have an XML file and you just want to read and display the whole file as String in Java, may be for debugging purpose. If you are wondering how to do that in Java, well there are many ways to read XML as String in Java. You can do it in one line if you are fine with using an open source library or you can do it in a couple of lines of code in core Java as well. Since an XML file is also a file, you can use BufferedReader or FileInputStream to read the content of an XML file as String by using the techniques, I have discussed in my earlier post 3 ways to convert InputStream to String in Java. But this post is about a new library called jcabi-xml which makes working with XML file really easy. You can parse the XML file using XPath expression, you can do XSL transformation, XSD schema validation and you can even parse whole XML file as String in just a couple of lines of code.

Difference between get and load in Hibernate

get vs load in Hibernate
Difference between get and load method in Hibernate is one of the most popular questions asked in Hibernate and spring interviews. Hibernate Session class provides two methods to access object e.g. session.get() and session.load() both looked quite similar to each other but there are subtle differences between load and get method which can affect the performance of the application. The main difference between get() vs load method is that get() involves database hit if an object doesn't exist in Session Cache and returns a fully initialized object which may involve several database calls while load method can return proxy in place and only initialize the object or hit the database if any method other than getId() is called on persistent or entity object.

Wednesday, July 19, 2017

How to convert String or char to ASCII values in Java

You can convert a character e.g. 'A' to its corresponding ASCII value 65 by just storing it into a numeric data type e.g. byte, int or long as shown below :

int asciiOfA = (int) 'A';

Here casting is not necessary, simply assigning a character to integer is enough to store ASCII value of character into an int variable, but casting improves readability. Since ASCII is 7-bit character encoding, you don't even need an integer variable to store ASCII values, byte data type in Java, which is 8 bits wide is enough to store ASCII value of any character.  So you can also do like this :
byte asciiOfB = 'B'; // assign 66 to variable

Tuesday, July 18, 2017

How to Configure HTTPS (SSL) in Tomcat 6 and 7 Java Web Server

Setting SSL (Secure Socket Layer) in Tomcat is often a requirement, especially while developing secure web applications, which requires access over https protocol. Since the Tomcat web server doesn't provide SSL settings by default, you need to know how to configure SSL in Tomcat, and even worse it varies between different tomcat versions. for Example SSL setup which works on tomcat 6, doesn't work as it is in tomcat 7. In this article we will see, how to configure tomcat for https in both tomcat 6 and 7. For those programmers who are not very familiar with SSL and https here is a quick overview of SSL, certificates and https, and I suggest reading that article to get a better understanding of How SSL works and How websites are accessed security over the internet.

What is Autoboxing and Unboxing in Java – Example Tutorial and Corner cases

What is Autoboxing in Java
Autoboxing and unboxing are introduced in Java 1.5 to automatically convert the primitive type into boxed primitive( Object or Wrapper class). autoboxing allows you to use primitive and object type interchangeably in Java in many places like an assignment, method invocation etc. If you have been using Collections like HashMap or ArrayList before Java 1.5 then you are familiar with the issues like you can not directly put primitives into Collections, instead, you first need to convert them into Object only then only you can put them into Collections. Wrapper class like Integer, Double and Boolean helps for converting primitive to Object but that clutter the code. With the introduction of autoboxing and unboxing in Java, this primitive to object conversion happens automatically by Java compiler which makes the code more readable.

Monday, July 17, 2017

9 Difference between TCP and UDP Protocol - Java Network Interview Question

TCP and UDP are two transport layer protocols, which are extensively used on the internet for transmitting data from one host to another. Good knowledge of how TCP and UDP works is essential for any programmer. That's why the difference between TCP and UDP is one of the most popular programming interview questions. I have seen this question many times on various Java interviews, especially for server-side Java developer positions. Since FIX (Financial Information Exchange) protocol is also a TCP based protocol, several investment banks, hedge funds, and exchange solution provider looks for Java developer with good knowledge of TCP and UDP. Writing fix engines and server side components for high-speed electronic trading platforms needs capable developers with a solid understanding of fundamentals including data structure, algorithms, and networking.

10 Things Every Java Programmer Should Know about String

String in Java is a very special class and most frequently used class as well. There are lot many things to learn about String in Java than any other class, and having a good knowledge of different String functionalities makes you use it properly. Given the heavy use of Java String in almost any kind of project, it becomes even more important to know subtle detail about String. Though I have shared a lot of String related articles already here in Javarevisited, this is an effort to bring some of the String features together. In this tutorial, we will see some important points about Java String, which is worth remembering. You can also refer my earlier post 10 advanced Java String questions to know more about String

Sunday, July 16, 2017

How to reload/refresh a page using JavaScript and jQuery

JavaScript provides several ways to reload or refresh an HTML page but the standard way to do this job is by using window.location object. This object provides a reload() method which instructs the browser to reload the page. The browser can do it from its cache or from the server, which depends upon optional parameter i.e. reload(true) will reload the page from the server but reload(false) will only reload the page from browser's cache, which may or may not represent the current version at the server.

Difference between ClassNotFoundException vs NoClassDefFoundError in Java

ClassNotFoundException vs NoClassDefFoundError
Though both of these errors are related to missing classes in the classpath, the main difference between them is their root cause. ClassNotFoundExcpetion comes when you try to load a class at runtime by using Class.forName() or loadClass() and requested class is not present in the classpath for example when you try to load MySQL or Oracle driver class and their JAR is not available, while in case of NoClassDefFoundError requested class was present at compile time but not available at runtime. Sometimes due to an exception during class initialization e.g. exception from static block causes NoClassDefFoundError when a failed-to-load class was later referenced by the runtime. 

Saturday, July 15, 2017

How to find duplicate words in Java String? [Solution]

Problem:  Write a Java program to print the duplicate words from a given statement e.g. if given String is "Java and JavaScript are totally different, JavaScript follows Java" then your program should print "Java" and "JavaScript" because those two are 2 duplicate words from given String. You need to consider all cases e.g. given String can be null, empty, may or may not contain any duplicate words, but for simplicity, you can assume that sentence will always in English and only use ASCII characters, alphabets, and numerals, no special character.

Difference Between Linked List and Array Data Structure in Java Programming

Array and linked lists are two fundamental data structures in the programming world. Almost all programs use Array in some form or other, which makes it increasingly important to learn array and linked list. The difference between the linked list and array data structure is also a popular data structure question, frequently asked in the various programming job interviews. This makes it even more important to learn and understand the difference between an array and a linked list. Well, there are a lot of differences between these two starting from how they store data, to how you retrieve data from them.

Is it possible to have an abstract method in a final class?

This is one of the interesting core Java questions which was asked to one of my readers recently during a telephonic interview for Java developer job interview. Even though he knows that you cannot make an abstract class final in Java, he got confused by the wording of the methods. The answer is simple, No, it's not possible to have an abstract method in a final class in Java. Why? because as soon as you declare an abstract method in a Java class, the class automatically becomes an abstract class and you cannot make an abstract class final in Java as discussed before, hence it's not possible to have an abstract method in a final class in Java.

Friday, July 14, 2017

How to Find Largest of Three Integers in Java - Algorithm, Logic Example

One of the classical programs to build programming logic is, write a program to find the largest of three numbers. I am sure many of you have already done this exercise in a variety of languages including C, C++, C#, JavaScript, Perl, Ruby, PHP, etc. This time we will do it in Java. We will first learn the logic by understanding the flowchart of the largest of three numbers and then we will implement solution using the ternary operator in Java. I love this program for its sheer simplicity and how it can help beginners to build logic. As always, you are not allowed to use any library function which can solve this problem directly, your main task is to build logic using primitive language tools e.g. operators.

Thursday, July 13, 2017

Why Enum Singleton are better in Java

Enum Singletons are new way to implement Singleton pattern in Java by using Enum with just one instance. Though Singleton pattern in Java exists from long time Enum Singletons are relatively new concept and in practice from Java 5 onwards after introduction of Enum as keyword and feature. This article is somewhat related to my earlier post on Singleton, 10 interview questions on Singleton pattern in Java where we have discussed common questions asked on interviews about Singleton pattern and 10 Java enum examples, where we have seen how versatile enum can be. This post is about why should we use Enum as Singleton in Java, What benefit it offers compared to conventional singleton methods etc.

Why multiple inheritances are not supported in Java

Why multiple inheritence is not supported implemented in javaRecently one of my friend appeared for an interview and after few so called easy questions he was asked "Why multiple inheritance is not supported in Java" , though he has a brief idea that in Java we can support multiple inheritance in java via interface but interviewer was keep pressing on why part , may be he was just read any blog post about it :). So after the interview my friend comes to me and in usual talk he told me about this questions and ask me the answer. Well this is very classical question like Why String is immutable in Java; similarity between these two questions is they are mainly driven by design decision taken by java's creator or designer. Though following two reason make sense to me on Why Java doesn't support multiple inheritances:

How to do GROUP BY in Java 8? Collectors.groupingBy() Example

Java 8 now directly allows you to do GROUP BY in Java by using Collectors.groupingBy() method. GROUP BY is a very useful aggregate operation from SQL. It allows you to group records on certain criteria. How do you group by in Java? For example, suppose you have a list of Persons, How do you group persons by their city like. London, Paris, or Tokyo? Well, we can do that by using a for loop, checking each person and putting them on a list of HashMap with the same city, but in Java 8, you don't need to hack your way like that, you have a much cleaner solution. You can use Stream and Collector which provides groupingBy() method to do this.

Tuesday, July 11, 2017

How to solve java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver in Java 8

java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver exception comes in Java 8 because it has removed the JDBC ODBC bridge driver class "sun.jdbc.odbc.jdbcodbcdriver" from JDK and JRE. This class is required to connect any database using Object database connectivity driver e.g. Microsoft Access, but unfortunately, you cannot use it from JDK 8 onward. In order to solve this error, just use the Jackcess library or a commercial driver like HXTT. Normally, in pre-Java 8 world, java.lang.classnotfoundexception sun.jdbc.odbc.jdbcodbcdriver error comes when you try to connect to the Microsoft Access database from Java using JDBC and JDBC ODBC bridge driver is not available in the classpath.

Monday, July 10, 2017

Write a Program to Find all Armstrong number in the range of 0 and 9999 - Example

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number, since 1**3 + 5**3 + 3**3 = 153, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. Along with usual beginner exercises e.g. calculating factorial, reversing a string, or calculating prime numbers, this is a good exercise to build programming logic. It teaches you basic programming technique of how to use the operator for something which is not obvious, for example, to solve this programming challenge, we first need to check if a number is Armstrong or not, and to do this we need individual digits of the number. how do we do that? well, there is a programming technique, which you might have learned while doing number palindrome exercise.

Top 16 Java ArrayList Tutorials and Examples for Beginners - Best of Lot

Most of the Java interview questions on ArrayList asked to freshers or Java developers with 1 to 2 years experience is just simply how to do task e.g. how to sort arraylist, how to serach element, how to remove an element using iterator etc. Since, I have written lots of Java tutorials on ArrayList, covering many general purpose tasks e.g. how to create an object of ArrayList and initialize to how to sort ArrayList in ascending and descending order etc. On request of my readers, I am creating this mega list of ArrayList tutorials, which will help you to learn everything about ArrayList class. These tutorials are great for beginners and even experienced Java developers can learn a trick or two.

When to Make a Method Static in Java

Making a method static in Java is an important decision . Though, static keyword is one of the fundamental concepts, many times programmers gets confused to make a particular method static or not. In Java programming, main motivation for making a method static is convenience. You can call a static method without creating any object, just by using it's class name. So if you need a method, which you want to call directly by class name, make that method static. Utility classes e.g. java.lang.Math or StringUtils, are good examples of classes, which uses static methods. Before making a method static, you should look into limitation of static methods as well, as you can not override static method in Java

Sunday, July 9, 2017

String vs StringBuffer vs StringBuilder in Java

Difference between String, StringBuffer, and StringBuilder
The String is one of the most important classes in Java and anyone who starts with Java programming uses String to print something on the console by using famous System.out.println() statements. Many Java beginners not aware that String is immutable and final in Java and every modification in String creates a new String object. For example, when you get the substring, you get a new String, when you convert uppercase String to lowercase, a new String is created. Even when you remove space by calling the trim() method, a new String is returned. So, now the big question is how do you manipulate String in Java without creating String garbage? StringBuilder and StringBuffer are the answer to this question. StringBuffer is old class but StringBuilder is newly added in Java 5 along with major improvements in Enum, Generics, varargs methods and Autoboxing in Java.

Strategy Design Pattern and Open Closed Principle in Java - Example

Strategy design pattern is based upon open closed design principle, the 'O' of famous SOLID design principles. It's one of the popular pattern in the field of object-oriented analysis and design along with Decorator, Observer and Factory patterns. Strategy pattern allows you to encapsulate possible changes in a process and encapsulate that in a Strategy class. By doing that your process (mainly a method) depends upon a strategy, higher level of abstraction than implementation. This makes your process open for extension by providing new Strategy implementation, but closed for modification, because the introduction of a new strategy doesn't require a change in a tested method. That's how it confirms open closed design principle.

Saturday, July 8, 2017

OCAJP 8 FAQ - Oracle Certified Associate Java Programmer I Certification (1Z0–808) Frequently asked Questions

The Oracle Certifications is one of the most repeated, industry-recognized certifications. It also provides Java certifications like Oracle Certified Associate Java Programmer, also known as OCAJP and Oracle Certified Professional Java Programmer, also known as OCPJP. These two are most popular Java certification and there are many benefits of passing them e.g. better chance to get a Java development job, improved performance on Java interviews, better salary rise, and promotions, and better opportunity for moving abroad.

Friday, July 7, 2017

SubQuery Example in SQL – Correlated vs Noncorrelated

SubQuery in SQL is a query inside another query. Some time to get particular information from a database you may need to fire two separate SQL queries, subQuery is a way to combine or join them in a single query. SQL query which is on the inner part of the main query is called inner query while the outer part of the main query is called outer query. for example in below SQL query

SELECT name FROM City WHERE pincode IN (SELECT pincode FROM pin WHERE zone='west')

section not highlighted is OUTER query while section highlighted with grey is INNER query.

Thursday, July 6, 2017

10 Tips to Debug Java Program in Eclipse

How to debug a java program in Eclipse

Debugging is a must-have skill for any java developer. Having the ability to debug java program enables to find you any subtle bug which is not visible during code review or comes when a particular condition offer, This becomes even more important if you are working in high-frequency trading or electronic trading system project where time to fix a bug is very less and bug usually comes on the production environment and doesn't appear in your Windows XP machine. in my experience debugging java application also helps you understand the flow of java program.

Fibonacci Series in Java Without Recursion - Programming Exercises for Beginners

Fibonacci series is a great example of Recursion and how the use of recursion can result in a clear and concise solution. That's why whenever asked about writing a Java program to get Fibonacci numbers or print the Fibonacci series of certain numbers, it's quite natural for programmers to resort to recursion. The interviewer often challenged this practice by asking candidates to implement Fibonacci series without using recursion. Yes, you read it right, you can't use recursion and this is what you will learn in this article. If you have attended your programming classes regularly then you may know that many recursive algorithms also has their iterative counterpart which uses loops instead of recursion or calling itself . We will take advantage of that concept to devise a solution of this problem.

Wednesday, July 5, 2017

java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [Solution]

This error comes when you try to connect to the Microsoft SQL Server database from Java program but the required JDBC driver is not available in Classpath or driver is available in CLASSPATH but the class loader is not able to find it due to classpath intricacies. Depending upon your situation, a solution could be as simple as downloading any of sqljdbc.jar, sqljdbc4.jar or sqljdbc41.jar, based upon the Java version you are using and adding them into CLASSPATH as set CLASSPATH = %CLASSPATH%; (path to Microsoft JDBC driver) in Windows. BTW, in most of the cases "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" comes because of classpath intricacies.

Tuesday, July 4, 2017

How SSL, HTTPS and Certificates Works in Java web Applications

Basic knowledge of SSL, HTTPS, and Certificates is a must for any Java programmer, especially who is working in financial and security-sensitive applications, which are accessed over the internet. In this article, I am giving you an overview of these three key concepts and How SSL, HTTPS and certificates work together, to provide secure communication between client and server. Security is major concern while developing web applications, which is accessible using HTTP protocol. Since HTTP protocol transfer data in plain text format, its not safe for transferring sensitive information like username, password, social security number (SSN) or credit card details for online shopping.

Monday, July 3, 2017

How to Convert Fahrenheit to Celsius in Java with Example

In this Java tutorial, you will learn how to write a program to convert Fahrenheit to Celsius in Java. Fahrenheit is a thermodynamic temperature scale, where the freezing point of water is 32 degrees Fahrenheit (°F) and the boiling point of water is 212°F (at standard atmospheric pressure). This puts the boiling and freezing points of water exactly 180 degrees apart. Therefore, a degree on the Fahrenheit scale is 1/180 of the interval between the freezing point and the boiling point of water. Absolute zero is defined as -459.67°F. If you know, in the Celsius scale, the freezing point of water is at 0ºC and the boiling point of water is at 100ºC. By using these facts, you can easily deduce a formula to convert Fahrenheit temperature into Celsius.

Sunday, July 2, 2017

Role based Access control using Spring Security and MVC, Mapping LDAP Groups to Authorities for Authorization

Authentication and Authorization is an integral part of any Java enterprise or web application. Since most of the company uses LDAP Active directory for authentication, authorization and Role-based access control (RBAC), it's good to know How to implement Role-based access control using Spring MVC and Spring Security. This is the second part of my articles on using Spring Security for authentication and authorization in Spring MVC based Java application. In the last part, we have learned about doing LDAP authentication against Windows active directory, and in this Spring Security tutorial, we will learn How to map LDAP groups to authorities for implementing Role-based access control or authorization.

How to solve java.lang.UnsatisfiedLinkError: no ocijdbc11 in Java

"java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path" error comes when you try to connect to Oracle 11g database using OCI (thick) driver by using tns name, but the ocijdbc11.dll file is not available in PATH or java.library.path environment variable. ocijdbc11.dll is a native library and if you know Java searches native library in PATH or a location specified by java.library.path system property, if it doesn't find the dll, then it throws java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path error. This dll is usually found in C:\Programs\Oracle\ora11g\bin\ocijdbc11.dll, but it could vary depending upon your Oracle installation.

Top 30 Linked List Algorithm Questions from Programming/Coding Interviews

The linked list is one of the most common and essential data structure and that's why you would frequently find linked list based coding questions on interviews. The range of questions can be from simple questions like finding the length of a linked list to very difficult e.g. merging two sorted linked lists. Nevertheless, the point is that you should be familiar with linked list data structure and must know how to perform basics task in the linked list e.g. adding or removing nodes from a linked list, traversing order linked list and implementing linked list in your choice of programming language e.g. Java, C++, C, or Python.

Saturday, July 1, 2017

How to resolve java.lang.UnsupportedClassVersionError with example

The java.lang.UnsupportedClassVersionError  is a quite common error after NoClassDefFoundError or ClassNotFoundException they all seems to related to class files but they all are different and there cause and resolution are different. In this java tutorial, we will see what is UnsupportedClassVersionError in Java? Why UnsupportedClassVersionError comes in Java? What are a class file format and version numbers associated with it and finally how to resolve UnsupportedClassVersionError in Java? 

How to use wait, notify and notifyAll in Java - Producer Consumer Example

You can use wait, notify, and notifyAll methods to communicate between threads in Java. For example, if you have two threads running in your program e.g.Producer and Consumer then producer thread can communicate to the consumer that it can start consuming now because there are items to consume in the queue. Similarly, a consumer thread can tell the producer that it can also start putting items now because there is some space in the queue, which is created as a result of consumption. A thread can use the wait() method to pause and do nothing depending upon some condition. For example, in the producer-consumer problem, producer thread should wait if the queue is full and consumer thread should wait if the queue is empty.