Arjun Thakur has Published 1109 Articles

Timer Class in Java

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 09:48:54

420 Views

The Timer Class in Java is a facility for threads to plan tasks for future execution in a background thread. Tasks may be executed a single time or multiple times. The Timer class is thread-safe i.e. the threads of the class do not require external synchronization and can share a ... Read More

How to schedule tasks in Java to run for repeated fixed-delay execution, beginning at the specified time

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 09:35:29

453 Views

One of the methods in the Timer class is the void schedule(TimerTask task, Date firstTime, long period) method. This method schedules tasks for repeated fixed-delay execution, beginning at the specified time.In fixed-delay execution, each execution is scheduled with respect to the original execution time of the preceding execution. If an ... Read More

Compare two int arrays in a single line in Java

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 09:30:01

321 Views

Two int arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order.A program that compares two int arrays using the Arrays.equals() ... Read More

Compute elapsed time in hours in Java

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 09:23:47

370 Views

To get the elapsed time of an operation in hours in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.Declaration −The java.lang.System.currentTimeMillis() is declared as follows −public static long currentTimeMillis()The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 ... Read More

Find maximum element of ArrayList with Java Collections

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 09:16:38

12K+ Views

In order to compute maximum element of ArrayList with Java Collections, we use the Collections.max() method. The java.util.Collections.max() returns the maximum element of the given collection. All elements must be mutually comparable and implement the comparable interface. They shouldn’t throw a ClassCastException.Declaration −The Collections.max() method is declared as follows −public ... Read More

Get the ID of this timezone in Java

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 09:12:34

4K+ Views

In order to get the ID of this timezone in Java, we use the getDisplayName() method. The getDisplayName() returns a name of this time zone acceptable for display to the user in the default locale. In other words, the name returned by the getDisplayName() is user friendly.Declaration − The java.util.TimeZone.getDisplayName() ... Read More

Difference between x++ and x= x+1 in Java programming

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 07:41:18

538 Views

x++ automatically handles the type casting where as x= x + 1 needs typecasting in case of x is not an int variable. See the example below.Example Live Demopublic class Tester {    public static void main(String args[]) {       byte b = 2;       //Type casting ... Read More

How Java objects are stored in memory?

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 07:37:24

4K+ Views

A stack and a heap are used for memory allocation in Java. However, the stack is used for primitive data types, temporary variables, object addresses etc. The heap is used for storing objects in memory.Stacks and heaps in Java are explained in more detail as follows −Stack in JavaStacks are ... Read More

Overloading in java programming

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 07:35:00

228 Views

Method overloading is a type of static polymorphism. In Method overloading, we can define multiple methods with the same name but with different parameters. Consider the following example program.Example Live Demopublic class Tester {    public static void main(String args[]) {       Tester tester = new Tester();     ... Read More

How to create your own helper class in Java?

Arjun Thakur

Arjun Thakur

Updated on 26-Jun-2020 07:26:54

4K+ Views

A helper class serve the following purposes.Provides common methods which are required by multiple classes in the project.Helper methods are generally public and static so that these can be invoked independently.Each methods of a helper class should work independent of other methods of same class.Following example showcases one such helper ... Read More

Advertisements