by Dinesh Thakur

A nested class as the name suggests is a class that is defined inside another class. It is merely a convenient way of grouping two or more classes together into a single unit or module. A class that contains a nested class is known as the enclosing or outer class of the nested class.

 
by Dinesh Thakur

Copy Constructor: Sometimes a programmer wants to create an exact but separate copy of an existing object so that subsequent changes to the copy should not alter the original or vice versa. This is made possible using the copy constructor. It takes the object of the class as a reference to the parameters. This means that whenever we initialize an instance using value of another instance of same type, a copy constructor is used.

 
by Dinesh Thakur

Method Overloading: When multiple methods in the same class with same name, having different functions or types of parameters, it is known as Method Overloading. When an overloaded method is invoked, it is the responsibility of the compiler to select the appropriate overloaded method based on the number of argument(s) passed and if the numbers of argument(s) are same then depending upon the type of argument(s) passed to the method. Thus, the key to method overloading is a method's parameter list. A method's return type is not enough to distinguish between two overloaded methods. If the compiler detects two methods declarations with the same name and parameter list but different return types then it will generate an error.

 
by Dinesh Thakur

In Java, there is no such thing as a call by reference, only a call by value. If a method that passes value called, we are calling by value and any change in the method called do not get affected in the method used to call.  Where a call by value is used, there is no change to the original value. Have a look  at the Example below:

 
by Dinesh Thakur

Interfaces and abstract classes both implements polymorphic behaviour and seem to be similar but they are different in the following ways:
1. An interface is purely abstract i.e. methods in an interface only have declarations no implementations. On the other hand, abstract class methods may or may not have an implementation.

 
by Dinesh Thakur

A thread can undergo some states during its life cycle. It is because in a multithreaded environment when multiple threads are executing only one thread can use the CPU at a time, and all other threads should be in some other states either waiting for their turn for the CPU or waiting for some other condition to be satisfied.

A thread is always in one of five states: newborn, runnable, running, dead and blocked. Figure shows the life cycle of a thread.

 
by Dinesh Thakur

Every thread in Java has a priority that helps the thread scheduler to determine the order in which threads scheduled. The threads with higher priority will usually run before and more frequently than lower priority threads. By default, all the threads had the same priority, i.e., they regarded as being equally distinguished by the scheduler, when a thread created it inherits its priority from the thread that created it. However, you can explicitly set a thread's priority at any time after its creation by calling its setPriority() method. This method accepts an argument of type int that defines the new priority of the thread. Its syntax is.

 
by Dinesh Thakur

Java Thread: One of the dominant features of the Java language is that it provides built-in support for multithreading - the concurrent running of multiple threads within the same program. Creating a thread in Java is relatively easy. Unlike the old fashioned programming languages, where you have to invoke system-dependent procedures and functions to implement multithreading, in Java, it is no harder than creating an instance of other classes.

The programs that we have written so far had only one entry point (main() method) and one exit point. All the instructions in these programs executed serially one at a time beginning at the first statement in main () and continuing sequentially through the statements until the program ends. This single sequence of executable statements within a program is known as a thread. In other words, a thread is s flow of execution of a task in a program, so it is known as a thread of execution or a thread of control.

 
by Dinesh Thakur

The ability of the Operating system to execute several programs simultaneously is known as multitasking. In system terminology, it is is a powerful programming tool that makes it possible to achieve concurrent execution of multiple units of a program called multithreading. In multithreading,  the application (process) is divided into two or more subprograms (processes), Several such processes originating from a single task, can be simultaneously started and handled by Java, which can be implemented at the same time in parallel. The processor is doing only one thing at a time, but it switches between the processes so fast that it appears to human beings that all of them are being done simultaneously. This mechanism of treating a single task as several independent processes simultaneously is called multithreading. Each separate process is called a thread. Each thread is executed one at a time in the CPU. Multithreading enables a program to do more than one task at a time and also to synchronize these tasks.  

 
by Dinesh Thakur

The Java language and its run-time system was designed keeping in mind about multithreading. The run-time system depend upon multithreading. Java provides asynchronous thread environment, this helps to increase the utilization of CPU.

 

Page 5 of 10

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.