The JSON format is one of the most popular formats to transfer and exchange data on the web. Almost all RESTful web services take JSON input and provide JSON output but unfortunately, JDK doesn't have built-in support for one of the most common web standards like JSON. As a Java developer if you want to develop a RESTful web service and produce JSON data or if you are developing a client to existing RESTFul web services and want to consume JSON response, you don't need to be disappointed. Fortunately, there are so many open source libraries and APIs available for creating, parsing, and processing JSON response in Java, like Jackson, Google GSon, json-simple, etc.
Saturday, September 7, 2024
Friday, September 6, 2024
10 Best Practices to Follow While Writing Code Comments
Comments are an important part of writing code not only in Java but whatever programming or scripting language you use. At the same time, this is one of the most abused things as well. Both writing no comment and writing too much comment is bad and this has been highlighted by many software gurus e.g. Robert C. Martin in his classic book Clean code. There is a whole chapter dedicated to How to write comments and finding the pros and cons of a comment. This article is my learning in the same direction, here I am going to share with you guys some 0f the rule and best practices I follow while writing comments.
Labels:
best of javarevisited
,
best practices
,
core java
,
programming
6 JDBC Performance Tips for Java Developers
JDBC Performance tips are a collection of some tried and tested ways of coding and applying process which improves the performance of JDBC code. The performance of core Java application or J2EE web application is very important, especially if its user database in the back end which tends to slow down performance drastically. do you experience your java j2ee web application being very slow (taking few seconds to process simple requests which involve database access, paging, sorting, etc) then the below tips may improve the performance of your Java application? these tips are simple in nature and can be applied to other programming language application which uses the database as back-end.
Dealing with Password in Java Application? 5 Best Practices You Should Follow
While working in core Java applications or enterprise web applications there is always a need of working with passwords in order to authenticate users. Passwords are very sensitive information like Social Security Number(SSN) and if you are working with real human data like in an online banking portal or online health portal it's important to follow best practices to deal with passwords or Social security numbers. here I will list down some of the points I learned and take care of while doing authentication and authorization or working with passwords. I recommend reading more on this topic and have a checklist of things based on your application requirement. Anyway here are few points which make sense to me:
Wednesday, September 4, 2024
How to create Immutable Class and Object in Java - Tutorial Example
Writing or creating immutable classes in Java is becoming popular day by
day, because of the concurrency and multithreading advantage provided by
immutable objects. Immutable objects offer several benefits over a
conventional mutable object, especially while creating concurrent Java
applications. Immutable object not only guarantees safe publication of
object’s state but also can be shared among other threads without any
external
synchronization. In fact, JDK itself contains several immutable classes like
String,
Integer, and other wrapper classes.
Labels:
best practices
,
coding
,
core java
,
core java interview question
What is difference between Enumeration and Iterator in Java? Answer
Though both Iterator and Enumeration allows you to traverse over elements of Collections in Java, there is some significant difference between them e.g. Iterator also allows you to remove elements from the collection during traversal but Enumeration doesn't allow that, it doesn't get remove() method. Enumeration is also a legacy class and not all Collection supports it e.g. Vector supports Enumeration but ArrayList doesn't. On the other hand, Iterator is the standard class for iteration and traversal. By the way, what is the difference between Enumeration and Iterator in Java?
Tuesday, September 3, 2024
Dealing with org.hibernate.LazyInitializationException: could not initialize proxy - no Session in Hibernate Java
If you are working in the Hibernate framework, then you know that one of the key features of Hibernate is "lazy initialization", which allows the framework to lazily initialize dependencies, relationships, or associations lazily from the database on a need basis. For example, if you are dealing with a User object, which has a relationship with a Permission object like one user can have multiple permissions, then Hibernate may choose not to initialize the collection which holds all permissions at the time it initialized User object and instead returns a proxy object.
How to fix org.hibernate.MappingException: Unknown entity Exception in Java? Solution
If you have used Hibernate with JPA and using annotation to declare your entity bean then you might have seen this confusing error called "org.hibernate.MappingException: Unknown entity". This error message is so misleading that you could easily lose anywhere between a few minutes to a few hours looking at the wrong places. I was using Spring 3 and Hibernate 3.6 when I got this error, which occurs when addEntity() method was executed. I checked everything, from Spring configuration file applicationContext.xml, Hibernate config file, my Entity class, and DAO class to see whether my Entity class is annotated or not, but I was still getting this error message.
Why JPA Entity or Hibernate Persistence Class Should Not be Final? Answer
One of the interesting hibernate interview questions is, why you should not make a Hibernate persistent class final? I'll try to answer this question in this short blog post. The use of proxies is the core feature of Hibernate (one of the most popular ORM frameworks for Java Projects) for implementing key performance features e.g. lazy loading and lazy associations fetching. In order to use a proxy in place of a real class, your hibernate persistence class must be either non-final or the implementation of an interface that declares all of the public methods.
Monday, September 2, 2024
10 Difference between Hibernate and JDBC in Java
JDBC is the core technology to access database from Java application but it require lot of boiler plate coding. Hibernate on the other hand an ORM (Object Relational Mapping) framework, which automatically map Java object to tables and records in database. You don't need to execute query to populate objects, Hibernate will do that for you. It also provides several benefit as compared to JDBC e.g. performance improvement via Proxy, lazy loading of associations and Caching, that's why both enterprise Java application and web application uses Hibernate to implement the DAO layer of application.
Labels:
hibernate
,
hibernate interview questions
,
JDBC
Tuesday, August 27, 2024
10 Examples of Conditional Breakpoint Debugging in Java and Eclipse
Eclipse is a great tool for Java developers, it allows you to write code, execute them and debug them but many developers doesn't use Eclipse to their full potential. I focus a lot of debugging skills when I take interviews and when I ask about how they debug their Java application, many developer mention use of line breakpoint and only few mention about conditional breakpoint. To be honest, if you are debugging a real-world Java application which has lots of users, clients or data then line breakpoint will not be very helpful and it will take ages to find the most of the data related issues.
For example, somewhere in your code you getting a NullPointerException and ArrayIndexOutOfBoundsException and you are not sure for which client, user or value this error came.
Monday, August 26, 2024
The 2024 Java Developer RoadMap [UPDATED]
Hello guys, I have been sharing a lot of roadmaps to become a Web developer, DevOps engineer, and recently React.js developer. One of the requests I received from many of my readers was for creating a Java Developer Roadmap. Since Java is my expertise, It wasn't a problem to create a Java Developer Roadmap, but it took slightly longer for me to create one because of the limited time I get. Anyway, I am finally ready to share my Java developer RoadMap with you. This Roadmap contains my years of experience and the unobstructed path of how to become a Java expert. It answers many burning questions like which technologies a Java developer should learn? What tools make you a better Java developer? And, which framework a Java developer must absolutely learn.
Labels:
best of javarevisited
,
core java
,
online resources
,
roadmap
Saturday, August 24, 2024
Top 10 Object-Oriented (OOP) Design Principles Java Programmers Should Know
The Object-Oriented Design Principles are the core of OOP programming, but I have seen most of the Java programmers chasing design patterns like Singleton pattern, Decorator pattern, or Observer pattern, and not putting enough attention on learning Object-oriented analysis and design. It's essential to learn the basics of Object-oriented programming like Abstraction, Encapsulation, Polymorphism, and Inheritance. But, at the same time, it's equally important to know object-oriented design principles. They will help you to create a clean and modular design, which would be easy to test, debug, and maintain in the future.
Labels:
best of javarevisited
,
core java
,
design patterns
,
programming
Top 5 Concurrent Collections Java Programmer Should Learn (with Examples)
Several new Collection classes are added in Java 5 and Java 6 especially concurrent
alternatives of standard synchronized
ArrayList, Hashtable
and synchronized
HashMap collection classes. Many Java programmer still not familiar with
these new collection classes from the java.util.concurrent package and
misses a whole new set of functionality which can be utilized to build more
scalable and high-performance Java application. In this Java tutorial, we will
some of the useful collection classes like ConcurrentHashMap,
BlockingQueue
which provides some of the very useful functionalities to build concurrent Java applications.
Labels:
best of javarevisited
,
core java
,
java collection tutorial
Friday, August 23, 2024
10 Example of this keyword in Java
this keyword in Java is a special keyword that can be used to represent the current object or instance of any class in Java. “this” keyword can also call the constructor of the same class in Java and is used to call overloaded constructor. In this Java tutorial, we will see how to use this keyword in Java and different examples of this in Java. this sometimes also associates with a super keyword which is used to denote an instance of the superclass in Java and can be used to call an overloaded constructor in Java.
Labels:
core java
Subscribe to:
Posts
(
Atom
)