GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing hackr.io — Java Cheat Sheet: Download PDF for Quick Reference
Object-Oriented Programming Language: based on the concepts of “objects”. The Java BuzzwordsJava was modeled in its final form, keeping into consideration the primary objective of having the following features
Read here: Major features of Java programming Primitive Data Types in Java
Non-Primitive Data Types
TypecastingIt is a method of converting a variable of one data type to another data type to process these variables correctly. Java defines two types of typecasting:
Operators in JavaJava supports a rich set of operators that can be classified as below :
Java IDE and Executing Code:Amongst many IDEs, the most recommended ones are :
Java code can also be written in any text editor and compiled on the terminal with the following commands : $ javac [file_name].java $ java [file_name] Note: Filename should be the same as the class name containing the main() method, with a .java extension. Visit here to know more about Java IDE. Variables in JavaVariables are the name of the memory location. It is a container that holds the value while the java program is executed. Variables are of three types in Java :
class TestVariables
{
int data = 20; // instance variable
static int number = 10; //static variable
void someMethod()
{
int num = 30; //local variable
}
}
Reserved WordsAlso known as keywords, particular words are predefined in Java and cannot be used as variable or object names. Some of the important keywords are :
Methods in JavaThe general form of method : Where type - the return type of the method type name (parameter list)
{
//body of the method
//return value (only if type is not void)
}
Conditional Statements in Java1. if-elseTests condition, if condition true if block is executed else the else block is executed. class TestIfElse
{
public static void main(String args[])
{
int percent = 75;
if(percent >= 75
{
System.out.println("Passed");
}
else
{
System.out.println("Please attempt again!");
}
}
}
2. SwitchTest the condition; if a particular case is true, the control is passed to that block and executed. The rest of the cases are not considered further, and the program breaks out of the loop. class TestSwitch
{
public static void main(String args[])
{
int weather = 0;
switch(weather)
{
case 0 :
System.out.println("Sunny");
break;
case 1 :
System.out.println("Rainy");
break;
case 2 :
System.out.println("Cold");
break;
case 3 :
System.out.println("Windy");
break;
default :
System.out.println("Pleasant");
}
}
}
3. Loops in JavaLoops are used to iterate the code a specific number of times until the specified condition is true. There are three kinds of the loop in Java :
Java OOPS ConceptsAn object-oriented paradigm offers the following concepts to simplify software development and maintenance. 1. Object and ClassObjects are basic runtime entities in an object-oriented system, which contain data and code to manipulate data. This entire set of data and code can be made into user-defined data types using class concepts. Hence, a class is a collection of objects of a similar data type. Example: apple, mango, and orange are members of class fruit. 2. Data Abstraction and EncapsulationThe wrapping or enclosing up of data and methods into a single unit is known as encapsulation. Take medicinal capsule as an example; we don’t know what chemical it contains; we are only concerned with its effect. 3. InheritanceInheritance provides the concept of reusability; it is how objects of one class (Child class or Subclass) inherit or derive properties of objects of another class (Parent class). Types of Inheritance in Java
class A
{
int i, j;
void showij() {
System.out.println("i and j: " + i + " " + j);
}
}
// Create a subclass by extending class A.
class B extends A {
int k;
void showk() {
System.out.println("k: " + k);
}
void sum() {
System.out.println("i+j+k: " + (i+j+k));
}
}
class SimpleInheritance {
public static void main(String args[]) {
A objA = new A();
B objB = new B();
// The superclass may be used by itself
objA.i = 10;
objA.j = 20;
System.out.println("Contents of objA: ");
objA.showij();
System.out.println();
/* The subclass can access to all public members of
its superclass. */
objB.i = 7;
objB.j = 8;
objB.k = 9;
System.out.println("Contents of objB: ");
objB.showij();
objB.showk();
System.out.println();
System.out.println("Sum of i, j and k in objB:");
objB.sum();
}
}
Some limitations in Inheritance :
4. PolymorphismDefined as the ability to take more than one form. Polymorphism allows creating clean and readable code. In Java Polymorphism, the concept of method overloading and method overriding is achieved, which is the dynamic approach. 4.1. Method OverridingIn a class hierarchy, when a method in a child class has the same name and type signature as a method in its parent class, then the method in the child class is said to override the method in the parent class. If we don’t override the method in the code below, the output would be 4 as calculated in ParentMath class; otherwise, it would be 16. class ParentMath
{
void area()
{
int a =2;
System.out.printf("Area of Square with side 2 = %d %n", a * a);
System.out.println();
}
}
class ChildMath extends ParentMath
{
void area()
{
int a =4;
System.out.printf("Area of Square with side 4= %d %n", a * a);
}
public static void main (String args[])
{
ChildMath obj = new ChildMath();
obj.area();
}
}
4.2. Method OverloadingJava programming can have two or more methods in the same class sharing the same name, as long as their arguments declarations are different. Such methods are referred to as overloaded, and the process is called method overloading. Three ways to overload a method :
example: add(int, int) add(int, int, int)
example add(int, int) add(int, float)
example add(int, float) add(float, int) Program to explain multilevel inheritance and method overloading : class Shape
{
void area()
{
System.out.println("Area of the following shapes are : ");
}
}
class Square extends Shape
{
void area(int length)
{
//calculate area of square
int area = length * length;
System.out.println("Area of square : "+area);
}
}
class Rectangle extends Shape
{
//define a breadth
void area(int length,int breadth)
{
//calculate area of rectangle
int area = length * breadth;
System.out.println("Area of rectangle : " + area);
}
}
class Circle extends Shape
{
void area(int breadth)
{
//calculate area of circle using length of the shape class as radius
float area = 3.14f * breadth * breadth;
System.out.println("Area of circle : " + area);
}
}
class InheritanceOverload
{
public static void main(String[] args)
{
int length = 5;
int breadth = 7;
Shape s = new Shape();
//object of child class square
Square sq = new Square();
//object of child class rectangle
Rectangle rec = new Rectangle();
//object of child class circle
Circle cir = new Circle();
//calling the area methods of all child classes to get the area of different objects
s.area();
sq.area(length);
rec.area(length,breadth);
cir.area(length);
}
}
Abstract ClassSuperclass only defines a generalized form shared by all of its subclasses, leaving it to each subclass to implement its methods. abstract class A {
abstract void callme();
// concrete methods are still allowed in abstract classes
void callmetoo() {
System.out.println("This is a concrete method.");
}
}
class B extends A {
void callme() {
System.out.println("B's implementation of callme.");
}
}
class Abstract {
public static void main(String args[]) {
B b = new B();
b.callme();
b.callmetoo();
}
}
InterfacesA class’s interface can be fully abstracted from its implementation using the “interface” keyword. Thus, they are similar to class except that they lack instance variables, and their methods are declared without anybody.
interface Area
{
final static float pi = 3.14F;
float compute(float x , float y);
}
class Rectangle implements Area
{
public float compute (float x, float y)
{
return (x*y);
}
}
class Circle implements Area
{
public float compute (float x, float y)
{
return (pi * x * x);
}
}
class InterfaceTest
{
public static void main (String args[])
{
float x = 2.0F;
float y = 6.0F;
Rectangle rect = new Rectangle(); //creating object
Circle cir = new Circle();
float result1 = rect.compute(x,y);
System.out.println("Area of Rectangle = "+ result1);
float result2 = cir.compute(x,y);
System.out.println("Area of Circle = "+ result2);
}
}
Constructors in Java
Constructors can be :
class Box {
double width;
double height;
double depth;
// This is the constructor for Box.
Box() {
System.out.println("Constructing Box");
width = 10;
height = 10;
depth = 10;
}
// compute and return volume
double volume() {
return width * height * depth;
}
}
class BoxVol {
public static void main(String args[]) {
// declare, allocate, and initialize Box objects
Box mybox1 = new Box();
Box mybox2 = new Box();
double vol;
vol = mybox1.volume();
System.out.println("Volume is " + vol);
vol = mybox2.volume();
System.out.println("Volume is " + vol);
}
}
class Box {
double width;
double height;
double depth;
Box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
double volume() {
return width * height * depth;
}
}
class BoxVolP {
public static void main(String args[]) {
Box mybox1 = new Box(10, 20, 15);
Box mybox2 = new Box(3, 6, 9);
double vol;
vol = mybox1.volume();
System.out.println("Volume is " + vol);
vol = mybox2.volume();
System.out.println("Volume is " + vol);
}
}
Learn more about Java Constructor. Arrays in JavaAn array is a group of like-type variables referred by a common name, having continuous memory. Primitive value objects are stored in an array. It provides code optimization since we can sort data efficiently and also access it randomly. The only flaw is that we can have a fixed-size element in an array. There are two kinds of arrays defined in Java:
import java.util.Scanner;class SingleArray{public static void main(String args[]){System.out.println("Enter the length in the array: ");Scanner sc = new Scanner(System.in);int len = sc.nextInt();int[] numbers = new int [len];System.out.println("Enter the elements in the array: ");// int n = s.nextInt();for(int i=0;i<len;i++){numbers[i] = sc.nextInt();}System.out.println("The elements in the array are: ");for(int i=0;i<len;i++){System.out.print(numbers[i] + " ");}System.out.println();System.out.println("The sum of elements in the array are: ");int sum =0;for(int i=0;i<len;i++){sum = sum + numbers[i];}System.out.println("Sum of elements = " + sum);}}
class MatrixArray { public static void main(String args[]) { int [][] m1 = {{1,2,1},{2,1,1},{1,1,2}}; int [][] m2 = {{2,2,2},{1,1,1},{2,1,2}}; int [][] sum = new int [3][3]; //printing matrix System.out.println("The given matrices are : "); for(int a=0;a<m1.length;a++) { for(int b=0;b<m2.length;b++) { System.out.print(m1[a][b] + " "); } System.out.println(); } System.out.println(); for(int a=0;a<m1.length;a++) { for(int b=0;b<m2.length;b++) { System.out.print(m2[a][b] + " "); } System.out.println(); } //matrix addition System.out.println("The sum of given 2 matrices is : "); for(int a=0;a<m1.length;a++) { for(int b=0;b<m2.length;b++) { sum[a][b] = m1[a][b] + m2[a][b]; System.out.print(sum[a][b] + " "); } System.out.println(); } } } Strings in JavaStrings are a non-primitive data type that represents a sequence of characters.
Creating String
String MethodsThe String class, which implements the CharSequence interface, defines several methods for string manipulation tasks. The list of most commonly used string methods are mentioned below:
Program to show Sorting of Strings: class SortStrings {
static String arr[] = {
"Now", "the", "is", "time", "for", "all", "good", "men",
"to", "come", "to", "the", "aid", "of", "their", "county"
};
public static void main(String args[])
{
for(int j = 0; j < arr.length; j++)
{
for(int i = j + 1; i < arr.length; i++)
{
if(arr[i].compareTo(arr[j]) < 0)
{
String t = arr[j];
arr[j] = arr[i];
arr[i] = t;
}
}
System.out.println(arr[j]);
} }
}
String Buffer and String Builder
Difference between length() and capacity()
/* StringBuffer length vs. capacity */ class StringBufferTest {
public static void main(String args[]) {
StringBuffer sb = new StringBuffer("Hello");
System.out.println("buffer = " + sb);
System.out.println("length = " + sb.length());
System.out.println("capacity = " + sb.capacity());
}
}
StringBuilder versus StringBuffer
MultithreadingMultitasking: Process of executing multiple tasks simultaneously to utilize the CPU. This can be achieved in two ways:
Multitasking vs. Multithreading
Life Cycle Of ThreadA thread is always in one of the following five states; it can move from one state to another in a variety of ways, as shown.
Common Methods Of Thread Class
Program to create threads using thread class. class A extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("From thread A : i " + i);
}
System.out.println("Exit from A ");
}
}
class B extends Thread
{
public void run()
{
for(int i=0;i<=5;i++)
{
System.out.println("From thread B : i " + i);
}
System.out.println("Exit from B ");
}
}
class C extends Thread
{
public void run ()
{
for(int k=1;k<=5;k++)
{
System.out.println("From thread C : k " + k);
}
System.out.println("Exit from C ");
}
}
class ThreadTest
{
public static void main(String args[])
{
new A().start();
new B().start();
new C().start();
}
}
Implementing Runnable InterfaceThe run( ) method is declared in the Runnable interface is required for implementing threads in our programs. The process consists of the following steps :
Using Runnable Interface class X implements Runnable
{
public void run()
{
for(int i=0;i<=10;i++)
{
System.out.println("Thread X " + i);
}
System.out.println("End of thread X ");
}
}
class RunnableTest
{
public static void main(String args[])
{
X runnable = new X ();
Thread threadX = new Thread(runnable);
threadX.start();
System.out.println("End of main Thread");
}
}
Thread Class vs. Runnable Interface
Exception Handling in JavaThe exception is an abnormality or error condition caused by a run-time error in the program; if this exception object thrown by the error condition is not caught and handled properly, the interpreter will display an error message. If we want to avoid this and want the program to continue, we should try to catch the exceptions. This task is known as exception handling. Common Java Exceptions
Exceptions in java can be of two types:
Try and CatchTry keyword is used to preface a block of code that is likely to cause an error condition and “throw” an exception. The keyword catch defines a catch block “catches” the exception “thrown” by the try block and handles it appropriately. A code can have more than one catch statement in the catch block; when an exception in the try block is generated, multiple catch statements are treated like cases in a switch statement. Using Try and Catch for Exception Handling class Error
{
public static void main(String args[])
{
int a [] = ;
int b = 5;
try
{
int x = a[2]/b-a[1];
}
catch(ArithmeticException e)
{
System.out.println("Division by zero");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexError");
}
catch(ArrayStoreException e)
{
System.out.println("Wrong data type");
}
int y = a[1]/a[0];
System.out.println("y = " + y);
}
}
FinallyFinally, statement: used to handle exceptions that are not caught by any previous catch statements. A final block is guaranteed to execute, regardless of whether or not an exception is thrown. We can edit the above program and add the following final block. finally
{
int y = a[1]/a[0];
System.out.println("y = " + y);
}
Throwing Your Own ExceptionOwn exceptions can be defined using the throw keyword. throw new Throwable subclass; /* Throwing our own Exception */ import java.lang.Exception;
class MyException extends Exception
{
MyException(String message)
{
super(message);
}
}
class TestMyException
{
public static void main(String args[])
{
int x = 5 , y = 1000;
try
{
float z = (float) x / (float) y ;
if(z < 0.01)
{
throw new MyException("Number is too small");
}
}
catch (MyException e)
{
System.out.println("Caught my exception ");
System.out.println(e.getMessage());
}
finally
{
System.out.println("I am always here");
}
}
}
Managing Files in JavaStoring data in variables and arrays poses the following problems:
Such problems can be solved by storing data on secondary devices using the concept of files. Collection of related records stored in a particular area on the disk termed as the file. The files store and manage data by the concept of file handling. Files processing includes:
Java provides many features in file management like :
StreamsJava uses the concept of streams to represent an ordered sequence of data, a path along which data flows. Thus, it has a source and a destination. Streams are classified into two basic types :
Stream ClassesThey are contained in the java.lang.io package. They are categorized into two groups.
Bytes Stream ClassesDesigned to provide functionality for creating and manipulating streams and files for reading/writing bytes. Since streams are unidirectional, there are two kinds of byte stream classes :
Input Stream ClassesThey are used to read 8-bit bytes include a superclass known as InputStream. InputStream is an abstract class and defines the methods for input functions such as :
Output Stream ClassesThese classes are derived from the base class OutputStream. OutputStream is an abstract class and defines the methods for output functions such as :
Reading/Writing BytesTwo common subclasses used are FileInputStream and FileOutputStream that handle 8-bit bytes. FileOutputStream is used for writing bytes to a file as demonstrated below: // Writing bytes to a file import java.io.*;
class WriteBytes
{
public static void main(String args[])
{
bytes cities [] = {'C','A','L','I','F','O','R','N','I','A', '\n', 'V','E','G','A','S','\n','R','E','N','O','\n'};
//Create output file stream
FileOutputStream outfile = null;
try
{
//connect the outfile stream to "city.txt"
outfile = new FileOutputStream("city.txt");
//Write data to the stream
outfile.write(cities);
outfile.close();
}
catch(IOException ioe)
{
System.out.println(ioe);
System.exit(-1);
}
}
}
FileIntputStream is used for reading bytes from a file, as demonstrated below: //Reading bytes from a file import java.io.*;
class ReadBytes
{
public static void main(String args[])
{
//Create an input file stream
FileInputStream infile = null;
int b;
try
{
//connect the infile stream to required file
infile = new FileInputStream(args [ 0 ]);
//Read and display
while( (b = infile.read ( ) ) !=-1)
{
System.out.print((char) b );
}
infile.close();
}
catch(IOException ioe)
{
System.out.println(ioe);
System.exit(-1);
}
}
}
Character Stream ClassesTwo kinds of character stream classes: Reader Stream Classes
Writer Stream Classes
Reading/Writing CharactersThe two subclasses of Reader and Writer classes for handling characters in files are FileReader and FileWriter. // Copying characters from one file to another import java.io.*;
class CopyCharacters
{
public static void main (String args[])
{
//Declare and create input and output files
File inFile = new File("input.dat");
File outFile = new File("output.dat");
FileReader ins = null; //creates file stream ins
FileWriter outs = null; //creates file stream outs
try
{
ins = new FileReader(inFile); //opens inFile
outs = new FileWriter(outFile); //opens outFile
//Read and write
int ch;
while((ch = ins.read( ))!=-1)
{
outs.write(ch);
}
}
catch(IOException e)
{
System.out.println(e);
System.exit(-1);
}
finally
{
try
{
ins.close();
outs.close();
}
catch (IOException e)
{}
}
}
}
Java CollectionsThe collections framework is contained in java.util package defines a set of interfaces and their implementations to manipulate collections, which serve as containers for a group of objects. InterfacesThe collection framework contains many interfaces such as Collection, Map and Iterator. The interfaces and their description are mentioned below:
ClassesThe classes available in the collection framework implement the collection interface and sub-interfaces. They also implement Map and Iterator interfaces. Classes and their Corresponding interfaces are listed :
Array List Implementation// Using the methods of array list class import java.util.*;
class Num
{
public static void main(String args[])
{
ArrayList num = new ArrayList ();
num.add(9);
num.add(12);
num.add(10);
num.add(16);
num.add(6);
num.add(8);
num.add(56);
//printing array list
System.out.println("Elements : ");
num.forEach((s) -> System.out.println(s));
//getting size
System.out.println("Size of array list is: ");
num.size();
//retrieving specific element
int n = (Integer) num.get(2);
System.out.println(n);
//removing an element
num.remove(4);
//printing array list
System.out.println("Elements : ");
num.forEach((s) -> System.out.println(s));
}
}
Linked List Implementation
import java.util.Scanner;
class LinkedList
{
public static void main (String args[])
{
Scanner s = new Scanner(System.in);
List list = new List();
System.out.println("Enter the number of elements you want to enter in LL : ");
int num_elements = s.nextInt();
int x;
for(int i =0;i<=num_elements;i++)
{
System.out.println("Enter element : ");
x = s.nextInt();
list.insert(x);
}
System.out.println(">>>>> LINKED LIST AFTER INSERTION IS : ");
list.print();
int size = list.count();
System.out.println(">>>>> SIZE OF LL => "+size);
System.out.println("Enter the node to be inserted in the middle: ");
int mid_element = s.nextInt();
list.insertMiddle(mid_element);
System.out.println(">>>> LL AFTER INSERTING THE NEW ELEMENT IN THE MIDDLE ");
list.print();
}
}
HashSet Implementationimport java.util.*;
class HashSetExample
{
public static void main(String args[])
{
HashSet hs = new HashSet();
hs.add("D");
hs.add("W");
hs.add("G");
hs.add("L");
hs.add("Y");
System.out.println("The elements available in the hash set are :" + hs);
}
}
Tree Set Implementationimport java.util.*;
class TreeSetExample
{
public static void main(String args[])
{
TreeSet ts = new TreeSet();
ts.add("D");
ts.add("W");
ts.add("G");
ts.add("L");
ts.add("Y");
System.out.println("The elements available in the tree set are :" + ts);
}
}
Vector Class Implementationimport java.util.*;
class VectorExample
{
public static void main(String args[])
{
Vector fruits = new Vector ();
fruits.add("Apple");
fruits.add("Orange");
fruits.add("Grapes");
fruits.add("Pineapple");
Iterator it = fruits.iterator();
while (it.hasNext())
{
System.out.println(it.next);
}
}
}
Stack Class Implementationimport java.util.*;
public class StackExample
{
public static void main (String args[])
{
Stack st = new Stack ();
st.push("Java");
st.push("Classes");
st.push("Objects");
st.push("Multithreading");
st.push("Programming");
System.out.println("The elements in the Stack : " + st);
System.out.println("The elements at the top of Stack : " + st.peek());
System.out.println("The elements popped out of the Stack : " + st.pop());
System.out.println("The elements in the Stack after pop of the element : " + st);
System.out.println("The result of search : " + st.search ("r e"));
}
}
HashTable Class Implementationimport java.util.*;
public class HashTableExample
{
public static void main (String args[])
{
Hashtable ht = new Hashtable();
ht.put("Item 1","Apple");
ht.put("Item 2","Orange");
ht.put("Item 3","Grapes");
ht.put("Item 4","Pine");
ht.put("Item 5","Kiwi");
Enumeration e = ht.keys();
while(e.hasMoreElements())
{
String str = (String) e.nextElement();
System.out.println(ht.get(str));
}
}
}
Memory Management In JavaMemory is a collection of data represented in binary format. Memory management is :
Example Illustrating Memory Management
Some Common Java Coding Questions Enter radius and print diameter, perimeter, and areaHere is the code: import java.util.Scanner;
class Circle
{
public static void main (String args [])
{
double r,dia,peri,area ;
System.out.println("Enter the radius of circle : ");
Scanner s = new Scanner (System.in);
r = s.nextDouble();
dia = 2*r;
peri = 2*Math.PI*r;
area = Math.PI*r*r;
System.out.printf("The dia of circle is : %.2f \n", dia);
System.out.printf("The peri of circle is : %.2f \n", peri);
System.out.printf("The area of the circle is : %.2f \n", area);
}
}
Print all the even numbers between x and y.Here is the code: import java.util.Scanner;
class EvenOdd
{
public static void main (String args[])
{
int x,y;
Scanner s = new Scanner (System.in);
System.out.println("Enter the values x , y : ");
x = s.nextInt();
y = s.nextInt();
System.out.println(" **** EVEN NUMBERS BETWEEN GIVEN RANGE ARE **** >> ");
int count = x;
while(count <=y)
{
if(count % 2 == 0)
{
System.out.println(count);
}
count ++;
}
}
}
To check if the given number is primeHere is the code: import java.util.Scanner;
class Prime
{
public static void main (String args[])
{
double num;
int n;
boolean isPrime = true;
Scanner s = new Scanner(System.in);
System.out.println("Enter the number to check :");
num=s.nextDouble();
n = (int) Math.sqrt(num);
for(int i=2;i<=n;i++)
{
if(num % i == 0)
{
isPrime = false;
}
else
{
isPrime = true;
}
}
if(isPrime)
{
System.out.println("***** NUMBER IS PRIME !!!! ****** ");
}
else
{
System.out.println("***** NUMBER IS NOT PRIME !!!! ****** ");
}
}
}
To check if the entered number is PalindromeHere is the code: import java.util.Scanner;
class Palindrome
{
public static void main(String args[])
{
int num,reverse=0,mode;
Scanner s = new Scanner(System.in);
System.out.println("Enter a number to check for Palindrome: ");
num = s.nextInt();
int number = num;
while(num!=0)
{
//System.out.println(" number entering = "+num);
mode = num % 10;
//System.out.println(" mode = "+mode);
reverse =(reverse * 10 )+ mode;
//System.out.println(" reverse = "+reverse);
num = num/10;
//System.out.println(" new num = "+num);
}
//System.out.println(" reverse out = "+reverse);
if(reverse == number)
{
System.out.println(" **** PALINDROME !!! **** ");
}
else
{
System.out.println(" **** NOT A PALINDROME !!! **** ");
}
}
}
Pattern printing* * * * * * * * * * * * * * * Here is the code: import java.util.Scanner;
class TriStars
{
public static void main(String args[])
{
for(int i=0;i<=5;i++)
{
for(int j=0;j<i;j++)
{
System.out.print(" * ");
}
System.out.println();
}
System.out.println();
}
}
SummaryCreated in 1995, object-oriented programming, Java, was developed to overcome the flaws of modular programming. Java introduced concepts like Abstraction, Encapsulation for robust and secure code. Java Programming Masterclass updated to Java 17 Similarly, the concept of Polymorphism, Inheritance, and Classes removed redundancy in the code. In addition, Java offers Collection Interface that implements data structures like Arrays, Lists, HashMap, and more. Java is used in various sectors like internet security, Android Development, Web Development, and more. Did you find this article helpful? Do you know other applications of Java? Comment below and share your learning with us!! People are also reading:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |