Difference between ArrayList and HashSet in Java? Answer with Example
Java67
by javin paul
1M ago
ArrayList vs HashSet Java The main difference between ArrayList and HashSet is that one is a List implementation while the other is a Set implementation. It means all the differences between a List data structure and a Set data structure also apply to this pair. For example, List implementations are ordered, it stores the element in the order they were added, while Set implementation doesn't provide such a guarantee. Similarly, since List provides Random access, you can access any element directly if you know the index, but Set doesn't provide such a facility.  Java Interview questions ..read more
Visit website
Java.lang.IllegalStateException: getOutputStream() has already been called for this response
Java67
by javin paul
1M ago
This error comes when you call to include() or forward() method after calling the getOutputStream() from ServletResponse object and writing into it.  This error is similar to java.lang.IllegalStateException: getWriter() has already been called for this response error, which we have seen in the earlier article. This is the exception: org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502) org.apache.jasper.servlet.JspS ..read more
Visit website
6 Difference between forward() and sendRedirect() in Servlet - Answer
Java67
by javin paul
1M ago
Servlet in JEE platform provides two methods forward() and sendRedirect() to route an HTTP request to another Servlet for processing. Though both are used for forwarding HTTP requests for further processing there are many differences between the forward() and sendRedirect() method e.g. forward is performed internally by Servlet, but the redirection is a two-step process, where Servlet instructs the web browser (client) to go and fetch another URL, which is different from the original. That's why forward() is also known as a server-side redirect and sendRedirect() is known as the clie ..read more
Visit website
How to convert Enum to String in Java with Example
Java67
by javin paul
1M ago
Enum to String Conversion Example in Java There are two ways to convert an Enum to String in Java, first by using the name() method of Enum which is an implicit method and available to all Enum, and second by using toString() method. name() method of Enum returns the exact same String which is used to declare a particular Enum instance like in WeekDays Enum if we have MONDAY as one Enum instance then the name() will return String "MONDAY". This method of conversion from Enum to String is useful if the String representation of Enum is the same as its String name but if you have diffe ..read more
Visit website
How to fix java.lang.IllegalStateException: getWriter() has already been called for this response [Solution]
Java67
by javin paul
1M ago
This error comes when a Servlet calls the getOutputStream() method on the response object for writing something after calling the include() method. Suppose a Servlet calls the include() method to load the response of a JSP. Since JSP has already written the response on it hence again opening OutputStream on the response object is illegal, you get the java.lang.IllegalStateException: getWriter() has already been called for this response error. This error also comes when you try to include the response of another Servlet and then tries to write something on the output stream again. In short, you ..read more
Visit website
How to get Current Date and Time in Java with Example
Java67
by javin paul
1M ago
You can get today's date or current date and time in Java by creating a new Date() object. A java.util.Date object represents the current date and time instance in Java. Now, if you want to date in DDMMYYYY format or any other date format, you can easily convert the Date object to String by using SimpleDateFormat class. Since the Date instance contains both date and time, if you only need a date then you can further convert the java.util.Date to java.sql.Date. Similarly, if you need just time then you can convert the java.util.Date to java.sql.Time, they represent the date and time part of jav ..read more
Visit website
Difference between jsp:include and jsp:forward action- Example
Java67
by javin paul
1M ago
JSP provides standard actions to do things without using Java inside the scriptlet. Two of such standard actions, which help JSP to interact with other server resources e.g. another JSP, Servlet, or HTML files are, include and forward actions. The <jsp:forward> action enables you to forward an HTTP request to a static HTML file, a servlet, or another JSP. It has an attribute called page, which accepts the URL of another resource as shown below: <jsp:forward page="URL" /> Java Interview questions and tutorials ..read more
Visit website
How to Run a JAR file from Command Prompt - Windows and UNIX [Example]
Java67
by javin paul
1M ago
So you got a JAR file that contains your favorite Java game and you are wondering how to run a Java program from a JAR  file? Or you may be simply trying your hand after running the Java program from the command prompt and Eclipse IDE. Anyway, it's good to know How to execute Java programs from the JAR file, as the JAR file is the most popular way of shipping Java programs. JAR file usually contains all sources and resources in the form of class files, images, sound files, etc.  Java Interview questions and tutorials ..read more
Visit website
How to convert java.util.Date to java.sql.Timestamp in Java - JDBC Example
Java67
by javin paul
1M ago
You can convert java.util.Date to java.sql.Timestamp by first taking the long millisecond value using the getTime() method of Date class and then pass that value to the constructor of Timestamp object. Yes, it's as simple as that. For better code reusability and maintenance, you can create a DateUtils or MappingUtils class to keep these kinds of utility or mapping functions. Now, the question comes, why do you need to convert java.util.Date to java.sql.Timestamp?  Well, If you are storing date values to a database using JDBC, you need to convert a java.util.Date to its equivalent java.sq ..read more
Visit website
How to use Enum in Java? Example
Java67
by javin paul
1M ago
Enum is a useful feature of Java and the best way to represent a fixed number of things like the number of the planet in the solar system, the number of state orders can be, or simply a number of days in a week. Java Enum is different than its predecessor in other languages like C and C++, where the enum is just a wrapper around integer constant. Enum in Java is a full-blown type like class and interface, they can have a constructor (though only private constructors are permitted for Enum), they can override methods, they can have member variables, they can even declare methods, can imple ..read more
Visit website

Follow Java67 on FeedSpot

Continue with Google
Continue with Apple
OR