Here I have attached the Simple example for instanceof in Java programming language package com.javatraineronline; public class Employee { public void work() { System.out.println("Employee is Working"); } } package com.javatraineronline; public class Engineer extends Employee { @Override public void work() { System.out.println("Engineer is Working"); } } package com.javatraineronline; public class Manager extends Employee { @Override […]
Here I have attached the Simple Class Array Example in Java Program. package com.javatraineronline; public class Customer { // Attributes private int customerId; private String customerName; private int customerAge; // Setter and Getter public int getCustomerId() { return customerId; } public void setCustomerId(int customerId) { this.customerId = customerId; } public String getCustomerName() { return customerName; […]
[su_table] For Loop For each Loop Both increment and decrement can be done Only Increment iteration can be done Need variable declaration Only temp variable is needed [/su_table] Here the sample program [su_highlight]JavaLoops.java[/su_highlight] package com.javatraineronline; public class JavaLoops { public static void main(String[] args) { // Declaring the String Array. String[] strArray = {"Aa", "Bb", […]
package com.javatraineronline; import java.util.Arrays; import java.util.List; public class CovertArrayToList { public static void main(String[] args) { // Declaring String Array String[] array = {"One", "Two", "Three", "Four", "Five"}; // Converting Array Object to List Object List<String> list = Arrays.asList(array); // Printing the Converted List Object System.out.println("List : "+list); } } [su_box title=”Output for CovertArrayToList.java”]List : […]
package com.javatraineronline; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ReverseList { public static void main(String[] args) { // Declaring the ArrayList List<String> list = new ArrayList<String>(); list.add("One"); list.add("Two"); list.add("Three"); list.add("Four"); list.add("Five"); // Printing the before reverse System.out.println("Before : "+list); Collections.reverse(list); // 'Collections' is a class 'reverse' is predefined method. //Printing the after reverse System.out.println("After […]
package com.javatraineronline; public class SwapNumber { public static void swap(int a, int b) { // Assigning 'a' value to 'temp' int temp = a; // Assigning 'b' value to 'a' a = b; // Assigning 'temp' value to 'b' b = temp; // Printing before swapping System.out.println("After Swapping A : "+a+" B: "+b); } public […]
package com.javatraineronline; import java.util.ArrayList; import java.util.List; public class SimpleArrayList { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("One"); list.add("Two"); list.add("Three"); list.add("Four"); list.add("Five"); System.out.println("List : "+list); } } [su_box title=”Output for SimpleArrayList.java”]List : [One, Two, Three, Four, Five][/su_box]
Recursion.java public class Recursion { public static void main(String[] args) { int n1 = 0; int n2 = 1; System.out.println(n1); System.out.println(n2); doRecursion(n1, n2); //Doing Recursion Here } public static int doRecursion(int n1,int n2){ int n3 = n1+n2; // Dynamic allocation of values System.out.println(n3); n1 = n2; n2 = n3; if(n3 > 40){ // Exit condition […]
The Simple Cross String Program in Java CrossString.java package com.javatraineronline; public class CrossString { public static void main(String[] args) { String data = "welcome";// Get the String to be crossed int l = data.length();// Find the length of the String char a[] = data.toCharArray();// Convert the String into char array // Loop through the length […]
The following program to create Simple Hour Glass in Java. HourGlass.java package com.javatraineronline; public class HourGlass { public static void main(String[] args) { // Initialize the 2D array. Here we've used 6*6 matrix int[][] array = {{-1,-1,0,-9,-2,-2},{-2, -1, -6, -8, -2, -5},{-1, -1, -1, -2, -3, -4},{-1, -9, -2, -4, -4, -5},{-7, -3, -3, -2, […]
The final is a keyword in Java Programming language which is used to restrict the access for some component, It can be used 3 places in Java language such as [su_list icon=”icon: arrow-circle-o-right”] final variable final method final class [/su_list] Final Variable Once the variable is declared as final variable the value cannot be changed […]
The Singleton class allows to create only one object for the given class. In order to make the class as Singleton you need to declare the constructor as private so that you can restrict for creating multiple objects for one class. Use static reference variable to make an object as shareable and define the static […]
In Java Programming Language totally 8 primitive datatypes are available. These primitive datatypes are predefined by the language and named by a keyword. [su_list icon=”icon: arrow-circle-o-right”] byte short int long float double char boolean [/su_list] Let us see these eight primitive data types in detail. byte Byte data type is an 8-bit Minimum range is […]
Hi folks Dinesh Krishnan(Online Java Trainer) here To write and execute the simple Hello World Program in Java Language. First make sure you have following requirements on your machine. [su_list icon=”icon: arrow-circle-o-right”] JDK(Java Development Kit) JRE(Java Runtime Environment) Text Editor [/su_list] Step 1: Open the any text editor such as (Subline Editor, NotePad++ and etc). […]