How to String Split Example in Java - Tutorial

Java String Split Example
I don't know how many times I needed to Split a String in Java. Splitting a delimited String is a very common operation given various data sources e.g CSV file which contains input string in the form of large String separated by the comma. Splitting is necessary and Java API has great support for it. Java provides two convenience methods to split strings first within the java.lang.String class itself: split (regex) and other in java.util.StringTokenizer. Both are capable of splitting the string by any delimiter provided to them. Since String is final in Java every split-ed String is a new String in Java.

Top 10 Spring Interview Questions Answers J2EE

Spring framework interview questions are on the rise on J2EE and core Java interviews,  As Spring is the best framework available for Java application development and now Spring IOC container and Spring MVC framework are used as a de-facto framework for all new Java development. With this popularity interview, questions from spring framework are top on any list of  core Java Interview questions. I thought to put together some spring interview questions and answers which have appeared on many Java and J2EE interviews and useful for practicing before appearing on any Java Job interview. This list of Spring interview questions and answers contains questions from Spring fundamentals e.g. Spring IOC and dependency Injection, Spring MVC framework, Spring Security, Spring AOP etc, because of length of this post I haven't included Spring interview questions from Spring JDBC and JMS which is also a popular topic in core Java and J2EE interviews. I suggest preparing those as well.

Finally Eclipse supports JDK7 in Eclipse Indigo 3.7.1

Much awaited release of Eclipse with JDK7 is now over, Eclipse has announced release of version Indigo 3.7.1 which will support JDK7.though I already have downloaded Netbeans with JDK7 support I was eagerly waiting for my favorite java development IDE to comes with java7 support. I am expecting this to support all new java7 features including automatic resource management, string in the switch and multiple-cache block in exception handling. You can download the new Eclipse 3.7.1 version from here. You can also update your existing eclipse IDE with new feature from Menu-->Help-->Check for

There is not much in this release except JDK7 feature, no new feature has been introduced which will probably be released in either 3.8 or 4.2. Java community is still embracing JDK7 but sooner or later it will adopt it and my feeling is that it will happen very soon because it contains the similar features which JDK 1.5 was contained though not that significant but still pretty useful for day 2 day work.

eclipse with jdk7, eclipse indigo 3.7.1 with java7

Related Java tutorials

Code Review Checklist and Best practices in Java

What to review while doing Code review
Code Review and Unit testing is one of best development practice I always recommend, strive for and enforce as much as possible. Even just by doing code review and Junit test case always offer positive result it can be improved a lot by constantly learning with our mistakes , others mistakes and by observing how others are doing it. I always try to get my code review by some one with more experience so that I can capture any domain specific scenario which has been missed during think through process and some with less experience so that he can improve his code readability, have a four eye check and most importantly I found that when i explain my code to some one as part of code review I myself discover many things which can be improved or left out.Overall it always add something and improve code quality and reduce bug.

How to convert String to Date in Java - SimpleDateFormat Example

SimpleDateFormat in Java can be used to convert String to Date in Java. java.text.SimpleDateFormat is an implementation of DateFormat which defines a date pattern and can convert a particular String which follows that pattern into Date in Java.This is the second part of the article on java.util.Date and String in Java. In the first part, we have seen How to convert Date to String in Java. SimpleDateFormat accepts a String in any date format e.g. yyyyMMdd is a date pattern and  20110924 is a String in that format. Now you want to create a java.util.Date object from this String. In this Java tutorial, we will see list steps to convert String to Date in Java and then we will see different examples of SimpleDateFormat with different date patterns e.g. ddMMyy or dd-MM-yyyy. Though converting String to Date is quite easy using SimpleDateFormat, but you need to remember that SimpleDateFormat is not thread-safe, which means you can not share the same instance of SimpleDateFormat between multiple threads. 

How to get google plus invites free

google + (plus) invites free

Hi guys as you know that google plus are a new social networking buzzes a google answer to facebook. But it’s different than facebook in terms of joining the site. It’s not open like facebook instead you need invites to join the google plus many of you might be already in google plus but for those who are not yet join google plus I have something to offer.

I have just joined the google plus thanks to my friend who invited me to join google plus and now I have many google plus invites left with me which I would  like to give you , my readers and anyone who is interested to joining google plus. I have been reading on google plus now and seeing how it is different than facebook. One good thing is that it provides more on privacy front and idea of google circle is quite nice. I am sure it will take a lot of time to topple facebook and its definitely a challenge for google but its a good networking service to join.

google plus invitees free

What you need to do to get google plus invites

Just drop your name and email address as comment and I will send you google invites. if you don't want to publish your email then let me know and I won't publish your comment but will send you the invites in your email.


How to write Production quality code?

We often here the term "production quality code" , some times in interview where interviewee asked to write production quality code for a particular function,sometimes discussion between developers and programmers and sometimes during code review. I know most of you familiar with the term but for those who wonder what is production quality code in simple terms its code which can bear the test of time in a production environment.

We all develop code in development, then test in QA and finally it gets released in production. But there are a lot of difference between test and prod and if you have not coded taking prod environment in mind most likely code will fail in prod or result in exceptions.So what makes production environment different than development environment? Here are few things which I noted:

Variable argument or Varargs methods from Java 5 with Example - Programming Tutorial

Variable argument or varargs in Java allows you to write more flexible methods which can accept as many argument as you need. variable arguments or varargs were added in Java 1.5 along with great language features like Java Enum, Generics, auto boxing and various others. Variable arguments a relatively small feature but useful for a developer who has been well aware about method and array. Some time we have a scenario that one method can take variable number of argument  and now with varargs from language makes it much easier. In this Java tutorial we will see How variable arguments makes it easy to write convenient method which can accept any number of arguments,  perfect candidates are sum() and average() kind of methods.

This article is in continuation of exploring features of Java programming language. I have already covered fork-join framework from Java 7 and automatic resource management or ARM blocks, if you haven't read them already you may find them useful.

10 examples of displaytag in JSP, Struts and Spring

Display tag is one of the best free open source libraries for showing data in tabular format in a J2EE application using jsp, struts or spring. it is shipped as tag library so you can just include this  in your jsp and add corresponding jar and there dependency in class-path and you are ready to use it. Display tag is my favorite solution for displaying any tabular data because of its inherent capability on paging and sorting. It provides great support for pagination on its own but it also allows you to implement your own pagination solution. On Sorting front you can sort your data based on any column, implement default sorting etc.

Difference between HashMap and HashSet in Java

HashMap vs HashSet is the most frequently asked question during any core java interview and interview is not said completed until they will not cover the Collection Framework and multi-threading interview and collections are uncompleted without Covering Hash Set and HashMap.
Both HashMap and HashSet are part of collection framework which allows us to work with a collection of objects. Collection Framework has their own interfaces and implementation classes. Basically, a collection is divided as Set Interface, List, and Queue Interfaces. All these interfaces have their own property also apart from they get from a collection like Set allows Collection of objects but forbids duplicate value, List allows duplicate along with indexing.Queue works on FCFS algorithm.

How to Convert Date to String in Java with Example

Some times we need to convert java.util.Date to string in java  may for displaying purpose I need it that while working on displaytag then I thought about this article  to list down various way of converting this in various ways, after some reading I found that SimpleDateFormat makes this quite easy. To get the feel of Date API in java and to familiarize ourselves with these classes we will see different examples of converting date to String in our application. Both DateFormat and SimpleDateFormat class belongs java.text package and they are very powerful and you can use them for conversion. it also good for parsing string into date and can be used to show in various locale also.

Difference between SendRedirect() and Forward() in JSP Servlet

Difference between SendRedirect and forward is one of classical interview questions asked during java web developer interview. This is not just applicable for servlet but also for JSP in which we can use forward action or call sendRedirect() method from scriptlet. Before examining difference on forward and SendRedirect let’s see what send Redirect method and forward method does.

SendRedirect ():  

This method is declared in HttpServletResponse Interface.

Signature: void sendRedirect(String url)

How to use Fork Join in Java 1.7 - Tutorial with Example

What is fork Join framework in Java: Already popular project coin of JDK7 release has presented a lot of good feature e.g automatic resource management, string in switch case, better exception handling in JDK7 etc. On of another important feature to note is fork-join as name implies it divide one task into several small task as a new fork means child and join all the fork when all the sub-tasks complete. Fork/join tasks is “pure” in-memory algorithms in which no I/O operations come into is based on a work-stealing algorithm. Concept of fork join would be much clear by following diagram.

InvokeLater and InvokeAndWait in Java Swing (an example tutorial)

Everyone who is doing programming in java swing has to come across invokeAndWait and invokeLater provided by SwingUtilites. In this java swing tutorial we will learn about both invokeLater() and invokeAndwait() method. In first part we will mostly focus on invokeLater and will find answers to questions like What is invokeLater, how to use invokelater in java swing, example of invokelater in swing etc while in second part of this invokeLater tutorial we will learn more about invokeAndWait method in java swing and will learn Why we need InvokeAndWait, how to use InvokeAndWait method in java Swing and differences between invokelater and invokeAndWait.

Finally, we will see a code example of both invokeLater and invokeAndWait in Swing and will be able to decide when to use invokeLater and when to use invokeAndWait while doing Swing programming.  We will also see famous Swing interview questions "difference between invokeLater and invokeAndWait" at the end of the article.

How to find IP Address from hostname in Windows Linux and Unix

IP Address from hostname in Windows and Linux
How many times in a day you have a hostname and you want to know the IP address? Host name to IP address and IP address to hostname conversion is one of frequent thing which we need to do for many things when dealing with networking command in Unix. For one command we need an IP address for other we need hostname even from bash script sometimes we require hostname and sometimes we look for IP address. networking commands are not as popular as find command or grep command but they are equally important and if you working in Windows or UNIX environment you must learn them and they should also be included in any list of Unix commands for beginners. By the way, In this hostname to IP address tutorial, I will show you how to get IP address from hostname or computer name in Unix or Linux and how to get hostname if you have IP address. If you are looking a way to do it via Java program then you can also see my post how to find IP address of localhost in Java.

Top 10 Java Swing interview questions answers asked in Investment banks

Java Swing is heavily used in developing trading application front end. Doesn’t matter whether its front office or middle office you will find swing GUI everywhere. Swing GUI is used to developed Order entry system, order monitoring GUI and for other tools which trader or operations can use on different trade life cycle. Due to it’s heavily usage there are lot of requirements of java swing developer in IB. In this post we will see some java swing interview questions asked in various interview. These swing interview questions are based on my experience as well as collected from friends and colleagues. So if you are going for any java swing development job interview you can use these java swing interview questions for practice, answers of swing question are also given.

How to work with transient variable in java (an example tutorial)

Transient keyword in java is comparatively less common than any other keyword like volatile.since transient is less common it becomes even more important to understand the correct usage of it. In One-word transient keyword is used in serialization process to prevent any variable from being serialized, so if you have any field which is not making sense to serialize, you can simply declare that as transient and it won't be serialized.In this article we will revise some basics like What is transient variable in java, why do we need transient variable and most importantly where should we use transient variable or which fields need to be declared as transient with example.

ARM- Automatic resource management in Java7 an example tutorial

ARM automatic resource management is  another attractive features of Java 7 and project coin. As name itself implies that now JVM is going to be handling all the external resource and make programmer free to bother about resource management.  If my java programmers use any external resources like file, printer or any devices to close after my program execution complete. Normally we close the resources which we have open in beginning of our program or we decide that if program finish normally how to manage the resource or if our program finish abnormally how to close the resource.

Difference between ArrayList and Vector in Java

ArrayList and Vector are two of most used class on java collection package and difference between Vector and ArrayList is one of the most frequently asked java interview question on first round or phone interview. Though it’s quite a simple question in my opinion but knowledge of when to use Vector over ArrayList or does matter if you are working on a project. In this article we will some point based difference between Vector and ArrayList in Java and trying to understand the concept behind those differences. Ultimate goal is to familiarize yourself with distinguish property of ArrayList and Vector. By the way Java 5 adds another implementation of List interface which is similar to Vector and ArrayList but provides better concurrency access than Vector, its called CopyOnWriteArrayList. By the way this is the third article on discussing about Collection interview question,  Difference between LinkedList and ArrayList  and   List vs Set are other popular interview questions based upon collection framework in Java.

2 solution of java.lang.OutOfMemoryError in Java

Everyone in java development faces java.lang.OutOfMemoryError now and then, OutOfMemoryError in Java is one problem which is more due to system's limitation (memory) rather than due to programming mistakes in most cases though in certain cases you could have a memory leak which causing OutOfMemoryError. I have found that even though java.lang.OutOfMemoryError is quite common basic knowledge of its cause and solution is largely unknown among junior developers. Beginners books like Head First Java doesn't teach you much about how to deal with this kind of error. You need real experience dealing with production systems, handling a large number of user sessions to troubleshoot and fix performance issues like running out of memory.