How to convert primitive int value to a Long object in Java?

Suppose you have an int variable but the part of the application is expecting a Long object, how do you convert a primitive int to a Long object in Java? It shouldn't be a problem, right? after all long is a bigger data type than int, so all int values are acceptable as long, but we also need a Long object, not just the long primitive value. Now, the problem is reduced to converting a long primitive to Long object, which is not really a problem if you are running on JRE version higher than Java 5. But, sometimes autoboxing is not efficient e.g. when you have to convert multiple long values into the Long object in a loop. A better way to convert your long primitive to the Long object is by using static factory methods like Long.valueOf(long l), which was originally meant to convert long primitive values to a Long object, prior to Java 5, but, also works fine with int primitive.

ArrayList vs Vector in Java - Interview Question

ArrayList vs Vector in Java
ArrayList and Vector is two most widely used Collection class in Java and used to store object in ordered fashion. Every Java programmer which is introduced to Java Collection Framework either started with Vector or ArrayList. For beginners Difference between Vector and ArrayList in Java  and LinkedList vs ArrayList are two most  popular Java Interview question. ArrayList vs Vector is not only important on interview perspective but also on effective use of Java Collection API. After reading this article you will know when to use Vector in Java, When to use ArrayList in Java and would be able to compare ArrayList vs Vector over several important parameters e.g. Speed, Synchronization, Code quality etc. Before seeing difference on Vector vs ArrayList, let's What is common between the.

How to convert comma separated String to ArrayList in Java - Example Tutorial

Suppose you have a comma separated list of String e.g. "Samsung, Apple, Sony, Google, Microsoft, Amazon" and you want to convert it into an ArrayList containing all String elements e.g. Samsung, Apple, Google etc. How do you do that? Well, Java doesn't provide any such constructor or factory method to create ArrayList from delimited String, but you can use String.split() method and Arrays.asList() method together to create an ArrayList from any delimited String, not just comma separated one. All you need to do is first split the given String on delimiter e.g. comma using the split() method, this will give you an array of String. Now, you can pass that array to Arrays.asList() method to create a List, but remember this would be fixed length list and not truly an ArrayList.

Java String Matches Example - Regular Expression Tutorial

String Matching Example in Java
String matches method in Java can be used to test String against regular expression in Java. String matches() method is one of the most convenient way of checking if String matches to a regular expression in Java or not. Quite often we need to write code which needs to check if String is numeric, Does String contains alphabets e.g. A to Z or a to Z, How to check if String contains a particular digit 6 times etc. There are so many cases in Java programming where we need regular expression. If you are familiar with Java's regular expression API than you must know about java.util.regex.Pattern and java.util.regex.Matcher class, these class provides regular expression capability to Java API. matches method of String class actually delegate request to these classes. Anyway regular expression can be best learn by seeing few examples and this is what we are going to do in this Java String matches example tutorial.

What is difference between Overloading and Overriding in Java

Overloading vs Overriding in Java
In last couple of articles we have seen What is method overloading and What is method overriding in Java and now we will see What is difference between overloading and overriding in Java. Overloading vs overriding is one of those frequently asked Java interview question which can not be ignored. Overloading vs Overriding has appeared in almost every Java interview, mostly at beginner and intermediate level e.g. 2 to 4 years experience. In fact most of those tricky Java interview Question came from Overloading and Overriding. It's one of the tricky fundamental to understand. In this article we will some important difference between Overloading and Overriding which not only help to understand concept better but also serves as good recap for Java interviews.

Top 10 Java Web Service Interview question answers

Java Web Services Questions and Answers
Web Services interview questions are part of J2EE interviews for jobs which are looking some experience in Java web services Space. Most of the Web services questions come from two different way of implementing Web Services e.g. SOAP and REST. SOAP is an standard and mature way of calling Web Services which uses XML while REST is a new way of implementing Web Services which is based on HTTP protocol. In fact REST Web Service interview questions are getting more and more popular on web services interviews in Java, So if you are going for any Java J2EE interview which require some web service experience, be prepare with both SOAP and REST Web services questions. Following is list of Java web services interview questions which I have prepared for practice. Answers of these web services questions can be easily found in many places on Internet and I will update this list whenever I have new web services interview question. If you guys find any interesting tricky or tough Java web service question asked in Interviews then please share with us :

keytool command examples Java - add view ssl certificate in keyStore trustStore

keytool command in Java is a tool for managing certificates into keyStore and trustStore which is used to store certificate and requires during SSL handshake process. By using keytool command you can do many things but some of the most common operation is viewing certificate stored in keystore, importing new certificates into keyStore, delete any certificate from keystore etc. For those who are not familiar keyStore, trustStore and SSL Setup for Java application , Here is a brief overview on What is a trustStore and keyStore in Java. Both trustStore and keyStrore is used to store certificate signed by signer authority or CA (Certificate authority), with keyStore additionally storing personal certificate for client which is used during client authentication on SSL handshake process if its enable. In this article we will see some basic example of keytool command in Java to find how many certificates we have in keyStore , viewing those certificates, adding new certificates and deleting old certificates from keyStore or trustStore in Java.

10 Linux and UNIX Interview Questions and Answers asked in Wipro TCS Capegemini

UNIX and Linux Interview Questions and Answers
Questions from various UNIX operating systems e.g. Solaris, Linux, IBM AIX or any other UNIX operating system is asked on different support and programming interviews. I have always seen few interview questions from Linux and UNIX along with SQL in almost every Java programming interviews. You just can not afford not to prepare questions from UNIX and Linux until your Job absolutely doesn't require any work in UNIX operating system. I have collected many UNIX command interview questions and already shared them but I found that except system admin jobs, many programming job interviews only focus on general UNIX commands e.g. chmod, find or grep and fundamentals like finding files and directories, managing file space, networking commands, checking process status and managing file permissions.

Difference between ServletConfig and ServletContext in JSP Servlet J2EE

Difference between ServletConfig and ServletContext
ServletContext and ServletConfig these two are important interface of Servlet API which is used by Java J2EE programmer during web application development. Correct understanding of What is ServletContext and ServletConfig is very important for any J2EE application developer. Apart from that Difference between ServletContext and ServletConfig are a popular Servlet JSP interview questions and mostly asked on both fresher and experienced Java programmer during J2EE interviews. Both ServletContext and ServletConfig are basically configuration objects which are used by servlet container to initialize various parameter of web application. But they have some difference in terms of scope and availability so first we see what is ServletContext and ServletConfig objects are and then we will see difference between ServletConfig and ServletContext in Java J2EE.

Rules of Method Overloading and Overriding in Java

The overloading and overriding rule in JavaSince you can either overload or override methods in Java, its important to know what are the rules of overloading and overriding in Java. any overloaded method or overridden method must follow rules of method overloading and method overriding to avoid compile time error and logical runtime errors;  where you intend to override a method but method get overloaded. That is not uncommon and happen several times when Java programmer tries to override equals in Java or  overriding compareTo method in Java while implementing Comparable interface, which accepts Object type of argument. From Java 5 onwards which introduces @Override annotation along with Enum, Generics and varargs method you can completely avoid that problem.

Top 10 Tough Core Java Interview Questions Answers for Programmers

tough core Java interviews questions and answers
What is tough core java interview question ? Why do people look for tough Java questions before going for an interview? well, I don't think I need to answer these tough questions because it's pretty natural to prepare for tough questions even if you are not expecting tough questions from core Java. If you are prepared for tough and tricky Java interview question than you feel more confident and answer other Java interview question with confidence. On the other hand, if you are not prepared for tough and tricky core Java questions than seeing them on Java interview or written test may surprise you. But the definition of tough core Java questions is not universal, same Java question which is easy for one programmer might be tough for other Java programmer. That's why it's best to prepare your own list of tough interview questions before appearing on any Java job interview. In this article, I am going to share you with my Top 10 tough core Java interview questions and answers, which may help you in Java interview.

Palindrome: Java program to check number is palindrome or not

How to find if number is palindrome in Java
Checking whether a number is palindrome or not is a classical Java homework exercise. When you start learning Java programming most institute which teach Java  programming provides these classical Java programs like How to find Armstrong number in Java or how to find Fibonacci number in Java using recursion etc. Write a Java program to check if number is palindrome comes from same category. For those who are not familiar with palindrome numbers, palindrome number is a number which is equal to reverse of itself. For example 121 is a palindrome because reverse of 121 is 121, while 123 is not a palindrome in Java because reverse of 123 is 321 and 121!=321. Finding palindrome number is easy in Java, you just need to develop logic to reverse a number in Java. Thankfully Java provides couple of arithmetic operators like remainder(%) operator also known as modules operator, which returns remainder in division operator and division operator(/) which returns quotient. By using remainder and division operator in Java we can create program to check if number is palindrome or not.