-->
Skip to main content

Posts

Showing posts with the label Java

Convert Java Instant to Date [2021]

Convert Java Instant to Date [2021] In this tutorial, We will Convert Java Instant to Date using Date.from(Instant instant) method. Java Instant to Date Example This example shows how to convert Java Instant to Date using Date.from(Instant instant) method. import java.time.Instant; import java.util.Date; public class JavaInstantNowToDate { public static void main(String[] args) { Instant instant = Instant.now(); System.out.println("Instant : " + instant); // Java Instant now to Date Date date = Date.from(instant); System.out.println("Java Instant to Date : " + date); } } Output: Instant : 2021-06-29T16:36:19.769Z Java Instant to Date : Tue Jun 29 16:36:19 IST 2021 Conclusion In this tutorial, we have covered how to convert Java Instant to Date using the Date class static method Date.from(Instant instant). Thanks for reading this tutorial so far. If you like this tutorial then please share it with your friends and colleagues. If you h

Convert calendar to date in java [2021]

Convert calendar to date in java [2021] In this tutorial, we will cover how to convert calendar to date in Java, Calendar class has static method Calendar.getInstance().getTime() which will give date class instance. Calendar to date in Java import java.util.Calendar; import java.util.Date; public class CalendarToDate { public static void main(String[] args) { //Creating calendar instance Calendar cal = Calendar.getInstance(); //Converting calendar to date Date date = cal.getTime(); //Output : Tue Jun 15 20:22:07 IST 2021 System.out.println(date); } } Output: Tue Jun 15 20:22:07 IST 2021 Conclusion In this tutorial, We have covered how to convert Calendar instance to date instance. Thanks for reading this tutorial so far. If you like this tutorial then please share it with your friends and colleagues. If you have any questions, doubts, suggestions, or feedback then please drop a comment and I'll try to answer your question. So what do you think about this

Solution : Improper Output Neutralization For Logs (CWE ID 117)

Solution: Improper Output Neutralization For Logs (CWE ID 117) Today we will give the solution for Improper Output Neutralization For Logs (CWE ID 117) which is one of the things that Veracode shows to fix the CRLF Injection. Why it Occured as Per Veracode documentation  A function call could result in a log forging attack. Writing untrusted data into a log file allows an attacker to forge log entries or inject malicious content into log files. Corrupted log files can be used to cover an attacker's tracks or as a delivery mechanism for an attack on a log viewing or processing utility. For example, if a web administrator uses a browser-based utility to review logs, a cross-site scripting attack might be possible. Thus if we don't fix this it will allow attackers to inject malicious content into our logs. Recommadation by documentation Avoid directly embedding user input in log files when possible. Sanitize untrusted data used to construct log entries by using a safe logging mec

Top 33 Hashmap Interview Questions in Java (+ Answers)

Top 33 Hashmap Interview Questions in Java Today we will discuss the Top 33 Hashmap Interview Questions in Java . In the earlier posts,  we had discussed Company-wise interview questions  IRIS Software Interview Questions in Java Kent CamEye Interview Questions in Java Fiserv Interview questions in Java NIIT Interview Questions in Java Let's see the Top 30 Hashmap Interview Questions in Java now...

Convert String Array to int array in java [2021]

Convert String Array to int array in java [2021] In today's programming world, We generally need to Convert String Array to int Array in Java, In this tutorial, we will cover  how to convert String Array to int Array in Java  using two approaches. Using the  Integer.parseInt method  of Integer class. Using the Stream API of Java 8.  Earlier we have covered different conversions like  Convert to String from Byte Array In Java ,  Convert String to Byte Array in Java  and  Convert Between Java Byte Array to Object In Java , Convert String to Array In Java  which is also similar to our current requirement. Let's dive in for our current tutorial... Convert String Array to int Array  1. Using Integer.parseInt method with for loop     We can convert String array to int array simply iterating one element at a time and then parsing that element to int form with the help of Integer.parseInt method.   Example : import java.util.Arrays; public class StringArrayToIntArray { public st

Single Dimensional Array In Java [2021]

Single Dimensional Array In Java [2021] This article will discuss all the details of the single dimensional array in java or one dimensional array in java . An array is a collection of similar type of elements which has contiguous memory location.  Single Dimensional Array in java is always used with only one subscript([]). A Single dimensional array behaves likes a list of variables. Array in Java is index-based, the first element of the array is stored at the 0th index, the 2nd element is stored on 1st index, and so on. Declaration of Single dimensional array in java To use anything in java, we must first declare it so to use array as well, we must declare it. Like normal variables, we must provide the data type of array and name of an array. Data type means the type of data we want to store in it. Then a name through which we will access the array elements. datatype[] arrayName; Or datatype arrayName[]; Or datatype []arrayName; datatype -- It is either primitive dat

NIIT Technologies Java Interview Questions for Experienced (3+)

NIIT Technologies Java Interview Questions for Experienced Today we will discuss NIIT Technologies Java Interview Questions for experienced developers having 3+ Years of Experience. In the earlier post, we had discussed  IRIS Software Interview Questions in Java ,  Kent CamEye Interview Questions in Java , and Fiserv Interview questions in Java .   Let's see the NIIT Java developer interview questions now... These questions are solely on the basis of the face-to-face interview given by people and collected thereafter. So let's get started... NIIT Java Interview Questions Face to Face Rounds      Core Java Interview Questions Write a program to print Fibonacci Series using recursion? What is the difference between hashtable and hashmap? How concurrency handles in the hashtable and hashmap? Is there any other alternative for concurrent collections in java?     Spring Interview Questions What is a Spring transaction? What is DI/IOC and what is the difference between constructor-ba

Fiserv interview questions in Java

Fiserv Interview Questions in Java Today we will discuss Fiserv Interview Questions in Java for experienced developers having 3+ Years of Experience. In the earlier post, we had discussed  IRIS Software Interview Questions in Java  and  Kent CamEye Interview Questions in Java .   Let's see the Fiserv Interview Questions now... These questions are solely on the basis of the telephonic interview given by people and collected thereafter. So let's get started... Fiserv Interview Questions Telephonic Rounds       Spring Boot Interview Questions What advantages does it provide? What is a spring initializer?         Core Java Interview Questions What is a race condition in java? What is the Deadlock condition in java and how to prevent it? We have a String s = ({)}(}) In this string we have to write logic to identify the missing opening or closing braces if any? We have a array = [12,25,-79,0,98,71], find the longest continuous array which have maximum sum.( Solution )     Hibernate I

Solution : java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.(I)V]

Solution : java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.<init>(I)V] This java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.<init>(I)V] happens when we compile our source class using common codec jar version 1.4 or more but at runtime , it founds common-codec jar either equal to 1.3 or lesser than that in which this constructor was not present. Exception Trace will look like this: java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.<init>(I)V at org.apache.http.impl.auth.BasicScheme.authenticate(BasicScheme.java:166) [httpclient-4.5.10.jar:4.5.10] at org.apache.http.impl.auth.HttpAuthenticator.doAuth(HttpAuthenticator.java:233) [httpclient-4.5.10.jar:4.5.10] at org.apache.http.impl.auth.HttpAuthenticator.generateAuthResponse(HttpAuthenticator.java:213) [httpclient-4.5.10.jar:4.5.10] at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:262) [httpclient-4.5.10.jar:4.5.10]

Solution : Table 'hibernate_sequence' doesn't exist

Table 'hibernate_sequence' doesn't exist  Maven + Eclipse + Hibernate 5 + Java 14 + Mysql and After successful project creation when application starts then hits the following error message  Table 'hibernate_sequence' doesn't exist. Tested with: 1, Hibernate 5.4.26 2. mysql-connector-java-8.0.22.jar 3. Java 14 4. Maven 3.6.3 Caused by: java.sql.SQLSyntaxErrorException: Table 'hibernate.hibernate_sequence' doesn't exist at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003) at org.hibernate.id.enhanced.TableStructure.executeQuery(TableStructure.java:216) at o

How to Reverse a String in Java [2021]

How to Reverse a String in Java [2021] This tutorial will show how to reverse a string in java using 7 different ways. how to reverse a string in java is a very common question that is being asked in interviews and also with different methods as there is no inbuilt method in the String class for string reversal. Few facts about String class 1. String class is immutable thus any change in string instance creates a new string object. 2. StringBuffer/StringBuilder class has an inbuilt reverse() method. 3. As StringBuffer is synchronized so StringBuilder is preferred over StringBuffer. So let's get started...  Here are the 7 different ways to reverse a string in java Reverse a string in java using for loop. Reverse a string in java using recursion. Using the built-in string reverse function in java of StringBuilder class/StringBuffer class. Converting String to Character Array and then swapping with iteration. Reverse string using the charAt method. Reverse a string in java 8. Re

Difference between double and float in java [2021]

Difference between double and float in java [2021] Both double  and float  are used to represent floating-point numbers in java, although there are similarities as well as differences between double and float in java. double can provide precision up to 15 to 16 decimal points whereas float provides precision up to 6 to 7 decimal places. double is more expensive in case of storage requirements . It requires 8 bytes to store a variable whereas float takes 4 bytes to store a variable. If memory is a constraint then it's better to use float than double. Here is one of the best book to learn Java: Core Java Volume 1 - Fundamentals by Cay S. Horstmann to learn more about similarities and differences between a float and a double data type in Java.  Let's discuss the differences in detail. Difference between double and float in Java 1. Suffix By default, float numbers are double in java. In order to store them in the float variable, you need to explicitly add the suffix