How to declare and initialize an array in Java

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.

Each item in an array is called an element, and each element is accessed by its numerical index. As shown in the preceding illustration, numbering begins with 0. The 9th element, for example, would therefore be accessed at index 8.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

Create ArrayList from Array In Java

In this tutorial, I am showing how to Create ArrayList from array using java in different useful ways.

1) You can use Arrays.asList(array) to convert an array to an Arraylist.
2) If you are working with java 8 you can use stream api Stream.of(array).collect(Collectors.toCollection(ArrayList::new))

3) If you are working with java 9 you can use List.of("Hello", "World"), where this list is backed by an array.

Iterate HashMap Using Java

In this tutorial, I am showing how to iterate through a HashMap using java in different useful ways.

If you are using Java 8 for the map iteration, you can use lambda expression as like method 5.

You can also use with generics as method 3, and without generics as method 4, if you are using old versions of jdk.

Convert Java String to InputStream

In this tutorial, I am showing how to convert Java String to InputStream using plain Java, Java 8 and Apache Commons IO library.

An InputStream is connected to some data streams like a file, memory bufferes, network connection, pipe etc. It is used for reading the data from above sources.

You can also check converting Java InputStream to String  (java InputStream to String)

Convert Java InputStream to String

In this tutorial, I am showing how to convert Java InputStream to String using Plain Java, Java 8, Apache Commons IO library and Guava.

An InputStream is connected to some data streams like a file, memory bufferes, network connection, pipe etc. It is used for reading the data from above sources.

You can also see an example for convert Java String to InputStream (java String to InputStream).

Anti Cross-Site Scripting (XSS) For Java Web Application

In this tutorial, I am showing how to protect cross site scripting (xss) attacks for a java web application.

Cross-site scripting (XSS) happens, when an attacker injects malicious client sides scripts in the application.

How can we prevent Cross-site scripting (XSS)?

We can prevent xss attacks through hibernate validator’s @safehtml, which prevents HTML tags for XSS protection. @safehtml ensure that it contains no malicious code, such as embedded <script> elements.

What Is Garbage Collection Log? How To Enable & Analyze?

Objects are created in the memory to service incoming requests. Once requests are serviced, newly created objects will become useless (i.e. garbage). This garbage must be evicted from the memory so that there is enough room created in the memory to service the new incoming requests. If there isn’t sufficient memory, the application can experience poor response times, OutOfMemoryError, and fatal crashes.

How to Avoid Liferay DXP Upgrading Pitfalls?

Timely upgrades can be proved a strategic move towards lifting the operational excellence to the next level. Experienced management individuals know very well that how the essential pieces of functionalities can greatly improve performance of process along with addressing the security challenges. Hence, they favor the technology upgrades anticipating reasonable amount of Return on Investment (ROI).

As Liferay DXP is a revolutionary version of Liferay enterprise portal launched in 2016, lot many organizations would rather opt for upgrading to Liferay DXP.