How to Load Resources from Classpath in Java with Example

Classpath in Java is not only used to load .class files, but also can be used to load resources e.g. properties file, images, icon..

Already a Member? Log In to Your Account
  
This Blog Posts All Posts Directory Listings Articles

How to Load Resources from Classpath in Java with Example

07/30/2014 09:15:00 AM

Classpath in Java is not only used to load .class files, but also can be used to load resources e.g. properties file, images, icons, thumbnails, or any binary content. Java provides API to read these resources as InputStream or URL. Suppose, you have

Default, Defender or Extension Method of Java 8 with Example

07/28/2014 09:49:00 AM

Java 8 now allows you to add non-abstract method implementations to interfaces by utilizing the default and static keyword. Methods with default keyword are known as default methods or defender methods in Java. Before Java 8, it was virtually impossi

Java ArrayList and HashMap Performance Improvement in JDK 1.7| Empty List and Map will Cost Less Memory

07/23/2014 09:18:00 AM

From long time one reason for me to update to newer Java version was always bug fix and performance improvement. Apart from major changes like Generics in Java 1.5 and Lambdas in Java 8, there are so many small improvements, performance optimization

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

07/17/2014 09:44:00 AM

TCP and UDP are two transport layer protocols, which are extensively used in internet for transmitting data between one host to another. Good knowledge of how TCP and UDP works is essential for any programmer. That's why difference between TCP an

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

07/14/2014 09:58:00 AM

One of the classical program to build programming logic is, write a program to find largest of three numbers. I am sure many of you have already done this exercise in variety of languages including C, C++, C#, JavaScript, Perl, Ruby, PHP etc. This ti

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

07/10/2014 09:19:00 AM

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number, since 1**3 + 5**3 + 3**3 = 153, 371 is an Armstrong number since 3**3 + 7**3 + 1**3

Top 5 Java Performance Tuning Books - Best of Lot, Must read

07/08/2014 07:59:00 AM

Why Java developer should read a book on Performance tuning? When I first faced this question long time back, I thought I will do it later, but I never get back to that for a long time. I realize my mistake of having lack of knowledge on performance

Top 50 Java Thread Interview Questions Answers for Freshers, Experienced Programmers

07/02/2014 08:28:00 AM

You go to any Java interview, senior or junior, experience or freshers,  you are bound to see couple of questions from thread, concurrency and multi-threading. In fact this built-in concurrency support is one of the strongest point of Java programmi

How to create Custom Exception in Java - Tutorial Example

06/30/2014 08:54:00 AM

Sometime we need to create custom Exception in Java, i.e. Exceptions which are not defined in JDK or any third party library your application is using. Though it’s widely recommended on several Exception best practices article, even Joshua Bloch ha

How to use CopyOnWriteArraySet in Java with Example

06/26/2014 08:09:00 AM

CopyOnWriteArraySet is little brother of CopyOnWriteArrayList class. These are special purpose collection classes which was added on JDK 1.5, along with their most popular cousin ConcurrentHashMap. They are part of concurrent collection framework and

20 Fancy Acronyms Programmers should know?

06/23/2014 08:26:00 AM

Do you read blogs on Internet? Do you understand what TL;DR or ITT means, Well I didn't, not until last year. Internet is full of acronyms. Techies, programmers, developers and bloggers has developed a lot more fancy acronyms than you can think o

How to Count number of Set bits or 1's in Integer on Java?

06/17/2014 09:55:00 AM

There are multiple ways to count number of 1's or set bits in a integer number in Java. You can use bitwise and bit shift operator by your own, or, you can use Java API to count number of set bits. Java 1.5 added two utility method called bitCoun

Is Java Compiled or Interpreted Programming language?

06/11/2014 09:49:00 AM

One of the first question a graduate C or C++ programmer, who has just started learning Java ask is, whether Java is a compiled language or an interpreted one? On academic courses or during college, students learn a lot of languages e.g. VB, C, C++ a

SynchronousQueue Example in Java - Produer Consumer Solution

06/09/2014 09:44:00 AM

SynchronousQueue is special kind of BlockingQueue in which each insert operation must wait for a corresponding remove operation by another thread, and vice versa. When you call put() method on SynchronousQueue it blocks until another thread is there

Exception in thread "main" java.lang.ExceptionInInitializerError in Java Program

06/06/2014 09:23:00 AM

JVM throws java.lang.ExceptionInInitializerError, when there is an Exception inside static initializer block. If you know about static variable in Java, then you may know that they are initialized at the time of class loading. If there is an Exceptio

2 Examples to read Zip Files in Java, ZipFile vs ZipInputStream

06/03/2014 08:27:00 AM

ZIP format is one of the most popular compression mechanism in computer world. A Zip file may contains multiples files or folder in compressed format.  Java API provides extensive support to read Zip files, all classes related to zip file processing

jQuery Class and ID Selector Example Tutorial

05/31/2014 08:02:00 AM

One of the best thing of jQuery is there selectors, which gives jQuery enormous power to find and select DOM elements so easily. If you are coming from JavaScript background then you might love those classical methods e.g. getElementById() and getEle

Law of Demeter in Java - Principle of least Knowledge - Real life Example

05/28/2014 08:50:00 AM

Law of Demeter also known as principle of least knowledge is a coding principle, which says that a module should not know about the inner details of the objects it manipulates. If a code depends upon internal details of a particular object, there is

Double Checked Locking on Singleton Class in Java

05/26/2014 09:47:00 AM

Singleton class is quite common among Java developers, but it poses many challenges to junior developers. One of the key challenge they face is how to keep Singleton class as Singleton? i.e. how to prevent multiple instances of a Singleton due to wha

Why use SerialVersionUID inside Serializable class in Java

05/22/2014 10:42:00 AM

Serialization and SerialVersionUID is always remains a puzzle for many Java developers. I often see questions like what is this SerialVersionUID, or what will happen if I don't declare SerialVersionUID in my Serializable class? Apart from complex

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 - Solving Array IndexOutOfBoundsException in Java

05/19/2014 09:40:00 AM

If you are coming from C background than there is pleasant surprise for you, Java programming language provides implicit bound checks on Array, which means an invalid array index access is not allowed in Java and it will result in java.lang.ArrayInde

How to find Prime Factors of Integer Numbers in Java - Factorization

05/16/2014 10:41:00 AM

One of the common homework/task in programming courses is about Prime Factorization. You are asked to write a program to find prime factors of given integer number. The prime factors of a number are all of the prime numbers that will exactly divide

10 Articles Every Programmer Must Read

05/13/2014 09:35:00 AM

Being a Java programmer and Software developer, I have learned a lot from articles titled as What Every Programmer Should Know about ..... , they tend to give a lot of useful and in-depth information about a particular topic, which otherwise is very

tibrvnative.dll : Can't load IA 32-bit .dll on a AMD 64-bit platform - Windows 8

05/10/2014 09:44:00 AM

Can't load IA 32-bit .dll on a AMD 64-bit platform is a generic error, which comes when a 64-bit process tries to load a 32-bit dll, but when it comes its not that easy to resolve. One of my reader was getting this error tibrvnative.dll : Can'

Open source Java Libraries to Create PDF documents - iText vs Apache FOP

05/07/2014 09:19:00 AM

PDF format is a popular format for sending receipt, email confirmation and other documentation and we often has requirement to create PDF documents using Java, mostly in JSP pages. Since most of official documentation uses PDF format now days, it bec

How String in Switch works in Java 7

05/05/2014 09:16:00 AM

Ever Since Java allows using String variable in switch and case statements, there are many programmers using this feature in code, which can be better written using integer and enum pattern. This was one of the popular features of JDK 7 release, inc

Top 5 Cloud Service Providers and Companies, Java IT professionals Should Know

05/02/2014 08:58:00 AM

Cloud computing is Hot, it's the biggest IT trend of last few years and will continue to grow strong in coming future. Cloud computing provides several not-so-easy-to-ignore advantages, especially to public and small enterprises, which cannot aff

Difference between Connected vs Disconnected RowSet in Java JDBC | RowSetProvider, RowSetFactory Example

04/28/2014 08:53:00 AM

RowSet interface is another key interface from JDBC API, which extends the ResultSet interface to provide support for the JavaBean component model. Along with convenient methods to set connection parameters e.g. setUrl(), setUsername(), setPassword()

How to Convert Byte Array to InputStream and OutputStream in Java

04/25/2014 09:52:00 AM

Are you stuck with your coding because you have a byte array and next method in chain needs an InputStream? don't worry Java has solution for that, You can use ByteArrayInputStream to convert byte array to InputStream in Java. This class takes a

Difference between State and Strategy Design Pattern in Java

04/22/2014 09:30:00 AM

In order to make proper use of State and Strategy design Pattern in Core Java application, its important for a Java developer to clearly understand difference between them. Though both State and Strategy design patterns has similar structure, and bot

10 JDK 7 Features to Revisit, Before You Welcome Java 8

04/15/2014 09:13:00 AM

It's been almost a month Java 8 is released and I am sure all of you are exploring new features of JDK 8. But, before you completely delve into Java 8, it’s time to revisit some of the cool features introduced on Java 7. If you remember, Java 6

How to fix org.hibernate.MappingException: Unknown entity Exception in Java

04/12/2014 23:45:00 PM

If you have used Hibernate with JPA and using annotation to declare your entity bean then you might have seen this confusing error called "org.hibernate.MappingException: Unknown entity". This error message is so misleading that you could easily lose

Difference between FileInputStream and FileReader in Java | InputStream vs Reader

04/10/2014 08:38:00 AM

Before going to explain specific difference between FileInputStream and FileReader in Java, I would like to state fundamental difference between an InputStream and a Reader in Java, and when to use InputStream and when to go for Reader. Actually, Bot

For Each loop Puzzle in Java

04/09/2014 01:54:00 AM

From Java 5 onwards, we have a for-each loop for iterating over collection and array in Java. For each loop allows you to traverse over collection without keeping track of index like traditional for loop, or calling hasNext() method in while loop usi

Dealing with org.hibernate.LazyInitializationException: could not initialize proxy - no Session in Hibernate Java

04/06/2014 02:50:00 AM

If you are working in Hibernate framework, then you know that one of the key feature of Hibernate is "lazy initialization", which allows framework to lazily initialize dependencies, relationship or association lazily from database on need basis. For

How to replace line breaks , New lines from String in Java.- Windows, Mac or Linux

04/04/2014 10:02:00 AM

We often need to replace line terminator characters, also known as line breaks e.g. new line n and carriage return r with different characters. One of the common case is to replace all line breaks with empty space in order to concatenate multiple l

Difference between Stub and Mock object in Java Unit testing - JUnit

04/02/2014 08:51:00 AM

JUnit is the most popular framework for unit testing Java code. Unit testing is used to test a single programming unit e.g. a class or a method, in-fact many Java developer write unit test on per method basis. Stub and Mock objects are two concepts w

How to use EnumSet in Java with Example

03/31/2014 09:55:00 AM

EnumSet is one of the specialized implementation of Set interface for enumeration type, introduced in Java 1.5 along with enumeration type itself. Programmer often stores Enum into common collection classes e.g. HashSet or ArrayList, mostly because t

Hibernate NullPointerException due to Space in HQL named queries

03/29/2014 00:05:00 AM

If you are using Hibernate for implementing persistence layer in Java and JEE application from couple of years then you would have seen this notorious NullPointerException while executing HQL named queries, Exception in thread “main” java.lang.Nu

3 ways to Find First Non Repeated Character in a String - Java Programming Problem

03/27/2014 09:44:00 AM

Write a Java program to find first non repeated character in a String is a common question on coding tests. Since String is a popular topic in various programming interviews, It's better to prepare well with some well-known questions like reversi

Difference between WeakReference vs SoftReference vs PhantomReference vs Strong reference in Java

03/25/2014 09:53:00 AM

WeakReference and SoftReference were added into Java API from long time but not every Java programmer is familiar with it. Which means there is a gap between where and how to use WeakReference and SoftReference in Java. Reference classes are particu

Binary Search vs Contains Performance in Java List

03/21/2014 10:18:00 AM

There are two ways to search an element in a List class, by using contains() method or by using Collections.binarySearch() method. There are two versions of binarySearch() method, one which takes a List and Comparator and other which takes a List and

2 Examples of Streams with Collections in Java 8

03/19/2014 08:44:00 AM

Finally Java 8 is here, after more than 2 years of JDK 7, we have a much expected Java 8 with lots of interesting feature. Though Lambda expression is the most talked item of coming Java 8 release, it wouldn't have been this much popular, if Coll

How to Check if a Number is Binary in Java - Programming Problem

03/17/2014 08:35:00 AM

Today we will take a look on another simple programming exercise, write a program to check if a number is binary in Java. A number is said to be binary if it only contains either 0 or 1, for example 1010 is binary number but 1234 is not. You can not

Why use Underscore in Numbers from Java SE 7 - Underscore in Numeric Literals

03/13/2014 09:14:00 AM

JDK 1.7 release had introduced several useful features, despite most of them being syntactic sugar, there use can greatly improve readability and code quality. One of such feature is introduction of underscore in numeric literals. From Java 7 onwards

How to Clone Collection in Java - Deep copy of ArrayList and HashSet

03/11/2014 09:13:00 AM

Programmer often mistook copy constructors provided by various collection classes, as a mean to clone Collection e.g. List, Set, ArrayList, HashSet or any other implementation. What is worth remembering is that, copy constructor of Collection in Java

Top 10 MQ Series Interview Questions Answers - WebSphere and Active MQ

03/05/2014 07:32:00 AM

MQ Series Interview Questions and Answers are collection of some of the questions asked on various MQ implementation e.g. IBM WebSphere MQ, Active MQ or Sonic MQ from different core Java and Enterprise Java (JEE) interviews. Most of these questions a

Covariant Method Overriding of Java 5 - Coding Best Practices

03/03/2014 07:24:00 AM

Sometime knowledge of a specific Java feature can improve code quality, Covariant method overriding is one of such feature. Covariant method overriding was introduced in Java 5, but it seems it lost between other more powerful features of that releas

Why Catching Throwable or Error is bad?

02/28/2014 07:10:00 AM

We often hear advice that catching Throwable or Error is bad practice and Java developer should avoid catching these, but have you thought Why? If language allows you to catch anything which is instance of java.lang.Throwable, then what is the proble

10 Example of Lambda Expressions and Streams in Java 8

02/26/2014 08:22:00 AM

Java 8 release is just a couple of weeks away, scheduled at 18th March 2014, and there is lot of buzz and excitement about this path breaking release in Java community. One of feature, which is synonymous to this release is lambda expressions, which

How to Format and Display Number to Currency in Java - Example Tutorial

02/24/2014 06:58:00 AM

Displaying financial amount in respective currency is common requirement in Java based E-commerce applications. For example if you are selling products on-line globally, you will show price of product in their local currency rather than USD or some o

Fixing java.net.BindException: Cannot assign requested address: JVM_Bind in Tomcat, Jetty

02/21/2014 08:57:00 AM

Some of the most dreaded error in Java based client server based application is networking related error, e.g. java.net.BindException: Cannot assign requested address: JVM_Bind. I have faced this issue, while working with web servers like Tomcat, Jet

Top 30 Java Phone Interview Questions Answers for Freshers, 1 to 2 Years Experienced

02/19/2014 08:57:00 AM

In this article, I am sharing 30 core Java technical questions, from screening and phone round of interviews. In telephonic interviews, questions are short, fact based and Interviewer expects some keyword in answers. Accordingly, I have given very sh

How to Create Tabs UI using HTML, CSS, jQuery, JSP and JavaScript

02/17/2014 07:06:00 AM

JSP is still a popular technology for developing view part of Struts and Spring based Java application, but unfortunately it doesn't have rich UI support available in GWT, or any other library. On other day, we had a requirement to display HTML

Why Static Code Analysis is Important?

02/14/2014 07:00:00 AM

From last few years, Software code quality and security has went from being a “nice to have” to a necessity, and many organizations, including investment banks are making it mandatory to pass static code analysis test, penetration testing and sec

Display tag Pagination, Sorting Example in JSP and Servlet

02/11/2014 08:12:00 AM

If you are a Java programmer, writing JSP pages for your web application and doesn't know much about JavaScript, jQuery, CSS and HTML, then display tag is best for creating dynamic tables, pagination, sorting, and exporting data into PDF, Word an

Java Comparable Example for Natural Order Sorting

02/07/2014 21:50:00 PM

Java allows you to sort your object in natural order by implementing Comparable interface. It's one of the fundamental interface of Java API and defined in java.lang package, which means you don't need to implement this unlike its counterpart

Difference between Association, Composition and Aggregation in Java, UML and Object Oriented Programming

02/05/2014 09:52:00 AM

In Object-oriented programming, one object is related to other to use functionality and service provided by that object. This relationship between two object is known as association in  object oriented general software design, and depicted by an arr

StringTokenizer Example in Java with Multiple Delimiters

02/02/2014 01:20:00 AM

StringTokenizer is a legacy class for splitting strings into tokens. In order to break String into tokens, you need to create a StringTokenizer object and provide a delimiter for splitting string into tokens. You can pass multiple delimiter e.g. you

Top 5 Hibernate Books for Java Developers - Best, Must read

01/28/2014 08:09:00 AM

Hibernate is one of the most popular, open source ORM (Object Relational Mapping) framework, which has now become an standard for developing persistence layer on Java enterprise application, along with JPA (Java Persistence API). I often receive requ

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

01/24/2014 22:48:00 PM

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 criterion, we need to create multiple comparators e.g. NameComparator, AgeComparator and SalaryCom

10 Tips to Improve Programming Skill and become better Programmer, Developer

01/21/2014 08:52:00 AM

Many Java developers ask me How to become better programmer, how do I improve my programming skills, or I am good at Java but not so good on problem solving skill etc. This is reality, today's era is full of language expert than real programmers.

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

01/18/2014 07:14:00 AM

If you are using Eclipse in your company, you might have faced issues, where Eclipse is not able to connect to internet. Since most of companies uses proxy for connecting to Internet, its important to configure proxy settings in Eclipse to allow Ecli

Why Default or No Argument Constructor is Important in Java Class

01/15/2014 08:13:00 AM

Almost all Java developers knows that compiler adds a default constructor or better known as no argument constructor in every Java class, but many of them forget that, it only does when you don't provide any other constructor. Which means it beco

Why Java Certifications are Good for Freshers and Junior Developers?

01/11/2014 04:31:00 AM

I have seen many Java programmers in doubt whether to go for certifications or not? Should I go for OCPJP 7 or not, is a common doubt among young graduate and a Java developer with few years of experience under his belt. Well, getting certified and r

Top 5 Free Scala Programming Books for Java Programmers, Download as PDF or Read Online

01/08/2014 08:00:00 AM

Scala is another JVM based programming language, which is quickly gaining popularity because of its interesting mix of object oriented and functional programming paradigm. Many companies has started using Scala for there strategic and mission critica

How to Remove Objects from Collection or ArrayList in Java while Traversing - Iterator remove() method Example

01/06/2014 07:48:00 AM

How do you remove objects from Java collections like ArrayList, while iterating is one of the frequent questions my reader asked to me in my post about Top 25 Java Collection Interview Questions. Well, this question may seems quite easy, because eve

How to Remove Duplicates from Array without using Java Collection API

01/04/2014 00:32:00 AM

This is a coding questions recently asked to one of my reader in a Java Technical interview. Question was to remove duplicates from an integer array without using any collection API classes like Set or LinkedHashSet, which can make this task trivial.

Does Java Certifications like SCJP, OCJP or OCPJP helps in Job and Career?

01/01/2014 08:34:00 AM

First of all, Wish you very Happy New Year 2014 !!, May god brings success to you all. I receive lots of questions about usefulness of Java certifications like SCJP, now known as OCJP or OCPJP. Questions like, does doing Java Certification helps land

Inter Thread Communication in Java using Wait Notify Example

12/30/2013 06:43:00 AM

Wait and notify methods in Java are used for inter-thread communication i.e. if one thread wants to tell something to another thread, it uses notify() and notifyAll() method of java.lang.Object. Classical example of wait and notify method is Producer

How to redirect a page or URL using JavaScript and JQuery

12/25/2013 06:24:00 AM

Redirecting a web page means, taking user to new location. Many website use redirect for many different reasons, e.g. Some website redirect user from old domain to new domain, some redirect from one page to another e.g. a more relevant page. If you a

JUnit Testing Tips - Constructor is Called Before Executing Test Methods

12/19/2013 08:20:00 AM

Most of Java programmers either use JUnit or TestNG for there unit testing need, along with some mock object generation libraries e.g. Mockito, but not everyone spend time and effort to learn subtle details of these testing libraries, at least not in

How to configure Log4j in Java program without XML or Properties File

12/12/2013 08:18:00 AM

Sometime configuring Log4j using XML or properties file looks annoying, especially if your program not able to find them because of some classpath issues, wouldn't it be nice if you can configure and use Log4j without using any configuration file

When to make a method final in Java

12/04/2013 08:40:00 AM

Final keyword in Java is not as mysterious as volatile or transient, but still it creates lot of doubts on programmers mind. I often receives questions like, When to make a method final in Java or When to make a method static in Java, later I answere

© 2006-2014 OnToplist.com, All Rights Reserved