This is the second article about tree traversal algorithms using Java. In the first part, we have seen the pre-order algorithm for visiting all nodes of the binary tree and today we'll learn about the InOrder traversal. As I told you before, unlike array and linked list, the binary tree has several ways of traversal. The traversal algorithms are broadly divided into depth-first and breadth-first traversal algorithms depending upon how the algorithm actually works. As the name suggests, depth-first explores binary tree towards depth before visiting sibling, while breath first visits all nodes in the same level before going to next level, hence it is also known as level order traversal.
Saturday, April 5, 2025
How to Print all Leaf Nodes of Binary tree in Java - Recursion and Stack Examples
Binary tree based questions is very common in Java or any other programming job interviews. One of the frequently asked binary tree questions is "write a program to print all leaf nodes of a binary tree". In order to solve this problem, you must know what is a leaf node? A leaf node in a binary tree is a node whose left and right child is null. They are actually the last nodes of any binary tree. In a typical programming interview, you would be given a binary tree and asked to write a program to print all leaf nodes. Usually, all binary tree related questions can be solved easily using recursion because a tree is a recursive data structure, but you should also know how to solve them without recursion.
Labels:
binary tree
,
data structure and algorithm
Top 10 Maven Plugins Every Java Developer Should Know
In the last couple of years, Maven has become the de-facto build tool for Java applications. Though there are challenges that exist from tools like Gradle, I think the dominance of Maven will help it to win the final battle. When I started with Maven, I was happy with just dependency management but then I come to know about maven plugins which let you customize your build-up to the level you can do with ANT. These plugins provide true power to Maven to automate most of the build-related tasks like compilation, testing, packaging, deployment, and even committing the source code into the remote source repository.
Labels:
Maven
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.
Labels:
core java
,
J2EE
,
JVM Internals
How to get max memory, free memory and total memory in Java? Example
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.
Labels:
core java
,
JVM Internals
Tibco Tutorial: Fundamentals of Tibco RV Messaging - Network, Service, and Daemon on RVD
This is in continuation of my tibco tutorial series where I will discuss tibco rv on the application developer's point of view as middleware or messaging solution.As discussed in earlier tibco tutorials, tibco is used for communicating between two systems e.g. client and server or server to server, here we will see some of the basic terms used in tibco rv world.
Labels:
Java Messaging Service
,
messaging
,
tibco
Top 20 FIX Protocol Interview Questions and Answers
Its' been a while since I shared FIX protocol interview questions. So here is the new set of top 20 FIX protocol interview questions. These are the question which is mostly asked in while interviewing any developer or support professional which has some knowledge of FIX protocol. Given the number of clients, brokers and exchanges using FIX protocol it’s really a great thing to have on your resume and can land you some very well paying jobs in the street.
Friday, April 4, 2025
How to set JAVA_HOME environment in Linux, Unix and Windows? Example
JAVA_HOME is a system environment variable that represents the JDK installation directory. When you install JDK in your machine (Windows, Linux, or UNIX) it creates a home directory and puts all its binary (bin), library(lib), and other tools. In order to compile the java program "javac" tool should be in your PATH and in order to get that in PATH we use the JAVA_HOME environment variable. Many tools like ANT and web servers like tomcat use JAVA_HOME to find java binaries. In this article, we will see how to set the JAVA_HOME environment variable in the different operating systems including Windows (Windows 7, Vista, XP) and Linux (Unix).
JSTL Set tag examples or <c:set> in JSP – Java J2EE Tutorial
JSTL set tag or <c:set> also called as JSTL Core tag library is a good replacement of <jsp:setProperty> jsp action which lacks lot of functionality and only allow you to set bean property. you can not set Map's key-value or create a scoped variable by using <jsp:setProperty>. jstl <set> tag allows you to do all the stuff related to setting or creating variables or attributes. by using JSTL <c:set> tag you can :
Labels:
J2EE
,
jsp-servlet
,
JSTL
What is Constructor Overloading in Java? Example
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 signatures, 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.
Labels:
constructor
,
core java
,
object oriented programming
Why use Memory Mapped File or MapppedByteBuffer in Java? Example
Memory Mapped Files in Java is a rather new java concept for many programmers and developers, though it’s been there from JDK 1.4 along with java.nio package. Java IO has been considerably fast after the introduction of NIO and memory-mapped file offers the fastest IO operation possible in Java, that's the main reason of Why high-performance Java application should use Memory Mapped files for persisting data. It's already quite popular in the high-frequency trading space, where the electronic trading system needs to be super fast and one-way latency to exchange has to be on the sub-microsecond level.
Labels:
core java
,
java IO tutorial
How to Fix Tibrv Errors and Exceptions? Examples
While working with tibco rv for many years I found that Tibco errors are mysteriously difficult to diagnose for a newcomer and minor differences between syntax and semantics along with network specifics lead to some strange errors. here I am putting the most common error which I have faced mainly because of some silly mistake in syntax and spent hours to figure out the 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 suggestions, input feedback always welcome.
Labels:
error and exception
,
tibco
How to add Primary key into a New or Existing Table in SQL Server? Example
Since a primary key is nothing but a constraint, you can use the ALTER clause of SQL to add a primary key into the existing table. Though it's an SQL and database best practice to always have a primary key in a table, you will often find tables that don't have a primary key. Sometimes, this is due to lack of a column that is both NOT NULL and UNIQUE (constraint require to be a primary key), but other times purely due to lack of knowledge or lack of energy. If you don't have a column that can serve as the primary key, you can use identity columns for that purpose. Alternatively, you can also combine multiple columns to create composite primary keys, like you can combine firstname and lastname to create a primary key name, etc.
Labels:
database
,
Microsoft SQL Server
,
SQL
Difference between Session Level Reject and Business message Reject in FIX Protocol? Answer
FIX Protocol tutorials: Difference between Session Level Reject and Business message Reject
In FIX protocol there are multiple ways of rejecting message some of them are using an Execution Report (MsgType=8) and ExecType=8 to reject a FIX message if it can not be acceptable by exchange e.g. Sending order for an exchange and link between broker and exchange is down. Another way of rejecting message is OrderCancelReject (FIX MsgType=9) which is used to reject amend (OrderCancelReplace message FIX MsgType 35=G) and cancel (OrderCancelRequest FIX MsgType=F) messages if its not possible to modify or cancel original message e.g. Sending Cancel request to an already filled order will be rejected by OrderCancelReject message in FIX protocol.
In FIX protocol there are multiple ways of rejecting message some of them are using an Execution Report (MsgType=8) and ExecType=8 to reject a FIX message if it can not be acceptable by exchange e.g. Sending order for an exchange and link between broker and exchange is down. Another way of rejecting message is OrderCancelReject (FIX MsgType=9) which is used to reject amend (OrderCancelReplace message FIX MsgType 35=G) and cancel (OrderCancelRequest FIX MsgType=F) messages if its not possible to modify or cancel original message e.g. Sending Cancel request to an already filled order will be rejected by OrderCancelReject message in FIX protocol.
Labels:
FIX protocol tutorial
Wednesday, April 2, 2025
Why non-static variable cannot be referenced from a static context? Example
"non-static variable cannot be referenced from a static context" is the biggest nemesis of someone who has just started programming and that too in Java. Since the main method in java is the most popular method among all beginners and they try to put program code there they face "non-static variable cannot be referenced from a static context" compiler error when they try to access a non-static member variable inside the main in Java which is static. if you want to know why the main is declared static in Java see the link.
Labels:
core java
,
static modifier
Subscribe to:
Posts
(
Atom
)