Create a class called Multiplication table as below: Ch7MultiplicationTable.java package com.java.basic; public class Ch7MultiplicationTable { void print() { for(int i=1; i<=10;i++) { System.out.printf("%d * %d = %d", 5, i, 5*i).println(); } } // making it generic to accept parameters that is print table of any number void print(int n) { for(int i=1; i<=10;i++) { System.out.printf("%d … Continue reading Java Series Part 7: Creating Multiplication Table using Classes, Object and Methods
Month: October 2022
Java Series Part 6 – Classes, Objects and Methods
A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions. Java is an object-oriented programming language. Everything in Java is associated with classes and objects, along with its attributes and … Continue reading Java Series Part 6 – Classes, Objects and Methods
Java Series Part 5 – JVM, JRE and ByteCode
JVM, JRE and JDK JVM (Java Virtual Machine) is an abstract machine. It is called a virtual machine because it doesn't physically exist. It is a specification that provides a runtime environment in which Java bytecode can be executed. It can also run those programs which are written in other languages and compiled to Java … Continue reading Java Series Part 5 – JVM, JRE and ByteCode
Java Series Part 4 – Strings & String Concatenation
Strings are used for storing text. A String variable contains a collection of characters surrounded by double quotes: String greeting = "Hello"; A String in Java is actually an object, which contain methods that can perform certain operations on strings. For example, the length of a string can be found with the length() method: String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; System.out.println("The … Continue reading Java Series Part 4 – Strings & String Concatenation
Java Series Part 3 – Variable/Data Types
Primitive Data Types Data types that can store integer values: int i;byte b;short s;long l; Variable types: byte b = 5; //8bits - 128 to 127short s = 128 //16bits - 32,768 to 32,767int i = 40000; //32 bits - 2,147,483,648 to 2,147,483,647long l = 222222222; //64bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807float f = 4.0f; //32 bits … Continue reading Java Series Part 3 – Variable/Data Types