2nd highest salary in Oracle using ROW_NUMBER and RANK in Oracle and MSSQL

This is the second article about calculating the 2nd highest salary in SQL. In the first part, you have learned how to find the second highest salary in MySQL, SQL SERVER and by using ANSI SQL, which should also work in all database which confirms ANSI standard e.g. PostgreSQL, SQLLite, etc. In this part, I will show you how to find the 2nd maximum salary in Oracle and SQL SERVER using ROW_NUMBER(), RANK(), and DENSE_RANK() method. These are window function in Oracle, which can be used to assign unique row id, or rank to each row based on any column and then select the right row.

How to Find Missing Number on Integer Array of 1 to 100 - BitSet Example

One of the most frequently asked questions on programming interviews is, write a program to find the missing number in an array in Java, C# or any other language; depending upon which language you choose. This kind of coding interview questions are not only asked in small start-ups but also on some of the biggest technology companies like Google, Amazon, Facebook, Microsoft, mostly when they visit the campus of reputed universities to hire graduates. The simplest version of this question is to find missing elements in an area of 100 integers, which contains numbers between 1 and 100. This can easily be solved by calculating the sum of the series using n(n+1)/2, and this is also one of the quickest and efficient ways, but it cannot be used if the array contains more than one missing number or if the array contains duplicates.

Difference between static vs non static method in Java

In this article, we will take a look at the difference between static and non-static method in Java, one of the frequently asked doubt from Java beginner. In fact, understanding static keyword itself is one of the main programming fundamental, thankfully it's well defined in Java programming language . A static method in Java belongs to class, which means you can call that method by using class name e.g. Arrays.equals(), you don't need to create any object to access this method, which is what you need to do to access non-static method of a class. Static method is treated differently by compiler and JVM than non-static methods, static methods are bonded during compile time, as opposed to binding of the non static method, which happens at runtime.

Database Transaction Tutorial in SQL with Example for Beginners

A database transaction is an important concept to understand while working in database and SQL. Transaction in the database is required to protect data and keep it consistent when multiple users access the database at the same time.  In this database transaction tutorial we will learn what is a transaction in a database, why do you need transaction in the database, ACID properties of database transaction and an example of database transaction along with commit and rollback.   Almost all vendors like Oracle, MySQL, SQL Server or Sybase provide transaction facility but MySQL only provide it for certain storage engines like InnoDB and BDB and not for MyISAM.

Great Example of Open Closed Design Principle in Java

Great Example of Open Closed Design Principle
I am big fan of design pattern article and love to read articles on design patterns and recently wrote about decorator design pattern in JavaObserver patternstatic factory pattern and about Singleton pattern. Today I come across this good article on open closed design pattern, what I like most is there example and clear way of explanation, first example is true value and it will help you understand open closed principle very quickly and second example is also not bad.

Top 10 Struts Interview Question And Answer - J2EE

This time its Struts interview questions, After writing Spring interview questions few weeks back I was thinking what to pick for my interview series and then I thought about any web framework, and on that struts is my favorite. Struts are open source framework used for web application. These Struts interview questions are based on my experience as well as collected by friends and colleague and they are not only good for interview practice but also shows a new direction of learning for anyone who is not very familiar with struts. The best way to use these interview questions does revise before going for any Struts interview or any Java or J2EE interview.

How to join three tables in SQL query – MySQL Example

Three table JOIN Example SQL
Joining three tables in single SQL query can be very tricky if you are not good with the concept of SQL Join. SQL Joins have always been tricky not only for new programmers but for many others,  who are in programming and SQL for more than 2 to 3 years. There are enough to confuse someone on SQL JOIN ranging from various types of SQL JOIN like INNER and OUTER join, LEFT and RIGHT outer join, CROSS join etc. Between all of these fundamentals, What is most important about Join is, combining multiple tables. If you need data from multiple tables in one SELECT query you need to use either subquery or JOIN. Most of the times we only join two tables like Employee and Department but sometimes you may require joining more than two tables and a popular case is joining three tables in SQL.

Difference between char, varchar, nchar and nvarchar data type in SQL Server database

What is the difference between char and varchar in SQL, followed by nchar and nvarchar, is one of the popular SQL interview questions, and surprisingly not every programmer knows this basic difference. If you go with the name, which you should, then you can figure out that char is a fixed-length data type while varchar should be variable length data type. Though all char, varchar, nchar, and nvarchar are used to store text or String data there are subtle differences between them. As I said char is fixed length, which means a variable or a column e.g. Zipcode char(10) will take only 10 bytes to store data, including space.

Scala vs Java - Differences and Similarities

Scala is new generation JVM language, which is generating popularity as an alternative of arguably one of the most popular language Java. It's not yet as popular as Java, but slowly getting momentum. As more and more Java developers are learning Scala and inspired by Twitter, more and more companies are using Scala, it's future looks very bright. To start with, Scala has several good feature, which differentiate it from Java, but same time it has lot of similarities as well e.g. both Scala and Java are JVM based language, You can code Scala in Java way and Scala can use any Java library, which in my opinion a great decision made by designers of Scala.

Top 25 Java Collection Framework Interview Questions Answers for Freshers and Experienced Programmers

Interview questions from Collection package or framework are most common in any Core Java Interview yet a tricky one. Together Collection and multithreading make any Java interview tough to crack and having a good understanding of Collection and threads will help you to excel in Java interview. I thought about writing interview questions on Java collection framework and important classes like ArrayList, HashMap, Hashtable, and newly added concurrent collections e.g. ConcurrentHashMap when I first wrote 10 multi-threading Interview questions  but somehow this article got delayed. Though I have shared several questions individually in between.

Decorator design Pattern in Java with Example Java Tutorial

I was thinking to write on decorator design pattern in Java when I first wrote 10 interview questions on Singleton Pattern in Java. Since design pattern is quite important while building software and it’s equally important on any Core Java Interview, It’s always good to have clear understanding of various design patterns in Java. In this article we will explore and learn Decorator Design pattern in Java which is a prominent core Java design pattern and you can see lot of its example in JDK itself. JDK use decorator pattern in IO package where it has decorated Reader and Writer Classes for various scenario, for example BufferedReader and BufferedWriter are example of decorator design pattern in Java.

Java Array Tutorial and Example for Beginners

The array is one of the most important data structures in any programming language, at the same time different programming languages implement and treat array differently. Anyone who is done some programming knows value of array and importance of knowing about array type, using them in their program. Together with a linked list, array forms a set of basic data structures. Though Java offers excellent Collection API and some of the collection classes like ArrayList and  HashMap, they are internally based on the array. If you are coming from C or C++ background then you will find some difference about how array behaves there and how it does in Java, a most notable difference between array in C and array in Java is bounds checking. 

How to Make and Run batch .bat file in Windows 8

batch files and shell scripts are developers best friend, they help to improve productivity a lot. They not only help you to automate boring, time consuming task but also saves lot of time doing and doing them again. Batch file also reduce chances of error, once tested and encourage re-usability by sharing them across team or people with similar needs. Though not every programmer, developer or computer user has mindset to use batch file, something it's too difficult to write, some just not able to fight with initial resistance and many of them are not even aware of batch file.

Difference between jQuery Document Ready Method and JavaScript Window Onload Event

Though both jQuery ready event and window onload event is used to perform task when page is loaded, there is a subtle difference between them. jQuery document.ready method, which is not method but a jQuery event is fired, when DOM is ready i.e. all elements of DOM is available, but not necessarily all contents e.g. images and video, on the other hand, JavaScript built-in window.onload event is fired when the HTML document is completely loaded, including DOM and all it's content e.g. images, audio and videos.

Helloworld Example Java : How to run Java Program from command prompt

This article contains HelloWorld Example in Java and step by step guide to run Java program from command prompt. Beginners who just started to learn Java or using Java often struggled and doesn't know how to run a Java program from command prompt. Running a Java program is simple but setting up Java environment is rather cumbersome especially if you are new in Programming world and not very familiar with words like PATH, CLASSPATH or even command prompt.

Difference between TreeSet, LinkedHashSet and HashSet in Java with Example

TreeSet, LinkedHashSet and HashSet all are implementation of Set interface and by virtue of that, they follows contract of Set interface i.e. they do not allow duplicate elements. Despite being from same type hierarchy,  there are lot of difference between them; which is important to understand, so that you can choose most appropriate Set implementation based upon your requirement. By the way difference between TreeSet and HashSet or LinkedHashSet is also one of the popular Java Collection interview question, not as popular as Hashtable vs HashMap or ArrayList vs Vector but still appears in various Java interviews.

What is Static Variable Class method and keyword in Java - Example Tutorial

What is Static in Java
Static in Java is an important keyword and used to create static method, static class and static variable in Java. Correct understanding of static keyword is required to understand and write sophisticated Java programs. Java 5 also introduced static imports along with Autoboxing, Generics, Enum and varargs method, which allows to import static members of one class or package into another using import keyword and then using them like they are member of that class. In this Java tutorial we will learn about What is is static in Java, What does it mean to be a static field, static class or method in Java and various points and issues involved around How to use static members in Java.

Difference between final, finally and finalize method in Java

What is the difference between final, finally and finalize method is asked to my friend in a Java interview with one of the US-based Investment bank. Though it was just a telephonic round interview, he was asked a couple of good questions e.g. how to avoid deadlock in Java, How to get() method of HashMap works and one of the puzzles which are based on recursion. In short final keyword can be used along with variable, method and class and has a different meaning for all of them. finally is another Java keyword which is used in Exception handling along with try, catch, throw and throws. finalize() is a special method in Java which is called by Garbage Collector before reclaiming GC eligible objects.

5 Free OCAJP8, OCPJP8 Mock Exams and Practice questions - 1Z0-808 809 (Java 8 Certification)

In order to do well on Java certifications, you need good books and a reasonable number of practice questions before you go for exams. Practice questions and mock exams will help you to assess your topic-wise preparation level and help you to identify your strong and weak areas. Based on the result of the mock exams, you can concentrate on areas where you lack expertise e.g. multi-threading is one of the tricky areas. It will also expose you to exam patterns and different types of questions you can expect in examination e.g. multiple choice questions, rearranging code, fill in the blanks etc. Though I highly recommend commercial exam simulators like Whizlabs and Enthuware, I also suggest you take advantage of many mock questions which are freely available.

4 Ways to Search Java Array to Find an Element or Object - Tutorial Example

Searching in Java Array sounds familiar? should be,  because it's one of the frequently used operations in Java programming. The array is an index based data structure that is used to store elements but unlike Collection classes like ArrayList or HashSet which has contains() method, array in Java doesn't have any method to check whether an element is inside an array or not. Java programming language provides several ways to search any element in Java array. In this Java tutorial, we will see 4 examples of searching Array in Java for an element or object.  Every example is different than other and some of them are faster and others are slow but take less memory.

Why use @Override annotation in Java - Coding Best Practice

@Override annotation was added in JDK 1.5 and it is used to instruct compiler that method annotated with @Override is an overridden method from super class or interface. Though it may look trivial @Override is particularly useful while overriding methods which accept Object as parameter just like equals, compareTo or compare() method of Comparator  interface. @Override is one of the three built in annotation provided by Java 1.5, other two are @SuppressWarnings and @Deprecated. Out of these three @Override is most used because of its general nature, while @SuppressWarnings is also used while using Generics, @Deprecated is mostly for API and library.

How to override compareTo method in Java - Example Tutorial

compareTo in Java is in the same league of equals() and hashcode() and used to implement natural order of object, compareTo is slightly different to compare() method of Comparator interface which is used to implement custom sorting order. I have seen during java interviews that many Java programmers not able to correctly write or implement equals(), hashCode() and compareTo() method for common business objects like Order or Employee. Simple reason behind this is that they either not understand the concept well enough or doesn't write this stuff at all.