Learnitweb

Author: editor

  • Anonymous Inner Class in Java

    Anonymous inner class is an inner class without a name. Anonymous class is commonly used to create implementation classes of listener interfaces. Anonymous class is very useful while creating an instance of subclass(of a class) or implementing an interface without actually extending and with less code. The main purpose of creating anonymous inner class is…

  • 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…