Skip to main content

Posts

simple 25-java programs

Easy 25-java programs for practice Java programs for beginners 

Introduction to java applets

 Java Applets And Its Uses What is an applet in java, and what are its uses? An applet is a software component that enables client-side programming and facilitates text, graphics, audio, imaging, animation and networking, besides live updating and securing two way interaction in web pages. One of the main features of java is the applet .These are usually small in size .Applets are used to embed the code in a web browser and to generate the dynamic contents and its works on the client side .Its response time is very fast . The main features of applets are following: It provides a GUI Facilitates graphics,animation and multimedia. Provides a facility for frames. Enable event handling. Avoid a risk and provides a secure two-way interaction between web pages.  Applet Life cycle: Java applets have a specific programming structure and a specific life cycle that describes how it starts, how it runs, and how it ends. The life cycle consists of five methods: These methods are used ...

Java programs for practice in eclipse IDE

 'For loop' practice code in java Q: What is the 'for loop' in computer programming ? A: A 'for loop' means to execute a block of code for a limited amount of time. Write a Java program to count down 10 times and print HAPPY ONAM on the screen? program package javaproject1; public class ForloopDemo { public static void main(String args []) { for ( int i =10; i >=0; i --){ System. out .println( i ); } System. out .println( "HAPPY ONAM" ); } } Eclipse output

Try catch-(exception handling in java)

 Exception handling in java with examples program Exception handling in java  with eclipse IDE example program and its output program1 package javaproject1; public class ExceptionDemo { public static void main(String[] args ) { String[] fruit_array = { "apple" , "orange" , "grapes" }; System. out .println( fruit_array [2]); System. out .println( fruit_array [3]); System. out .println( fruit_array [1]); } } program 1 output Listen to the program 1, line number 9,10,11. line 9 no error Line 10 an error occurred Therefore the rest of the statement is not executed(line 11) Let's see how the error occurred and how to fix it. In our program the array length is three. Array values are arranged starting from zero index. Let's see how the array values are arranged in this program starting from zero index. fruit_array[0]-->apple in zeroth position fruit_array[1]-->orange in first position fruit...

Method overriding in java example program

 Java programs for practice in eclipse IDE Method overriding in java example program eclipse IDE package javaproject1; class college { public void move() { System. out .println( "College is open" ); } } class University extends college { public void move() { System. out .println( "University is open today" ); super .move(); } } public class Student { public static void main(String args []) { University university = new University(); university .move(); } } short explanation of method overriding

Method overloading in java program

 Method overloading in java example program using eclipse IDE Method overloading in java real time example program using eclipse IDE package javaproject1; class MethodOverloading { public static void main(String args []) { int result1 = add (25,25); int result2 = add (25,25,50); System. out .println( "Result of two integer value is stored in result1 :" + result1 ); System. out .println( "Result of three integer value is stored in result2 :" + result2 ); } static int add( int num1 , int num2 ) { return num1 + num2 ; } static int add( int num1 , int num2 , int num3 ) { return num1 + num2 + num3 ; } } short explanation of  static key word in java short explanation of methods in java 

Program for java constructor overloading

 Example program for constructor overloading in java using eclipse IDE constructor overloading in java-example program package javaproject1; class Pudding { String ingreidents1 ; String ingreidents2 ; String ingreidents3 ; String ingreidents4 ; Pudding(String inds1 ,String inds2 ) { this . ingreidents1 = inds1 ; this . ingreidents2 = inds2 ; } Pudding(String inds1 ,String inds2 ,String inds3 ,String inds4 ) { this . ingreidents1 = inds1 ; this . ingreidents2 = inds2 ; this . ingreidents3 = inds3 ; this . ingreidents4 = inds4 ; } } class Constructor { public static void main(String args []) { Pudding pudding1 = new Pudding( "coconutmilk" , "sugar" ); Pudding pudding2 = new Pudding( "bread" , "sugar" , "custard" , "butter" ); System. out .println( "Gelatin is an ingredient that sets the pudding" ); System. out .pri...

Implementing interface in java eclipse IDE example program

 Eclipse IDE implement interface in java Example program in java interface using eclipse IDE package javaproject1; interface Interface1 { void show1(); } interface Interface2 { void show2(); } class InterfaceDefintion implements Interface1,Interface2 { public void show1() { System. out .println( "Here give the definition of show1 method....." ); } public void show2() { System. out .println( "Here give the definition of show2 method....." ); } } class IntrefaceDemo { public static void main(String a []) { InterfaceDefintion obj = new InterfaceDefintion(); obj .show1(); obj .show2(); } } short explanation of interface

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...