What is rt.jar in Java/JDK/JRE? Why it’s Important?

rt.jar stands for runtime JAR and contains the bootstrap classes, I mean all the classes from Core Java API. I have found that many Java programmer doesn't know what is rt.jar? and often confused with the role of rt.jar file or why we use of rt.jar file in Java? No surprise, the name is a little bit cryptic.  This file always resides inside the lib directory of JRE, at least in Windows and Linux. In MacOSX it resides at a different location and also has a different name i.e. classes.jar, but that is only prior to JDK 1.7. From Java 7 release Apple has stopped distributing Java and if you separately install, it will have the same name as rt.jar.

How to Reverse String in Java Using Iteration and Recursion - Example

How to reverse String in Java is a popular core java interview question and asked on all levels from junior to senior java programming job. since Java has rich API most java programmer answer this question by using StringBuffer reverse() method which easily reverses a String in Java and its right way if you are programming in Java but most interview doesn't stop there and they ask the interviewee to reverse String in Java without using StringBuffer or they will ask you to write an iterative reverse function which reverses string in Java.

Difference between for loop and Enhanced for loop in Java

Though you can use both for loop and enhanced for loop to iterate over arrays and collections like a list, set, or map. There are some key differences between them. In general, enhanced for loop is much easier to use and less error-prone than for loop, where you need to manage the steps manually. At the same time, for loop is much more powerful because you get the opportunity to control over looping process. All the difference, you will learn in this article, stems from this very fact that traditional for loop gives more control that enhanced for loop but on the other hand enhanced or advanced for loop gives more convenience.

How to Set Classpath for Java on Windows and Linux

What is CLASSPATH in Java 
Classpath in Java is the path to directory or list of the directory which is used by ClassLoaders to find and load class in Java program. Classpath can be specified using CLASSPATH environment variable which is case insensitive, -cp or -classpath command-line option or Class-Path attribute in manifest.mf file inside the JAR file in Java.  In this Java tutorial, we will learn What is Classpath in Java, how Java resolves classpath and how Classpath works in Java alongside How to set the classpath for Java in Windows and UNIX environment. 

How to Convert Binary Number to Decimal in Java - Algorithm

Problem : Write a Java program to convert a binary number into decimal format, without using any library method which can directly solve the problem. You are free to use basic Java functions though e.g. those defined in java.lang and all kinds of Java operator e.g. arithmetic and logical operator, bitwise and bitshift operator and relational operators.

Solution : Let's first revise some theory of number system, which is required to convert a number from binary to decimal format. There are four kind of number systems binary, octal, decimal and hexadecimal. Binary is base 2 and that's why any number is represented using only two digit, 0 and 1 also known as bits.

Difference between IdentityHashMap and HashMap in Java

IdentityHashMap in Java was added in Java 1.4 but still, it's one of those lesser-known classes in Java. The main difference between IdentityHashMap and HashMap in Java is that IdentityHashMap is a special implementation of Map interface which doesn't use equals() and hashCode() method for comparing object unlike other implementation of Map e.g. HashMap. Instead, IdentityHashMap uses equality operator "=="  to compare keys and values in Java which makes it faster compared to HashMap and suitable where you need reference equality check and instead of logical equality.

How to use Future and FutureTask in Java Concurrency with Example

Future and FutureTask in Java allows you to write asynchronous code. The Future is a general concurrency abstraction, also known as a promise, which promises to return a result in the future. In asynchronous programming, the main thread doesn't wait for any task to finished, rather it hands over the task to workers and moves on. One way of asynchronous processing is by using callback methods. The Future class in Java is another way to write asynchronous code.

Spring - java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener Quick Solution

If you have worked in Spring MVC than you may be familiar with  
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
which is common problem during deployment. Spring MVC throws  java.lang.ClassNotFoundException:                           org.springframework.web.context.ContextLoaderListener ,
when its not able to find org.springframework.web.context.ContextLoaderListener class which is used to load spring MVC configuration files like application-context.xml and other Spring Framework configuration files defined in context-param element of web.xml in an Spring MVC web application as:

What is difference between Maven, ANT, Jenkins and Hudson?

In short, though Maven and ANT are build tools the main difference is that maven also provides dependency management, standard project layout, and project management. On the difference between Maven, ANT, and Jenkins, later is a continuous integration tool which is much more than a build tool. You can set up your CI environment using Jenkins or Hudson and automatically build, test, and deploy your Java project. Now last, the main difference between Jenkins and Hudson, both originate from the same source code but one is a closed source while the other is open source. You can read the details in this article.

How to get and set default Character encoding or Charset in Java

Default Character encoding in Java or charset is the character encoding used by JVM to convert bytes into Strings or characters when you don't define java system property "file.encoding". Java gets character encoding by calling System.getProperty("file.encoding","UTF-8") at the time of JVM start-up. So if Java doesn't get any file.encoding attribute it uses "UTF-8" character encoding for all practical purpose e.g. on String.getBytes() or Charset.defaultCharSet()

How to define Error page in Java Web Application - Servlet JSP

There are two ways to define the Error page in Java web application written using Servlet and JSP. The first way is page wise error page which is defined on each jsp page and if there is any unhandled exception thrown from that page, the corresponding error page will be displayed. The second approach is an application-wide general or default error page which is shown if any Exception is thrown form any Servlet or JSP and there is no page-specific error page defined.

How to fix java.sql.SQLException: Invalid column index

"java.sql.SQLException: Invalid column index" is a frequent error while working in Java Database Connectivity (JDBC). As the name suggests "Invalid column index" its related to accessing or setting column in your SQL Query using prepared statement in Java. I have seen "java.sql.SQLException: Invalid column index" coming mostly due to two reason:

1) Setting column data using setXXXX(int coloumIndex) e.g. setInt(0) setString(0)
2) Getting column data using getXXX(int columnIndex) e.g. getInt(0) getString(0)

The most common cause of "java.sql.SQLException: Invalid column index" is a misconception that column index started with "0" like array or String index but that's not true instead column index starts with "1" so whenever you try to get or Set column data with column index "0" you will get "java.sql.SQLException: Invalid column index".

How to create LocalDateTime in Java 8 - Example

The LocalDateTime is a new class introduced in Java 8 new Date and Time API. This class is in java.time package and it represents both date and time information without timezone. In this example, you will learn different ways to create an instance of LocalDateTime class in Java 8 like by using the static factory method, or by combining LocalDate and LocalTime instances together, which are subsequently used to denote date without time and time without the date in Java 8. As their name suggests they are local, so they don't contain timezone information.

Difference between Thread vs Runnable interface in Java

Thread vs Runnable in Java is always been a confusing decision for beginnerin java. Thread in Java seems easy in comparison to Runnable because you just deal with one class java.lang.Thread while in case of using Runnable to implement Thread you need to deal with both Thread and Runnable two classes. though the decision of using Runnable or Thread should be taken considering differences between Runnable and Thread and pros and cons of both approaches.

Difference between FIX 4.2 vs FIX 4.4 in FIX connectivity

FIX 4.2 vs FIX 4.4
FIX protocol has evolved over time; it’s now more than a decade it’s started by Fidelity and Solomon Brothers. FIX connectivity is the most popular connectivity solution exists for trading whether its equities, futures, options or fixed income or even foreign exchange (FX). FIX protocol has dominated the market and become as standard solution for any market or broker which is trying to develop connectivity with market within a short period of time because of complexity of native exchange api and lack of support FIX protocol come as handy.

Java Comparator Example for Custom Sorting Employee by Name, Age and Salary

In this tutorial, we will see Java Comparator example to sort an Employee object by name, age, and salary. In order to sort Employee object on different criteria, we need to create multiple comparators e.g. NameComparator, AgeComparator, and SalaryComparator, this is known as custom sorting in Java. This is different than natural ordering of object, provided by compareTo() method of java.lang.Comparable interface. Though both compare() and compareTo() method looks similar they are different in a sense that, former accepts one parameter, while later accept two-parameter. Former compare passed object to the current object, on the other hand, compare() method compares two different objects passed to it.

JAXB XML Binding tutorial - Marshalling UnMarshalling Java Object to XML

XML binding is a concept of generating Java objects from XML and opposite i.e. XML documents from Java object. Along with parsing XML documents using DOM and SAX parser, XML binding is a key concept to learn if you are working in a Java application that uses XML in any way e.g. for storing persistence data like user preferences or for transmitting messages between two systems, etc. XML binding is also a popular XML Interview question in Java. JAXB and XMLBeans are two common ways to achieve XML binding in Java.  XML binding, also known as XML marshaling and marshaling has two sides, first converting an XML document to Java object, modify Java object, and then converting back to an XML file.

How to Split String based on delimiter in Java? Example Tutorial

You can use the split() method of String class from JDK to split a String based on a delimiter e.g. splitting a comma-separated String on a comma, breaking a pipe-delimited String on a pipe or splitting a pipe-delimited String on a pipe. It's very similar to earlier examples where you have learned how to split String in Java. The only point which is important to remember is little bit knowledge of regular expression, especially when the delimiter is also a special character in regular expression e.g. pipe (|) or dot (.), as seen in how to split String by dot in Java. In those cases, you need to escape these characters e.g. instead of |, you need to pass \\| to the split method.

Solaris Command to Show Long argument list of a Running Process

One of the problems with ps command, which is a popular tool to find any processes along with the grep command in the Solaris operating system is that it doesn't show full command-line argument of process. This means if you are doing grep on any text which appears at the tail end of the long command line, you will likely not able to capture that process by using ps and grep. This is dangerous because it may lead you to assume that certain process is not running and you may restart it again, despite its being running and only because you didn't find the process.

How to find if JVM is 32 or 64 bit from Java program.

You can find JVM bit size e.g. 32 bit or 64 bit by using either running java command from the command prompt or by using System.getProperty() from Java program. The question is why do you want to know hardware or platform configuration while writing Java code which is supposed to write once and read anywhere(32 bit, 64 bit, etc)? Yes we don't really need to know whether JVM is 32 bit or 64 bit more often but there are many situations when this matters

Top 10 Excuses Programmers Gives to Avoid Unit Testing

Though everyone loves unit tests and everyone agrees with the benefits they bring in, when the time comes to write them, you will see a lot of excuses, even from some of the more experienced and senior developers. At the heart of the problem of not writing unit tests or enough unit tests they are two things, first is time pressure i.e. you don't have enough time to complete coding forget about writing unit tests. This problem comes due to erroneous estimation i.e. only estimating time for coding and not including unit testing as part of development.

How many characters is allowed on VARCHAR(n) columns in SQL Server? How much memory VARCHAR variable takes in disk?

One of the frequently asked SQL questions in any programming interview is what is the difference between VARCHAR and CHAR data type in SQL? particularly when your project is using Microsoft SQL Server. You might have seen this couple of times, but given its popularity, nowadays people are asking this question differently e.g. they will ask you how much space a column of VARCHAR(2) data type will take? How many characters can it take? How do you minimize space? Is it better to use a CHAR variable instead of VARCHAR(2) and why? These are some of the really interesting questions and more meaningful than classical SQL questions like the difference between char vs varchar data type questions.

Difference between Functional and Non-Functional Requirements in Software development

Gathering the correct and complete requirement is one of the most important thing in software development. Incorrect and incomplete requirement are main reason of why project fails. If you are in software development, you may have come across terms like functional and non-functional requirement. If you are wondering why a prototype take a 2 weeks but actual application development requires around 3 to 4 months of development; think of non-functional requirement. When someone told you to build a software, what they tell you is what that software should do e.g. allow you to trade on certain market, but they don't tell you about security, performance, load and other stuff, this is what I called non functional requirement. Obvious difference between functional and non-functional requirement is, former is specified by its users, business analyst and its part of software's feature list, for example functional requirement of a trading application is to receive order, enrich, transform and send it to Stock Exchange, but non-functional requirement is not specified by user, its rather thought by Software architect, Subject Matter Experts, Technical lead and Support peoples. For example, for this same trading application non-functional requirement could be Failover and Recovery, logging, auditing, latency and other performance characteristic that, application should be able to run continuous, can process 5K orders per second etc. Support people can also ask functionality require to add user, give access, revoke access, monitoring etc. Every application in software development has one or other kind of non-functional requirements. In this article, we will learn more about difference between functional and non-functional requirements in software and product development.

Top 20 Tibco Rendezvous and EMS Interview questions and answers

Hi Guys, in this part of my Tibco Rendezvous tutorial series I am sharing some Tibco RV interview questions and answers most often asked in any TIBCO messaging interviews. These are based on fundamental TIBCO concepts and also offer some new way of learning TIBCO RV or TIBCO Rendezvous technology. Some of the TIBCO Interview questions I have already discussed in my TIBCO command series.

TIBCO Rendezvous Interview Questions

Here is the list of TIBCO interview question, I am not putting answer for these interview questions right now but will put together in some other post but these questions are really great in terms of any Tibco messaging interview. For better organization and quick access I will divide TIBCO Interview questions on various category e.g. TIBCO Rendezvous Interview questions, TIBCO EMS Interview questions, TIBCO Certified Messaging questions, TIBCO Hawk Interview questions and Miscellaneous TIBCO Interview questions. Please let me know if you want some more categories. Answers of these Tibco Interview questions can be found in different tutorials available in my blog; I will also try to post relevant links here.

This article is in continuation of my interview articles 10 Interview questions on Singleton Pattern in Java , Top 20 FIX Protocol Interview questions and Top 20 Core Java interview questions asked in Investment banks and Top 10 Java Serialization Interview questions

Display Tag Export Example in JSP – Issue Fix Java Tutorial

Display tag provides export options to export page into PDF, CSV, Excel, and XML in Java web application written using JSP, Servlet, Struts or Spring MVC framework. Display tag is a tag library and you just need to use it in your JSP page to display tabular data or generate HTML tables dynamically. Earlier we have seen 10 display tag tips for getting most out of display tag and in this JSP Servlet tutorial we will see one display tag export issue, which prevents display tag export functionality to work properly. Display tag experience is considered good in various JSP interviews and some questions related to sorting, paging, both internal paging and external paging and exporting on display tag also appear as various J2EE and Servlet Interview questions.

What is Constructor Overloading in Java? - Interview Question

Constructor overloading in java allows having more than one constructor inside one Class. in the last article we have discussed method overloading and overriding and constructor, overloading is not much different than method overloading. Just like in the case of method overloading you have multiple methods with the same name but different signature, in Constructor overloading you have multiple constructors with a different signature with the only difference that Constructor doesn't have a return type in Java. That constructor will be called as an overloaded constructor.

Java Clone Tutorial Part 2 - Example to Override with Mutable field

This is the second part of Java tutorial on Cloning, In the first part, we have seen how the clone method works in Java with a simple example of cloning objects, with primitives and Immutable. In this tutorial, we will take one step further and override the clone method for creating a clone of objects with a mutable field. In our case the mutable field is a Collection here, to be precise a List. Since the default implementation of the clone() method only does a shallow copy of objects, it can create issues, if the original object contains mutable object or Collection classes. In our example, we have a class called Programmer, with String name, int age, and List of Certifications.

Difference between Serializable and Externalizable in Java Serialization

The difference between serializable and externalizable is the popular java interview question which we have touched on my earlier post on Serialization: Top 10 java serialization interview questions. knowing differences between externalizable and serializable is not just important from the interview point of view but also getting control of the serialization process and optimizing the performance of serialization. both serializable and externalizable used to serialize or persist java objects but the way they do is little different.

Difference between URL-rewriting URL-encoding in Servlet JSP

URL-rewriting vs URL-encoding in Servlet JSP
The main difference between URL-rewriting and URL-encoding is that URL-rewriting is a technique to maintain user session if cookies are not enabled on client browser or browser doesn't support cookie while URL-encoding is a way to pass a string to the server containing special characters by converting special characters like space into some other characters like +. people often confuse between URL encoding and URL rewriting because of there names which sound quite similar for new guys but functionality wise they are totally different to each other, Also servlet encodeURL() method adds more confusion because its sounds like its used for URL Encoding but indeed used for URL Rewriting.

3 ways to loop over Set or HashSet in Java? Examples

Since Set interface or HashSet class doesn't provide a get() method to retrieve elements, the only way to take out elements from a Set is to iterate over it by using the Iterator, or loop over Set using advanced for loop of Java 5. You can get the iterator by calling the iterator() method of the Set interface. This method returns an iterator over the elements in the sets but they are returned in no particular order, as Set doesn't guarantee any order. Though individual Set implementations e.g. LinkedHashSet or TreeSet can impose ordering and in such iterator will return elements on that order.

How to fix Failed to load Main-Class manifest attribute from jar - Java Eclipse Netbeans Tutorial

If you have tried creating JAR file and running Java program from command the line you may have encountered "Failed to load Main-Class manifest attribute from jar", This error which haunts many Java programmer when they enter into command line arena and tries to create JAR file in the command line or IDE like Netbeans and Eclipse. The major problem with "Failed to load Main-Class manifest attribute from jar" error is that, it’s unnecessary creates panic which it doesn't deserve, maybe because the process involves of creating and running JAR is not that common like running Java program using the "java" command.

String replaceAll() example - How to replace all characters and substring from String

You can replace all occurrence of a single character, or a substring of a given String in Java using the replaceAll() method of java.lang.String class. This method also allows you to specify the target substring using the regular expression, which means you can use this to remove all white space from String. The replaceAll() function is a very useful, versatile, and powerful method and as a Java developer, you must know about it. Even though Java provides separate methods for replacing characters and replacing substring, you can do all that just by using this single method.

How to get max memory, free memory and total memory in Java

Getting free memory, total memory and max memory on JVM is using Runtime class in Java. and many java programmers is interested to know whether they have any relationship with JVM argument -Xms and -Xmx which is used to specify starting heap size and maximum heap size of JVM. I have touched this on 10 Points on Java heap and how to set heap size in ANT and Maven but here we will see some way to find out starting and maximum heap size from Java program.

Eclipse Not Able To Connect Internet, Market Place - Configure Connection Proxy Settings

If you are using Eclipse in your company, you might have faced issues, where Eclipse is not able to connect to the internet. Since most of the companies use a proxy for connecting to the Internet, it's important to configure proxy settings in Eclipse to allow Eclipse to access the Internet behind the organization's firewall. If your company regularly changes there internet proxy settings then this also needs to be updated whenever your Proxy server changes. Since Eclipse needs an internet connection for connecting to Eclipse Market place, installing and updating plugins, downloading Maven dependencies from remote maven repository, it's really frustrating when Eclipse just hung up, shows connecting and time out after a long time.

How to check if a Number is Positive or Negative in Java - Interview Question

Write a Java program to check if a number is positive or negative is one of the popular Java coding interview questions, it may look easy but programmers often fumble on this question. One of the tricky parts of this question is that Java has multiple data types to support numbers like byte, short, char, int, long, float, and double, out of those all are signed except char, which can not represent negative numbers. Some solutions work for int and long but may not work for floating-point number e.g. float and double.

5 Free OCEJWCD 6 Mock Exam 1Z0-899 Practice Test

The OCEJWCD is the Oracle's version of SCWCD (Sun Certified Web Component Developer) exam, which tests candidate's knowledge on Servlet, JSP, and other web technology. The OCEJWCD stands for Oracle Certified Enterprise Java Web Component Developer. Like other Java certifications e.g. OCAJP or OCPJP, the key to success is selecting a good book, practicing code daily, and then solving as many mock questions as possible. In the last article, I have shared some of the best OCEJWCD books and in this article, I am going to share of the best free OCEJWCD 6 mock tests you can online. These mock exams are good for self-assessment and practicing before real exams.

How to use Lambda Expression in Place of Anonymous Class in Java 8

Before Java 8, Anonymous class was the only way you can implement functional idiom in Java. Since prior to Java 8 you cannot pass function to another function, you would have to wrap it into an object, as seen in Strategy Pattern. Those are also known as function objects in Java. Anonymous class was also handy to create a throw-away implementation of SAM (Single Abstract Methods) interfaces like Runnable, Callable,  CommandListener, or ActionListener. Despite all these goodies and flexibility, the Anonymous class adds too much boilerplate code, making it hard to read and understand.

Why Default or No Argument Constructor is Important in Java Class

Almost all Java developers know that compiler adds a default constructor or better known as a no-argument constructor in every Java class, but many of them forget that it only does when you don't provide any other constructor. This means it becomes the developers' responsibility to add a no-argument constructor if he is adding explicit constructor. Now, Why it's important to provide default constructor in Java, What happens if your class doesn't have a no-argument constructor? Well, this is how it's asked in many Java interviews, most commonly as part of Spring and Hibernate interviews.

6 JDBC Performance Tips for Java Developers

JDBC Performance tips are a collection of some tried and tested ways of coding and applying process which improves the performance of JDBC code. The performance of core Java application or J2EE web application is very important, especially if its user database in the back end which tends to slow down performance drastically. do you experience your java j2ee web application to be very slow (taking few seconds to process simple requests which involve database access, paging, sorting, etc) than below tips may improve the performance of your Java application? these tips are simple in nature and can be applied to other programming language application which uses the database as back-end. 

How to Sort Array in Java Ascending and Descending Order of Elements With Example

Quite often we need to sort array in Java luckily java.util.Arrays class provides several utility methods to sort java array of any type e.g. primitive, object or int, String, etc. Arrays are in java.util package and exposed all sorting related methods as static utility functions. you can access sort() as Arrays.sort() and just pass your array and it will sort that array object. You can sort array in ascending order, descending order, or any custom order defined by the custom comparator in Java.

Tibco tutorial : RVD (Rendezeous daemon) vs RVRD (Rendezeous Routig Daemon)

RVD (Rendezvous daemon) vs RVRD (Rendezvous Routing Daemon)
RVRD (Rendezvous Routing Daemon) are simply process owned by middleware or network teams which listens multicast traffic locally and transmit it to another RVRD counter part (another host) using TCP. This remote host than re multicast this traffic to there own network. So essentially it used to bridge two different regional network e.g. London and Newyork etc.

RVRD is multicast in one end and unicast on other end so it receives messages from multiple RVD (Rendezvous Daemon) and send via TCP to another RVRD which distributes messages on different RVD (Rendezvous Daemon) on there own network e.g. say on NY network.

How public static final variable works in Java?

Hello guys, how do public static final variable works in Java is a common Java interview question on interviews? It is also asked as to what is the difference between a public static final variable and a public final (non-static) variable in Java? Does both are same? It is one of the simple, yet tricky questions that may Interviewers like to ask candidates, and would you believe that almost 50% of Java developers miss the key point to mention here, which we'll see in this article. In short, No, they are not the same. Even though both are final variables and you cannot change their value once assigned there is a very subtle difference between them.

Top 5 Blogs Java EE developers should follow

One reason for Java's great success as a programming language is that it has dominated Enterprise space. Earlier J2EE used to be the popular platform, but now we have a more modern and improved Java EE platform, with the latest release of Java EE 7. Java Platform, Enterprise Edition 7 provides new features that include enhanced HTML5 support, increases developer productivity, and further improves how enterprise demands can be met. One of the biggest advantages of Java EE 7 is the reduction of boilerplate code.

ThreadLocal Memory Leak in Java web application - Tomcat

ThreadLocal variables are infamous for creating memory leaks. A memory leak in Java is the amount of memory hold by an object which is not in use and should have been garbage collected, but because of unintended strong references, they still live in Java heap space. There are many ways memory leak can be caused in Java but when this memory leak is caused due to the ThreadLocal variable, it’s referred to as ThreadLocal memory leak. In our last post about the ThreadLocal variable, we have seen How the ThreadLocal variable can make SimpleDateFormat thread-safe and also raised points that in a managed environment like the J2EE application server or a web servers like Tomcat, Jetty, WebSphere or Weblogic use of ThreadLocal should be avoided.

How to convert double to int in Java?

Suppose you have a double primitive variable 4.444 and you want to convert it to the integer value 4, how do you that in Java? Since double is bigger data type than int, you can simply downcast double to int in Java. double is 64-bit primitive value and when you cast it to a 32-bit integer, anything after the decimal point is lost. Btw, typecasting doesn't do any rounding or flooring, which means if you have 9.999999 and while casting to int you are expecting 10 then you would be disappointed, casting will give you just 9. If you need 10 then you need to use Math.round() method to first round the double value to the nearest integer and then truncate decimals.

How to create hidden file in Java- Example Tutorial

In the last article, we saw how to check hidden files in Java and now we will see how to hide files in Java or make hidden files in Java. As we said File API in Java doesn’t provide any method to make a file hidden in Java but still you can apply some quick tricks to hide files from Java program. Like in Unix environment any file whose names begin with a dot (.) is hidden so you can name your file starting with a dot (.)  and your File will be hidden in Linux or Unix Environment.

How to check if a File is hidden in Java with Example

This article is a quick tip to find hidden files in Java by checking the hidden properties of a File or directory from Java Program. File Handling is a crucial topic in java already we have discussed how to create a file in java, how to create a directory, how to read write in a text file in Java, how to set permissions on the file and some more aspect and we will discuss one more property of the file, i.e. hidden property. Now the question arises can we make a file Hidden using our java code or not.

Basics of FIX protocol and FIX Engine

FIX protocol is Industry standard protocol for electronic trading , with evolution with computer technology Trading also getting Electronic and now most of the exchanges in the world are fully electronic and the concept of trading floor is taken over by computers.When I was new to FIX protocol I have searched the net to find a good FIX protocol tutorial but not much is available so I am trying to write my own experience in the form of short  FIX protocol tutorial.

Difference between OCPJP 8 Upgrade Exams 1Z0-813 and 1Z0-810? Which one to take?

Many Java developers who holds a Java certification either from Sun or Oracle and who is looking to upgrade to latest Java version i.e. Java SE 8 certification has a common doubt, should they go for 1Z0-810 or 1Z0-813 upgrade exams? What are the different between these two exams? Well, even though they are both upgrade to Java SE 8 exam, they are separate exams and have a different exam code, the difference is also obvious when you look at their title. The 1Z0-810 exam is known as "Upgrade Java SE 7 to Java SE 8 OCP Programme" while the 1Z0-813 exam is known as "Upgrade to Java SE 8 OCP ( Java SE 6 and all prior versions)".

How to get current Date Timestamps in Java on GMT or Local Timezone Example

Getting current data and timestamps in java is a requirement for most java enterprise applications. The formatting date in java or parsing date in Java is such a common functionality that you will need it now and then. Though most of the programmers look Google for finding current date and timestamps code in Java, it's worth to having an idea how you can do that by using java.util.Date class. sometimes you might need formatted data string say "yyyy-MM--dd:HH:mm:ss".

Why Override equals, hashcode and toString method in Java

A couple of questions, which are often asked to me was why do we need to override equals() and hashcode() method, Why should I implement toString(), What will happen if I don't override them or in a different way, I have never overridden equals and hashcode and not faced any problem, why should I override them now. You guessed it correct, almost all of these questions come from beginners, who have either taken some Java programming classes or started learning Java by their own.

How to decompile class file in Java and Eclipse - Javap command example

The ability to decompile a Java class file is quite helpful for any Java developer who wants to look into the source of any open source or propriety library used in a project. Though I always prefer to attach sources in Eclipse of most common libraries like JDK it’s not always possible with an increasing number of dependencies. Java decompiler (a program that can decompile Java class files to produce source files) is very helpful in such a situation. By using Java decompiler you can easily check out the source of any .class file. Thanks to Eclipse IDE and the increasing number of free plug-ins available for Java developers, You can have powerful Java decompile in your armory.

FIX protocol tutorial : Fix Session is not connecting how to diagnose it ?

In this blog post of FIX protocol tutorial series I would like to share my experience with connectivity issues around Fix Engines. to exchange message or say to trade electronically clients connect to broker using FIX protocol and for that they use FIX Engine. In FIX protocol connection between two FIX Engine is refereed as FIX Session and we normally say whether FIX Session is connected or not connected. FIX Session normally have there start time , end time and EOD time (End of day time) also called TradingSession start time , Trading Session End Time and Trading Session EOD time.

Difference between include directive and include action in JSP Servlet

Difference between include directive and include action is one of the most popular JSP interview questions and also asked as What is the difference between page include and file include in JSP.  Similar to the difference between forward and send redirect and URL encoding vs URL rewriting, this is also asked at a beginner level. Here we will see page include vs file include in detail. Both include directive and include action is used to include the output of a static page e.g. HTML or a dynamic page e.g. jsp inside another jsp file.

Top 20 Amazon and Google Programming Interview Questions

Hello, In this article I am going to sharing some frequently asked programming job interviews from technical giants and startups. If you are going for a programming job interview with Microsoft, Google or Amazon, you better be prepared for all kinds of questions. These companies are known to ask tough questions, tricky puzzles, and lots of data structure and algorithm questions. Since it's hard to prepare all these in a short time, it makes sense to at least have a good idea of frequently asked programming questions in Microsoft, Google, or Amazon.

12 Essential Apache Web Server Interview Questions Answers - Java & Linux

The Apache HTTP Server, also known as httpd, has been the most popular web server on the Internet since April of 1996. It is both free and robust and that's the reason that almost half of the world's websites  runs on Apache HTTP web server, ranging from small hobby websites to huge e-commerce giants and big banks. There are also many companies which use Apache and Tomcat to host Java web application. In a typical setup, Apache web server receives the HTTP request and depending upon the URL it either route to Tomcat or serve the static files directly from the file system. These questions are based mostly on that experience. Though Apache is not just famous in Java world it is even more popular with other web technologies e.g. Perl, PHP, and MySQL. It's one of the powerful and secure web servers so anyone can use it to handle HTTP traffic. It supports both HTTP and HTTPS. It's worth noting that Apache is also an HTTP/1.1 compliant web server.

10 Example of this keyword in Java

this keyword in Java is a special keyword that can be used to represent the current object or instance of any class in Java. “this” keyword can also call the constructor of the same class in Java and used to call overloaded constructor. In this Java tutorial, we will see how to use this keyword in Java and different examples of this in Java. this sometimes also associates with a super keyword which is used to denote instance of the superclass in Java and can be used to call an overloaded constructor in Java.

Difference between Sun (Oracle) JVM and IBM JVM

There are different JVM implementation available apart from popular Sun's (now Oracle) hotspot JVM like IBM's JVM. Now the question comes, what makes two JVM different from each other? Quite a lot of things can be different even if two JVMs are implemented by following Java virtual machine specification. IBM has its own JVM implementation which is different than Oracle's JVM in many things like JIT(Just in Time) Compiler, the structure of Java heap, garbage collectors, and support for monitoring and management. Though I have mostly used Sun’s hotspot JVM recently got a chance to run some Java program on IBM JVM on the AIX platform.

How to fix java.net.SocketException: Software caused connection abort: recv failed

Out of many client servers related socket errors here is one more interesting socket related error from Java program, "java.net.SocketException: Software caused connection abort: recv failed". The key point in this error message is "abort" and "recv", which means is someone (client or server) is trying to read from a closed connection.This error usually comes at the client socket end, when server closed the connection before the client has read the response, but, in general, it can come to any end of TCP socket, so you must check the log files for both client and server to find out who is complaining. If Server is complaining then it's fine and the client has closed the TCP connection may be due to timeout or any RuntimeException at the client end.

How to Sort Java ArrayList in Descending Order - Example Tutorial

Sorting ArrayList in Java is a common task for Java developer and we have touched it while discussing in my last article 10 Examples of  ArrayList in Java and again when we discussed comparator and comparable in Java. In order to sort an ArrayList, we need to use the Collections utility class which contains an overloaded sort() method for sorting different collections and supports different comparators in Java. In this article, we will see how to sort ArrayList in the natural order of elements and then sorting ArrayList in Java with a comparator.

Tibco tutorial : Tibrv Errors and Exceptions

While working with tibco rv during many years I found that tibco errors are mysteriously difficult to diagnose for a newcomer and minor difference between syntax and semantics along with network specifics lead some strange error. here I am putting most common error which I have faced mainly because of some silly mistake in syntax and spent hours to figure out exact cause during my initial days.This list is by no means complete and I would encourage to put any other error you have encountered to make this list more useful. Any suggestion, input feedback always welcome.

Reading/Writing to/from Files using FileChannel and ByteBuffer in Java

In the past, I have talked about RandomAccessFile and how it can be used for doing faster IO in Java, and in this Java NIO tutorial, we are going to see how to use read/write data from using FileChannel and ByteBuffer. Channel provides an alternate way to read data from a file, it provides better performance than InputStream or OutputStream. It can also be opened in blocking and non-blocking mode. Though FileChannles are read/write channels and they are always blocking, they cannot be put into non-blocking mode.

Difference between Bitwsie and Logical Operator in Java - & vs &&, | vs ||

Java beginners often ask the same type of questions, and of them is what is difference between & and && operator in Java or difference between | and || operators? The standard answer of this question is well, the main difference between & and && is that former is a bitwise operator and && is a logical operator in Java. That's academic until you clearly explain the difference in working of & and && or | and ||. For absolute beginners, & is used to represent AND logic operation in Java and | is used to represent OR logic operation.

3 Ways to Convert Java 8 Stream to an Array - Lambda Expression and Constructor Reference Example

One of the frequently asked Java 8 questions is, how you do convert a Java 8 Stream to an array? For example, you have a Stream of Strings and you want an array of String so that you can pass this to a legacy method which expects an array, how do you do that? Well, the obvious place to search is the Javadoc of java.util.stream.Stream class and there you will find a toArray() method. Though this method will convert the Stream to an array it has a problem, it returns an Object array. What will you do, if you need a String array? Well, you can use the overloaded version of the toArray(IntFunction generator), which expects a generator function to create an array of the specified type.

How to Create and Initialize Anonymous Array in Java Example

Anonymous arrays in Java is an Array without any name, just like Anonymous inner classes and policy of using Anonymous array is just create, initialize and use it, Since it doesn't have any name you can not reuse it. The anonymous array was a good way to implement variable argument methods before Java introduced varargs in Java5. You had the liberty to create an array of any length and pass that to a method that operates on an anonymous array. Classical example of such variable argument method is aggregate function like sum(), avg(), min(), max() etc.

How does Java HashMap or LinkedHahsMap handles collisions?

Prior to Java 8, HashMap and all other hash table based Map implementation classes in Java handle collision by chaining, i.e. they use linked list to store map entries which ended in the same bucket due to a collision. If a key end up in the same bucket location where entry is already stored then this entry is just added at the head of the linked list there. In the worst case this degrades the performance of the get() method of HashMap to O(n) from O(1). In order to address this issue in the case of frequent HashMap collisions, Java8 has started using a balanced tree instead of a linked list for storing collided entries. This also means that in the worst case you will get a performance boost from O(n) to O(log n).

Method and Constructor Overloading Best Practices in Java

You need to be careful while overloading a method in Java, especially after the introduction of autoboxing in Java 5. Poorly overloaded method not only adds confusion among developers who use that but also they are error-prone and leaves your program on compiler's mercy to select proper method. One of the best examples of a poorly overloaded method is the removal method of ArrayList. There are two versions of remove, first, one which takes an Object as argument i.e. remove(Object element) and the second one, which takes an index as argument i.e. remove(int index).

Difference between extends and implements keywords in Java

Though both extends and implements keyword in Java is used to implement Inheritance concept of Object-Oriented programming, there is a subtle difference between them. The extends keyword is mainly used to extend a class i.e. to create a subclass in Java, while implements keyword is used to implement an interface in Java. The extends keyword can also be used by an interface for extending another interface. In order to better understand the difference between extends and implements, you also need to learn and understand the difference between class and interface in Java.

How to convert ArrayList to Set in Java with Example

Converting ArrayList to Set in Java means creating a Set implementation like HashSet from an ArrayList full of objects. Before Converting your ArrayList into HashSet do remember that List keep insertion order and guarantees the same but Set doesn't have such obligation. Also, List allows duplicates but Set doesn't allow any duplicates, which means if you have duplicates in your ArrayList they will be lost when you convert ArrayList to HashSet and that's the reason why the sometime size of ArrayList doesn't match with the size of HashSet after conversion.