Learnitweb

Category: Java tutorial

  • Java Thread Life Cycle and Thread States

    1. Introduction From creation to termination, a thread can be in one of the five states. A thread can only be in one state at a time. These states are with reference to JVM and not operating system. Thread can be in any of the following states: 2.1 New A thread is in NEW state…

  • Thread.join() method in Java with examples

    There are three overloaded versions of join. When to use Thread.join() method Suppose you have two threads, thread A and thread B. If the requirement is that thread B can not start and do its work until thread A has finished its work. In such case, you can join thread B at the end of…

  • How to create and run a thread in Java

    1. Introduction A thread is a thread of execution in program. A thread is a light weight sub-process. It is smallest unit of processing. 2. Create a thread There are two ways to create thread in Java: 2.1 Create a thread by extending java.lang.Thread To create a thread by extending Thread class involved two steps:…

  • synchronized in Java

    An object in Java has a state and behavior. The state of the object is the value of the instance variables it has. The methods in the object are used to change the state of the object by changing the state of the object. In multi-threaded programming, it is possible by multiple threads to invoke…

  • Race condition in Java with examples

    Race condition is the condition in which multiple threads try to access the same data or perform some operation on the data, and the correctness of the result depends on the timing of execution of the threads. In race condition, if the timing of the threads is changed then the result may not be correct.…

  • Rules of declaring package, import and class in source file

    While writing source code, following are the rules of declaring package, import statement and class: This class should be saved as Foo.java as the the source code has class which is public.

  • Create, compile, run and understand Hello World program in Java

    Let us write our first program in Java. We’ll print “Hello World” on the console. 1. Write Hello World program in Java Write in following peace of code and save as file HelloWorldApplication and extension as java in your favorite code editor. Output 2. javac – Compile java program The code which you have written…

  • Java LocalDateTime class with examples

    1. Brief Description 2. How to create instance of LocalDateTime We’ll discuss few of the common ways of creating a LocalDateTime instance. 2.1 LocalDateTime representing current date and time Output 2.2 LocalDateTime instance using method ‘of’ Following are commonly used overloaded versions of method of to get instance of LocalDateTime. LocalDateTime represents time in nano…

  • Java LocalTime class with examples

    1. Brief Description 2. Create instance of LocalTime We’ll discuss few common used methods to create instance of LocalTime. 2.1 LocalTime representing current time 2.2 LocalDateTime from hour, minute and second There are other variations of method of to get instance of LocalTime: 2.3 LocalTime instance from a String 2.4 Example of creating LocalTime instance…

  • LocalDate class in Java with examples

    LocalDate class is provided by java.time package in Java 8. This class respresents a date often in the form of year-month-date, without a time-zone in the ISO-8601 calendar system. This class does not store or represent time and is used to represent date like your birthday or anniversary, for example 2021-03-13. This class is immutable…