Skip to main content

Posts

Java program using abstract class and concrete class

 Java program using abstract class and concrete classes using Eclipse IDE Example program in abstract class and method package javaproject1; abstract class Abstract { abstract void display();  //method declaration only void show() { System. out .println( "This show method is normal method in abstract class" ); } } class AbstractDefinition extends Abstract { void display() { System. out .println( "This is display method definition" ); } } class AbstractDemo { public static void main(String args []) { AbstractDefinition obj = new AbstractDefinition(); obj .display(); obj .show(); } } Short explanation of  abstract class and concrete class

A java program for hierarchical inheritance

 A simple program for java  hierarchical inheritance  Java program using eclipse IDE package javaproject1; class Birds { void display1() { System. out .println( "Birds have wings and fethers" ); } } class Crow extends Birds { void display2() { System. out .println( "crow is a bird its color is black" ); } } class Parrot extends Birds { void display3() { System. out .println( "parrot is a bird its color is green" ); } } class HierachicalDemo { public static void main(String a []) { Crow crow = new Crow(); crow .display1(); Parrot parrot = new Parrot(); crow .display2(); parrot .display3(); parrot .display1(); } } Short explanation of hierarchical inheritance in java

Example program in java (oops) concepts

 Java programs for beginners in eclipse IDE Java single inheritance example program using  eclipse IDE package javaproject1; class Vehicle { double speed =80; void go() { System. out .println( "This vehicle is moving,Vehicle speed is :" + speed ); } void stop() { System. out .println( "This vehicle is stopped" ); } } class Car extends Vehicle { int wheel =4; int door =4; } class Inherits { public static void main(String a []) { Car car = new Car(); System. out .println( "Vehicle speed = " + car . speed ); car .go(); System. out .println( "This vehicle has :" + car . wheel + " wheel" ); } } Short explanation of single inheritance in java

Thread synchronization in java

 Java thread synchronization and types  what is synchronization how it work short explanation? synchronization is a technique through which we can control multiple thread execution at a time. If you apply the synchronization concepts on the thread instruction, automatically whatever the thread is executing the instruction, that thread will be in a lock procedure so that no other thread will interrupt this thread.All remaining thread will wait for until the running thread is completed. synchronization can be achieved in three way  Synchronized keyword —> Applied for method  As a prefix to the method in which statements written to be executed as a thread. synchronized block —> Applied for inside the method This should be applied inside the method,If we want to restrict this synchronization for a few lines in a method. Syntax synchronization(this){ Statements } synchronized static block ---> Applied for method Syntax Synchronization static return type method na...

java basic programs1

  simple java programs for beginners in eclipse IDE Data type example program in java using eclipse IDE package javaproject1; public class DataTypeExample { public static void main(String a []) { byte b_value =126; short s_value =32767; int i_value =221133; float f_value =3.14f; double d_value =4.888; char ch = 'a' ; boolean bln = true ; //true or false value only System. out .println( "java data type example program" ); System. out .println( b_value ); System. out .println( s_value ); System. out .println( i_value ); System. out .println( f_value ); System. out .println( d_value ); System. out .println( b_value ); System. out .println( ch ); System. out .println( bln ); System. out .println( "observe the output value carefully" ); } } short explanation of data type in java Different type variable declaration and printing program in eclipse IDE pa...

Java basic program using eclipse IDE

Example program in java multilevel Inheritance using eclipse IDE Multilevel inheritance program in java using eclipse IDE package javaproject1; class MultilevelInherit { public static void main(String[] args ) { Orange frt = new Orange(); frt .display2(); frt .display3(); frt .display1(); } } class Fruits{ int a_box =50; int o_box =25; void display1() { System. out .println( "Total orange box :" + o_box ); System. out .println( "Total apple box :" + a_box ); } } class Apple extends Fruits{ int kgm =40; void display2() { System. out .println( "This apple box is " + kgm + " kilogram" ); } } class Orange extends Apple { int kgm1 =20; void display3() { System. out .println( "This orange box is :" + kgm1 + " kilogram" ); } } short explanation of multilevel inheritance

Thread class methods in java

 Java thread class methods and its function  Thread class contains different methods, using these methods we can manipulate the thread. Some methods are given below. Thread class methos and its funtion start()---->A thread execution started from the start() method,unless you implement the start() method thread will not be started. run()----> implicitly called by the start() method sleep(milliseconds)---->suspends the thread for given milliseconds of time,This should be written in the try catch block as the exception occurs.This is a static method,So this method can be called directly. join()---->waits the thread to complete its process,used in multi threading,it should be written in the try catch block as the exception occurs.This is a static method,So this method can be called directly. getId()---->Gives the ID of the thread getName()---->Gives thread names,always start from thread-0 setName(sting)---->Thread name will be replace with given string getPri...

Thread Life Cycle in Java

 Life Cycle of Thread in Java Programming In java, thread is a class. We know that class consists of a number of methods, variables, constructors etc. Here also the thread class consists of a number of methods. In order to access those methods first create an object for thread class. Thread life cycle has five states. From the creation up to the terminating the thread will move in five different states; these are called thread life cycles . Whenever a thread is created it is moved to a new state.In other words, the state where a thread is created and it is not running is called the newborn state . Whenever a thread is ready to execute the task it moves to runnable state, but is not executed currently.when the start() method is called on the new born thread, it will be in runnable state . After the runnable state, if the thread gets CPU access, it moves into the running state . If the CPU, completes without interrupting the process, it will move to a stop state. If any I/O inter...

Multithreading in java

Explanation of multithreading in java programming What is multithreading in java in simple words? Multithreading Multithreading is a powerful programming tool that makes it possible to achieve concurrent execution of multiple units of a program.In another word it is Concurrent execution of several parts of the same program at same time(This will improve CPU utilization). Advantages of multithreading in java Multi threading support for java includes thread creations,thread prioritizing,thread scheduling,resource locking (thread synchronization)and establishing inter thread communication. What is thread and how to create a thread in java? A thread can be defined as a process in execution within a program. A thread is a lightweight process and it is an individual part of a running program. Group of threads is called a program.All these threads will be working concurrently. There are two ways to create a thread. 1 By extending the thread class 2 By implementing the runnable interface

How does try catch finally work in java

 program for 'try catch finally' in java programming Java program using try catch finally block  public class Divide2  { public static void main(String args[]) { System.out.println("\nPROGRAM EXECUTION START HERE\n"); int NUM1,NUM2,RESULT; try { NUM1=Integer.parseInt(args[0]); NUM2=Integer.parseInt(args[1]); RESULT=NUM1/NUM2; System.out.println(NUM1+"/"+NUM2+"="+RESULT); } catch(Exception e) { System.out.println(e); } finally { System.out.println("\nTHE FINALLY BLOCK ALWAYS EXICUTED\n");  } System.out.println("\nPROGRAM EXECUTION COMPLETE HERE\n"); } } observe the program and its output carefully