HTML

Top 50 JavaScript Interview Questions for Programmers and Web Developers

Hello guys, you may know that JavaScript is one of the most popular programming languages, having ranking #1 for a couple of years in the StackOverflow survey. There is no doubt that JavaScript is the most popular language or web development. The best thing is that you can use JavaScript to develop both frontend and backend using the same programming language and tech stack. You have so many popular frameworks like React.js, Angular, Node.js, Vue.js to implement sophisticated web applications for different domains. That's why the demand for JavaScript developers is very high, especially full-stack JavaScript developers who can create both frontend and backend of application on their own.

Java Program to find Armstrong numbers with Example

Armstrong number Example in Java
How to check if a number is Armstrong number or not? or write a Java program to find Armstrong's number? This is a common Java interview question asked on-campus interviews and fresher level interviews. This is also a popular Java programming exercise on various schools, colleges and computer courses to build programming logic among Students. An Armstrong number is a 3 digit number for which the sum of cube of its digits is equal to the number itself. One of the popular examples of the Armstrong number is 153 as 153= 1+ 125+27 which is equal to 1^3+5^3+3^3 which is equal to the sum of cube of its digits 1, 5, and 3

Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core” - Cause and Solution

This error comes in when you are trying to use the JSTL core tag library in your JSP page but web container is not able to locate corresponding TLD files, also known as tag library descriptor. In order to use the custom tags in the JSP page, the first step is to import them using @taglib directive and for that purpose, we provide a URI. Many JSP developer thinks this is the location where TLD files are stored but that's not true, this is actually the value, custom tab library developer has put in the URL field of tag library descriptor. This misunderstanding causes lots of trouble while solving "Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”.

Bubble sort in Java - Program to sort an Integer Array

Bubble sort is one of the classic sorting algorithms,s which is used to explain sorting during various computer and engineering courses. Because of its algorithmic nature and simplicity, it's often used in various Java and C++ programming exercises. You may expect questions like Write Java program to sort integer array using bubble sort during any programming interview. Since algorithmic questions are always a tricky question and not easy to code. Even the simplest of them can lead to confusion, especially if you are not gifted with a natural programming head. I have seen many developers fumble if asked to code on the spot. That's why it's advisable to do algorithmic and logical programming during training and learning programming and OOPS to get this skill of converting logic into code.

How to Run Command Line, External Program and Batch files from Eclipse Console - Tips

Hello guys, have you ever think how much time a Java developer spends on Eclipse or his favorite IDE? I guess most of his time, isn't it would be great to do as much as work possible from Eclipse itself, without switching to another application. Since switching between application or program requires some time, which is generally gone waste, I like to use Eclipse as much as possible, starting from coding in Java, executing Java program to exploring XML files, and now even running the batch command from Eclipse. Most of you know about Eclipse's external tool configuration feature, which allows you to run any external program like a batch file from local drive, but it can also be used to run command prompt from Eclipse console itself.

JFileChooser Example - Show Open Save File Dialog in Java Swing Application

Hello guys, if you worked in Java GUI based application then you may know that Swing provides class javax.swing.JFileChooser that can be used to present a dialog for the user to choose a location and type a file name to be saved, using the showSaveDialog() method. Syntax of this method is as follows:

        public int showSaveDialog(Component parent)

where the parent is the parent component of the dialog, such as a JFrame.

How to Check is given String is a Palindrome in Java using Recursion

In this tutorial, you will learn how to check if a string is a palindrome in Java using Recursion. A String is nothing but a collection of characters like "Java," and String literals are encoded in double-quotes in Java. A String is said to be a palindrome if the reverse of String is equal to itself like "aba" is a palindrome because the opposite of "aba" is also "aba", but "abc" is not a palindrome because the reverse of "abc" is "cba" which is not equal. Recursion means solving a problem by writing a function which calls itself. In order to check if String is a palindrome in Java, we need a function that can reverse the String.

Dealing with java.net.SocketException: Broken pipe in Java - Cause and Solution

Hello guys, If you have worked in a client-server Java application then you may be familiar with the  "java.net.SocketException: Broken pipe" error, It is one of the many socket related error you will see on server-side application log.  This error comes intermittently when many clients are connecting to a server and many clients closing the connection before a response is fully transferred. Some of the common causes of java.net.SocketException: Broken pipe exception includes
  • The user closed the browser before the page loaded.
  • Their internet connection failed during loading.
  • They went to another page before the page loaded.
  • The browser timed the connection out before the page loaded (would have to be a large page).

java.lang.VerifyError: Expecting a stack map frame at branch target 14 in method at offset JDK 7 [Solved]

Hello guys, today, we'll take a look at the not so common error for Java application. If you have been working in Java for a couple of years then you might have seen this dreaded "java.lang.VerifyError: Expecting a stack map frame at branch target 14 in method at offset JDK 7" error in your application log or in Eclipse, particularly if you are running your Java application in Java 7. The main cause of this error, "java.lang.VerifyError: Expecting a stack map frame at branch target ... in the method ... at offset 0 error comes when you have some library, JAR file which is only compatible with Java 1.6 or below and you are running your program in JDK 1.7.

How to get current URL, Path, and hash using jQuery - Example, Tutorial

Hello guys,  in the last jQuery tutorial, I have taught you how to set and get values from a text field using jQuery and in this jQuery tutorial, you will learn about how to get the current URL and hash values, like something which starts with # (hash) letter. For example, in the URL http://localhost:8080/HelloWeb/test.html#ixzz2PGmDFlPd, URL is http://localhost:8080/HelloWeb/test.html and the hash value is ixzz2PGmDFlPd. This is important information and you will often find needing hash values from the current URL while working on a web application.

How to find largest and smallest number from integer array - Java Solution

Hello guys, if you have gone through any coding interview or have done some professional Software development then you know that a good understanding of array data structure is crucial for any software developer but it doesn't come for free, you need to spend time and effort. The best way to develop this understanding by solving coding problems and there are lots of programming exercises beginners can do. One of them is writing a program to find the smallest and largest number in an integer array. Java programmers are no different than others, so they can do this program in Java, not just to understand array but also different relational operators available in Java.  

How to Check if Given Number is Prime in Java - With Example

Hello guys, today, we are going to discuss one of the most common programming exercises for beginners is, write a program to check if a given number is prime or not? There are many ways to check if a number is prime or not, but the most common of them is the trial division, which is what we will see in this tutorial. In my opinion, these kinds of programs are their first steps towards algorithmic understanding. You first come up with a solution, which is driven by the fact that prime numbers are natural numbers, that are not divisible by any positive number other than 1 and themselves. Then, you write a for loop to check every number, starting from 1 to a given number, to see if the given number is divisible by any positive number or not. This leads you to the solution.

How to send Logging Messages to SysLog using Log4j2 SysLogAppender in Linux - Java

Sometimes you may want to route your log messages to Syslog in UNIX based environment e.g. Linux. Since logger allows multiple appenders, you can print the same log messages to log file, console and route it to Syslog at the same time. In order to send log messages to Syslog using log4j2, you need to make some changes in your log4j2.xml file. This change is to include Syslog appender and configure that, once you do that you also need to enable TCP or UDP reception by editing rsyslog.conf file. For faster transmission you can choose UDP protocol and configure a port number on which your Syslog is listening, In our example, Syslog is listening on port 618. Let's see the complete step by step guide to configure Syslog logging in log4j logger.

How to Convert Date to LocalDate in Java 8 - Example Tutorial

Hello guys, you may know that JDK 8 introduced the new Date and Time API, which has got a new set of shiny date classes like LocalDate, LocalTime, etc, but you still have a lot of code written against java.util.Date? In order to work with that code, you should know how to convert java.util.Date to java.util.LocalDate in Java. There are actually multiple ways to do this conversion. You can use java.sql.Date class here as well, becuase it provides direct conversion methods like the toLocalDate() and the toInstant(). Equivalent class of the java.util.Date in Java 8 is Instant.

How to recursive copy directory in Java with sub-directories and files

Hello guys, it's a common requirement in Java to copy a whole directory with sub-directories and files but it's not that straight forward, especially not until Java 7. JDK 7 introduced some new file utility methods as part of Java NIO 2 which we will use in this article to show you how to recursively copy a whole directory with sub-directories and files in Java. I'll also show you how you can use Apache Commons if you are not running on Java 7 or higher versions. Basically, You can copy a file or directory by using the copy(Path, Path, CopyOption...) method. The copy fails if the target file exists unless the REPLACE_EXISTING option is specified.

How to Check if given Array contains a value in Java - Linear Search vs Binary Search

Hello guys, one of the common coding questions from Java interviews is how to test if an Array contains a certain value or not? This is a simple question, but sometimes interview pressure makes candidates nervous. In this article, you'll learn how to solve this problem using different approaches. Since an array in Java doesn't have any inbuilt method for searching values, interviewers prefer to ask this question, to see how a candidate deals with such a situation. If you have good knowledge of Java API, then you will immediately come to know that there are alternatives available like using the binarySearch() method of Java Java .util.Arrays class or taking advantage of ArrayList contains method by first converting your array to ArrayList.

How to find GCD of two numbers in Java - Euclid's algorithm

How to find Greatest Common Divisor of two numbers in Java
Simple Java program to find GCD (Greatest Common Divisor) or GCF  (Greatest Common Factor) or HCF (Highest common factor). The GCD of two numbers is the largest positive integer that divides both the numbers fully i.e. without any remainder. There are multiple methods to find GCD, GDF or HCF of two numbers but  Euclid's algorithm is very popular and easy to understand, of course, only if you understand how recursion works. Euclid's algorithm is an efficient way to find GCD of two numbers and it's pretty easy to implement using recursion in Java program. According to Euclid's method GCD of two numbers, a, b is equal to GCD(b, a mod b) and GCD(a, 0) = a.

Top 5 Scala and Functional Programming Books and Courses - Must read, Best of Lot

Hello guys, if you are a Java developer who is interested in learning Scala or someone starting with Scala afresh and looking for some awesome Scala resources like books, courses, and tutorials then you have come to the right place. In the past, I have shared some free Scala courses to start with and today, I will share some of the best books to learn Scala and Functional Programming, particularly Java developers. While in this age of online courses, fewer and fewer people are using books to learn a new technology or skill but in my opinion, both books and courses have different purposes. I have taken many online courses and read even more books so I can tell that books are almost always more in-depth and provide comprehensive coverage than courses.

How to check if a File exists in Java with Example

Hello guys,  if you are working in Java for a couple of years then you have come across a scenario where you need to check if a file exists or not. This is often required while writing defensive code that writes or read from a file. While there is a method to check if a file exists in Java or not, it's not so straight forward to use because it returns true if a given path represents a file or a directory. Yes, I am talking about the File.exists() method of java.io package. This method is the key method to solve this problem but you need to keep in mind that it returns true if a given path exists and its either file or directory. If your requirement is not just to check if the path is valid but also it represents a file and you have permission to read the file then you also need to ensure that it's not a directory.

How to Find Duplicate Characters on String - Java Programming Problems

Hello guys, today's programming exercise is to write a program to find repeated characters in a String. For example, if given input to your program is "Java", it should print all duplicates characters, i.e. characters appear more than once in String and their count like a = 2 because of character 'a' has appeared twice in String "Java". This is also a very popular coding question on the various level of Java interviews and written tests, where you need to write code. On difficulty level, this question is at par with the prime numbers or Fibonacci series, which are also very popular on junior level Java programming interviews and it's expected from every programmer to know how to solve them.

Difference between private and final in Java?

Hello guys, one of the common questions among Java beginners is what is the difference between a private and final keyword in Java? The confusion arises because they are very similar and used in a similar context. For example, you can make a class, method, and variable final as well as private. Both put some kind of restriction like you cannot override a final method in Java and the private method is not even accessible outside the class, so obviously you cannot override it. The main difference between private and final keyword in Java is that private is primarily an access modifier, which controls the visibility of variable, method, and classes in Java application, while final is just a modifier that enforces additional constraints on the field, method, and class in Java.

4 Examples to Round Floating-Point Numbers in Java up to 2 Decimal Places

Rounding numbers up to 2 or 3 decimal places id a common requirement for Java programmer. Thankfully, Java API provides a couple of ways to round numbers in Java. You can round any floating-point numbers in Java unto n places By using either Math.round(), BigDecimal, or DecimalFormat. I personally prefer to use BigDecimal to round any number in Java because of it's convenient API and support of multiple Rounding modes. Also, if you are working in the financial industry, it's best to do a monetary calculation in BigDecimal rather than double as I have discussed in my earlier post about common Java mistakes

20+ JMS (Java Messaging Service) Interview Questions and Answers for Java Programmers

Java Messaging Service or JMS interview questions is one of the important parts of any Core Java or J2EE interview as messaging is a key aspect of enterprise Java development. JMS is a popular open-source Messaging API and various vendors like Apache Active MQ, Websphere MQ, Sonic MQ provides an implementation of Java messaging API or JMS. Any Java messaging services or JMS interview can be divided into two parts where the first part focuses on fundamental of JMS API and messaging concept like What is a topic, What is Queue, publish-subscribe or point to point model, etc, While the second part is related to JMS experience with particular JMS provider.

5 Best books to learn JDBC - Java Programming

The JDBC (Java Database connectivity) is one of the vital API in Java programming language which allows a Java program to connect to any database, like Oracle, Microsoft SQL Server, MySQL, PostgreSQL, SQL Lite, Sybase or any other relational database. It's an essential API to learn and master for both core Java and Java EE professionals, given the ubiquitous nature of Database in real-world applications. Despite its importance, many Java developer lacks essential JDBC skills, like they are not familiar with Connection, Statement, connection pool, calling stored procedures, and executing a transaction in JDBC.

Eclipse - Access restriction: The type BASE64Decoder is not accessible due to restriction Error [Solved[

Hello guys, if you have been using Eclipse for Java development then you might have seen this dreaded  "Access restriction: The type BASE64Decoder is not accessible due to restriction Error" before. This error comes when you are trying to encode String into Base64 using BASE64Decoder in Eclipse because the class BASE64Decoder is not part of JDK's public API, it comes from sun.misc package which is non-public. Though this class is present in JDK and JRE and allows you to encode and decode String into base 64, any access to this class from Eclipse flags as an error in Eclipse IDE. If you compile and run the same program from the command line or Netbeans you will not get this error.

Top 5 Apache Maven Free Ebooks for Java Developers

If you are working in Java for a couple of years, you surely know about Maven, the most popular tool to build Java application. Recently I had shared 10 things about Maven Java developer should know, (if you have read it yet, you can read it here) and I receive a lot of good feedback about how useful those plugins and Maven, in general, are for Java developers. This motivated me to write more stuff about Apache Maven, and then I thought about sharing some of the free ebooks Java developers can use to learn Maven. Sonatype, the company behind the Nexus open source repository manager and creators of the Apache Maven project, provides a couple of good free ebooks to learn Maven and Nexus repository.

Difference between table scan, index scan, and index seek in SQL Server Database

Hello guys, a good understanding of how the index works and how to use them to improve your SQL query performance is very important while working in a database and SQL and that's why you will find many questions based upon indexes on Programming Job interviews. One of such frequently asked SQL question is the real difference between table scan, index scan, an index seek? which one is faster and why? How does the database chooses which scan or seek to use? and How you can optimize the performance of your SQL SELECT queries by using this knowledge. In general, there are only two ways in which your query engine retrieves the data, using a table scan or by using an index.

How to validate phone number in Java? Google libphonenumber library Example Tutorial

It's a common requirement to validate phone numbers for a Java web application, much like validating email addresses. Unfortunately, Java doesn't provide any built-in method to carry out this kind of common validation, I would love to have a validation package in Java, but don't worry there must be an open-source library to cover this deficiency, right? Yes, there is Google's phone number library which allows you to validate any phone number both international, USA specific or any country-specific.

7 Reasons of NOT using SELECT * in a SQL Query?

I have read many articles on the internet where people suggest that using SELECT * in SQL query is a bad practice and you should always avoid that, but they never care to explain why? Some of them will say you should always use an explicit list of columns in your SQL query, which is a good suggestion and one of the SQL best practices I teach to junior programmers, but many of them don't explain the reason behind it.  Unless you explain some reasons why one should not use SELECT * in queries, it's difficult to convince many SQL developers,  many of whom have started learning SQL by doing SELECT * from EMP in Oracle database. In this article, I will try to bridge that gap by giving some practical reasons why using SELECT * in the SQL query is not a good idea.

How to Create Java Project with Maven in Eclipse - Step by Step Guide

If you are not using Maven for managing dependency and creating a build for your Java project, then you are definitely missing something. Being an ardent fan of ANT, I started with Maven quite late, but once I started, I haven't looked back. Maven makes it so easy to add new open-source JAR files, building and testing your project that you wouldn't look back. By the way, like all the things starting is difficult. I spent countless hours will creating my first Java project using Maven and Eclipse, but those were days with older Eclipse IDE. Now with Eclipse Juno and indigo, you get inbuilt support of Maven, which means it's a lot easier to start working with the Maven-based Java project in Eclipse IDE.