Core Java - [Thread Life Cycle]

♠ Posted by Unknown in
Thread Life Cycle and Example During the life time of a thread, there are many states it can enter. They include: 1.      Newborn State 2.      Runnable State 3.      Running State 4.      Blocked State 5.      Dead State A thread is always in one of these five states. It can move from one state to another via a variety of ways. Shown in below figure. 1.      Newborn State : When we create a thread object, the thread is born...

Core Java - [Multithreading Fundamentals]

♠ Posted by Unknown in
Multithreaded Programming in Java Multithreading is a conceptual programming paradigm where a program (process) is divided into two or more subprograms (processes), which can be implemented at the same time in parallel. For example, one subprogram can display an animation on the screen while another may build the next animation to be displayed. This is something similar to dividing a task into subtasks and assigning them to different people for execution independently and simultaneously. A thread is similar to a program that has a single flow of control. It has a beginning, a body, and an end, and executes commands sequentially. In fact all main programs can be called single-threaded programs. The main thread is actually the main method module, which is designed to create and start the other three threads, namely A, B, and C. Once initiated by the main thread, the threads A, B, and C run concurrently and share the resources jointly. The ability of a language to...

Core Java - [Exception-02]

♠ Posted by Unknown in
Exception handling Examples When Runtime Error occurred in program can be terminated abnormally and cannot display output or proper error message. So, at runtime if program can be terminated without inform any error that can be understand by programmer, it is very crucial to find an error in program or taken output. If programmer can be expected that error in his code it can be handled by the java exception handling method. Java will help the programmer to handle exception using following five keywords : try, catch, throw, throws, and finally. Syntax : try.....catch : try {             Exception expected             code segment; } catch(exception object) {             when exception occurred             code segment; } try with multiple...

Core Java - [Exception-01]

♠ Posted by Unknown in
Exception: List the Common Java Exceptions. An exception is a condition that is caused by a run-time error in the program. When the Java interpreter encounter an error such as dividing an integer by zero, it creates an exception object and throws it (i.e., informs us that an error has occurred). If the exception object is not caught and handled properly, the interpreter will display an error message and will terminate the program. If we want the program to continue with the execution of the remaining code, then we should try to catch the exception object thrown by the error condition and then display an appropriate message for taking corrective actions. This task is known as exception handing. The purpose of exception handling mechanism is to provide a means to detect and report an “exceptional circumstance” so that appropriate action can be taken. The mechanism suggests incorporation of a separate error handling code that performs the following tasks:                        ...

Core Java - [Wrapper Class]

♠ Posted by Unknown in
Wrapper Class The vectors cannot handle primitive data types like int, float, long, char,  and double. Primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package. Below table shows the simple data types and their corresponding wrapper class types. Simple Type Wrapper Class boolean Boolean char Character double Double float Float int Integer long Long Converting Primitive to Objects Using Constructor Converting Objects to Primitive using method Converting Numbers to Strings Converting String objects to Numeric objects Converting Numeric Strings to Primitive Numbers Integer IntVal = new Integer() int i =  IntVal.intValue() str = Integer.toString(i) IntVal = Integer.valueOf() int i = Integer.parseInt(str) Float FloatVal...

Core Java - [Vector Class]

♠ Posted by Unknown in
Vector class The Vector class contained in the java.util package. This class can be used to create a generic dynamic array known as vector that can hold objects of any type and any number. The objects do not have to be homogenous. Arrays can be easily implemented as vectors. Vectors are created like arrays as follows:                                                 Vector intVect = new Vector(); //declaring without size                         Vector list = new Vector(3); //declaring with size The vector can be declared without specifying any size explicitly. A vector can accommodate an unknown number of items. Even, when a...