Skip to main content

Posts

Showing posts from August, 2023

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