Converting local time into GMT or any other timezone in Java is easy as Java has support for time zones. JDK has a class called java.util.Timezone which represents timezone and Java also has classes like SimpleDateFormat which can use Time zone while parsing or formatting dates. By using java.uti.TimeZone and java.text.SimpleDateFormat we can write a simple Java program to convert local time to GMT or any other time zone in Java. We have already seen examples of How to get current date and time in GMT and this Java program is an extension of that in order to convert time form one timezone to other timezones.
Tuesday, July 27, 2021
What is rt.jar in Java/JDK/JRE? Why it’s Important?
rt.jar stands for runtime JAR and contains the bootstrap classes, I mean all the classes from Core Java API. I have found that many Java programmer doesn't know what is rt.jar? and often confused with the role of rt.jar file or why we use of rt.jar file in Java? No surprise, the name is a little bit cryptic. This file always resides inside the lib directory of JRE, at least in Windows and Linux. In MacOSX it resides at a different location and also has a different name i.e. classes.jar, but that is only prior to JDK 1.7. From Java 7 release Apple has stopped distributing Java and if you separately install, it will have the same name as rt.jar.
Labels:
core java
Java PropertyUtils Example - getting and setting properties by name
PropertyUtils class of Apache commons beanutils library is very useful and provides you the ability to modify properties of Java object at runtime. PropertyUtils enables you to write highly configurable code where you can provide the name of bean properties and their values from configuration rather than coding in Java program and Apache PropertyUtils can set those properties on Java object at runtime. One popular example of how powerful PropertyUtils can be is display tag which provides a rich tabular display for JSP pages, it uses PropertyUtils class to get values of an object at runtime and then display it.
Labels:
core java
,
jsp-servlet
What is Effectively Final variable of Java 8? Example
Apart from the big three, Lambda expression, Stream API, and new Date and Time API, Java 8 has also introduced a new concept called the "effectively final" variable. A non-final local variable or method parameter whose value is never changed after initialization is known as effectively final. It's very useful in the context of the lambda expression. If you remember, prior to Java 8, we cannot use a non-final local variable in an anonymous class. If you have to access a local variable ( a method parameter or a variable decreed in the method itself) in the Anonymous class, you have to make it final. This restriction is relaxed a bit with lambda coming up. Java designers have taken the need to make local variable final if it's not changed once initialized.
Top 10 JSP Interview Questions Answers for Java Programmer
These JSP interview questions and answers are asked in the various J2EE interview and focus on the view part of the MVC framework. JSP or Java Server Pages is a Java technology used to render a dynamic view. Whenever you go for any Java web developer interview there are always some interview questions on JSP. This article is a collection of some JSP interview questions which has asked in the various interview to my friends and colleagues. You can easily find answers to these JSP interview questions by google but I have included my version for quick reference.
5 Difference between Application Server and Web Server in Java?
Application server and web server in Java both are used to host Java web applications. Though both the application server and web server are generic terms, the difference between the application server and the webserver is a famous J2EE interview question. From on Java J2EE perspective, the main difference between the web server and application server is the support of EJB. In order to run EJB or host enterprise Java application (.ear) files, you need an application server like JBoss, WebLogic, WebSphere, or Glassfish, while you can still run your servlet and JSP or java web application (.war) file inside any web server like Tomcat or Jetty.
Display tag Pagination, Sorting Example in JSP and Servlet
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 and Excel format. Display tag is a JSP tag library, where code is written in Java but you can use them like HTML tags e.g. <display></display> . Though the display tag is an old library, I have always used it in JSP for displaying tabular data. It comes with sample CSS as well, which is good enough for many applications. Long time back, I have shared some display tag tips and examples, and many of my readers asked me to write about how to do pagination and sorting on the JSP page.
Labels:
display tag example
,
java
,
jsp-servlet
Bitwise and BitShift Operators in Java - AND, OR, XOR, Signed Left and Right shift Operator Examples
Bitwise and Bit Shift Operators in Java are a powerful set of operators
that allows you to manipulate bits on integral types like int, long, short,
bytes, and boolean data types in Java. Bitwise and Bit shift operator is among
the fastest operator in Java but still, many Java programmers don't familiar
with bitwise and bitshift operations, especially those who don't come from C programming
backgrounds. If you have already learned C or C++ before starting with Java
then understanding bitwise and bitshift operators
are quite easy in Java, because it's similar to the bitwise operation in C.
How to Install JDK on Windows - Java Programming Tutorial Example
Installing JDK is the first step in learning Java Programming. If you are
using Windows 8 or Windows 7 Operating System, then installing JDK is quite
easy as you just need to follow instructions given by the Java SE Installation
wizard. The only thing which requires some attention is, choosing the correct JDK
installer based upon, whether you are running with 32-bit or 64-bit Windows 8
or Windows 7 OS. JDK 7 is the latest Java version but JDK 6 is still most popular
in the software and programming world. You can choose to install JDK 7 or JDK 6 based
on your course material.
Labels:
core java
,
Java Programming Tutorials
,
windows 8
How to format Date and Time in SQL Server and Sybase? Examples
How to format a date in SQL Server like in the "yyyymmdd" format? Suppose you have a date and time column in Sybase or Microsoft SQL Server, which is displaying values in "Dec 31, 2011, 12:00 AM" and you want to display it in any particular DATE format like YYYYMMDD or DDMMYYYY, how will you do that? This is also one thing you need to keep in mind when you convert a DATE, TIME, DATETIME column into CHAR or VARCHAR values. It's easy to format dates using the convert function in Sybase or SQL Server, but it's slightly difficult to remember the cryptic formatting style codes that go with it. For example, using style code, 112 is used to format dates in the "YYYYMMDD" format e.g. "20170329".
Labels:
Microsoft SQL Server
,
SQL
,
Sybase and SQL Server
What is JSESSIONID in Java Web application - JSP Servlet? Example
What is JSESSIONID in JSP-Servlet
JSESSIONID is a cookie generated by Servlet containers like Tomcat or Jetty and used for session management in the J2EE web application for HTTP protocol. Since HTTP is a stateless protocol there is no way for Web Server to relate two separate requests coming from the same client and Session management is the process to track user sessions using different session management techniques like Cookies and URL Rewriting. If a Web server is using a cookie for session management it creates and sends JSESSIONID cookie to the client and then the client sends it back to the server in subsequent HTTP requests.
How to Export HTML to PDF, CSV, and Excel using Display Tag in JSP? Example
Display tag provides export options to export page into PDF, CSV, Excel, and XML in Java web application written using JSP, Servlet, Struts, or Spring
MVC framework. Display tag is a tag library and you just need to use it in your
JSP page to display tabular data or generate HTML tables dynamically. Earlier
we have seen 10 display tag tips for
getting most out of display tag and in this JSP Servlet tutorial we will see
one display tag export issue, which prevents display tag export functionality to
work properly.
Labels:
J2EE
,
jsp-servlet
,
programming
How to Configure HTTPS (SSL) in Tomcat 6 and 7 Java Web Server? Example
Setting SSL (Secure Socket Layer) in Tomcat is often a requirement, especially while developing secure web applications, which requires access over HTTPS protocol. Since the Tomcat web server doesn't provide SSL settings by default, you need to know how to configure SSL in Tomcat, and even worse it varies between different tomcat versions. for Example SSL setup which works on tomcat 6, doesn't work as it is in tomcat 7. In this article, we will see, how to configure tomcat for HTTPS in both tomcat 6 and 7. For those programmers who are not very familiar with SSL and HTTPS here is a quick overview of SSL, certificates and HTTPS, and I suggest reading that article to get a better understanding of How SSL works and How websites are accessed securely over the internet.
Labels:
core java
,
J2EE
,
jsp-servlet
JDBC - java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Solution
"java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" is a frequent Exception Java programmer face while writing JDBC connectivity code for MySQL, especially if you are trying to establish a JDBC connection to MySQL database first time. we have touched base on ClassNotFoundException in MySQL on our earlier articles on how to resolve ClassNotFoundException in Java and here we will see in detail what causes "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" and how to fix com.mysql.jdbc.Driver error in Java.
File Upload Example in Java using Servlet, JSP and Apache Commons FileUpload - Tutorial
Uploading Files to the server using Servlet and JSP is a common task in Java web applications. Before coding your Servlet or JSP to handle file upload requests, you need to know a little bit about File upload support in HTML and HTTP protocol. If you want your user to choose files from the file system and upload them to the server then you need to use <input type="file"/>. This will enable us to choose any file from the file system and upload to a server.
Labels:
core java
,
jsp-servlet
,
programming
Subscribe to:
Posts
(
Atom
)