Resolving 'LoadLibrary failed - a DLL initialization routine failed' error There might be other reasons for this error as well, but the most...| geekexplains.blogspot.com
Why String has been made immutable in Java?Though, performance is also a reason (assuming you are already aware of the internal String pool maintained for making sure that the same String object is used more than once without having to create/re-claim it those many times), but the main reason why String has been made immutable in Java is 'Security'. Surprised? Let's understand why.Suppose you| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Does 'static' cause Memory Leak in Java?What's memory leak? In simple terms, it's unused but referenced (somehow because the programmer probably unintentionally forgot to remove the references once the use of the object was over) part of the memory. Before we start discussing if 'static' can cause memory leak in Java, let me assure you that whatever you've read about Garbage Collectors in Java,| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
What are Marker Interfaces in Java?An empty interface having no methods or fields/constants is called a marker interface or a tag interface. This of course means if the interface is extending other interfaces (directly or indirectly) then the super interfaces must not have any inheritable member (method or field/constant) as otherwise the definition of the marker interface (an entirely empty| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Connecting to an HTTP Web Service from VBA Excel via a Proxy ServerThough MSDN suggests using stubs generated from the WSDL by MS Soap Toolkit for connecting to an HTTP Web Service from within VBA Excel, but it might not work as you would like it to, especially for a SOA-compliant web service and particularly in the cases where you need to access the service via a Proxy Server.I have used the| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Why wait(), notify() and notifyAll() methods have been defined in the Object class?Java concurrency model uses locks to implement mutually exclusive access to objects in a multi-threaded environment and locks are associated with every object in Java (of type 'Object'), not only with Threads.wait, notify/notifyAll methods are used by threads to communicate with each other while trying to access a| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Usage of ThreadLocal: per-thread Singleton and per-thread LoggingShould you require a refresh of what ThreadLocals in Java are and how they work, refer to this article first. You can then proceed with the current article for understanding two of the most common uses of ThreadLocals in Java.per-thread Singleton impl using ThreadLocalSuppose you have a need of having a JDBC Connection objects per| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Choosing the Most Specific Method - Tricky Method OverloadingLet's start with looking at a code-segment and try to think of the output/error, it would produce when compiled/executed and subsequently we'll discuss the behavior of code.public class NullTest { public static void method(Object obj){ System.out.println("method with param type - Object"); } public static void method(String| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Initializer Blocks in Java and their possible alternativesInitializer Blocks - what are they, why & how are they used?These blocks are similar to the static initialization blocks with the only difference being the absence of the 'static' keyword. The Java compiler copies all the initializer blocks in the same order as they are in the source code in every constructor before any executable| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Static Initialization Blocks and their alternatives in JavaWhy do we need Static Initialization Blocks?The easiest way of initializing fields (static or instance) in Java at the time of their declaration is simply by providing a compile time constant value of a compatible data type. For example:public class InitializationWithConstants{public static int staticIntField = 100;private boolean| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
How to choose a suitable access control specifier of a method or a field?Access Control Modifiers available for classes and members in JavaTop-level classes in Java can have only two access control modifiers - public and default (package-private) whereas the members have four access control modifiers - public, protected, default (package-private), and private. Nested Classes are treated as| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Finding Caller object, method/class of an instance method in JavaYou might think if we would ever need it? Well... you may never, but no harm in exploring whether we have any/some ways of finding this in Java or not. This question was asked by one of our visitors - Marco Servetto. Thanks Marco for bringing this question up.For instance methods, by caller you might mean either the object instance| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Can we pass a new-line ('\n') character or any other escape sequence via command line in Java?One of our visitors (Vivek Athalye) asked this in response to the article - Tricky use of static initializer block. Thought of posting the answer as a separate article to increase the chances of it reaching to a wider range of audience.The answer to the query is NO. The question arises, if you pass the| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Can we get a different output without changing the main-method definition?public class HelloMain {/*** @param args*/public static void main(String[] args) { System.out.println("Mr. main.");}}Can we have the output of the above code-segment as "Hi, Mr. main. Bye!" without changing the main-method code?Yeah, we can have the required output by using 'static initializer' blocks effectively. As we| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
How to find whether a number is a power of 2 or not in Java?There can be many possible solutions to this problem, but probably the most efficient remains to be the one which uses bit-level manipulation wisely.We'll talk about only that solution here and since it involves bit-level manipulation of binary sequences, so should you require a refresh, first go through this article - 2's complement, 1'| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
2's Complement: Binary representation of negative numbers in JavaNegative numbers in Java are represented using 2's complement. As we know that integers in Java occupy 4 bytes so to understand how a negative integer (say -4) is represented internally in Java, we first need to find the binary equivalent of the positive value of the integer (in this case 4) and subsequently by finding the 2's| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Puzzle: There is a huge pile of quarters and a circular table. There are two people to play a game of placing the quarters down on the table alternately without any overlap. The one who can't put down a quarter loses. Assuming that the pile of quarters is non-exhaustive what will be your winning strategy? Whether you would like to start or let your partner start?Solution: The winning strategy| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Viewing/Editing files without having the required s/w or tools installedWonder what will you do in case you end up getting caught in a situation where none of the widely used tools/softwares (such as MS Office, Flash, File Viewers/Editors like Acrobat, etc.) are installed on a machine on which you need to at least view (or maybe edit if possible) some docs/files?Well... until recently it was| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
For those who have reached to this article directly, before we move on to discussing the implmenetation of a sample SAX-based XML parser in Java, they may like to refresh their understanding of SAX by referring to this article - Evolution of Java and XML combo. SAX, DOM, JAXP, JDOM >>Implementation of a SAX2-based XML parser in JavaWe will start with looking at the various steps involved in| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Differences between DOM and SAX. When to use what? Before going through the differences, if you need a refresh of what SAX and DOM are, please refer to this article - SAX, DOM, JAXP, & JDOM >>.While comparing two entities, we tend to see both of them as competitors and consequently comparing them to find a winner. This of course is not applicable in every case - not at least in the case| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Evolution of the XML Parsing/Manipulation using JavaThe combination of Java and XML has been one of the most attracting things which had happened in the field of software development in the 21st century. It has been mainly for two reasons - Java, arguably the most widely used programming language and XML, almost unarguably the best mechanism of data description and transfer.Since these two were| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Finding the name of a Class in Java from within a static methodOne of our regular visitors (Ranvijay) had asked it a couple of days back. Though, the code is pretty straightforward, I think it might help few others if posted as an article.One of the many possible ways of finding the name of the class in Java from within a static method is by using a static nested class, which will have a public| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
How to recover Shift + Deleted folders/emails in Microsoft Outlook?Ever wondered if you can really recover something in Windows, which you have Shift + Deleted? Well, you can do that at least in few cases (if not in all) - one of them being recovering folders/emails which you accidentally Shift + Deleted in your Microsoft Outlook (running with MS Exchange Server). I managed to delete one| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
Outlook Express v/s MS Outlook. How to choose one between the two?Outlook Express v/s Microsoft OutlookMany of you would already be aware of the main difference between the two. For those, who might not have cared to thought of it so far, here is the summary of the main difference(s) between the two messaging and collaboration clients delivered to us by Microsoft:-Outlook Express: it has been| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!
ThreadLocal in Java - what is it used for?As the name suggests this Java library class is used for supporting thread-local variables - the variables which are local to the particular thread instance and hence each thread will have their own copy of such variables which will be initialized every time a new thread is spawned.To be more clear, let's take one simple example. If you have a class| Geek Explains: Java, J2EE, Oracle, Puzzles, and Problem Solving!