Chapter Two

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 78

1

WOLKITE UNIVERSITY

CHAPTER
TWO
Basics in Java Programming

COMPILED BY: Minichil A.

YEAR: 2016
2
Structure of Java Program
General Syntax

class Classname
{
Data;
Methods()
{
Statements;
}
}
3
Simple Java Program

Example 1.

public class FirstExample{

public static void main(String[] args)


{
System.out.println(“WelCome To First Java Program”);
}

}
4

Cont..
Class File

Method 1
 Put a class in a source fi le. statement
 Put methods in a class. Method 2
statement
 Put statements in a method statement

Source File
5

Code Structure in Java

Public class FirstExample


{

What goes in a source file?


}

 A source code file (with the .java extension) holds


one class definition.
 The class represents a piece of your program

Class
6

Cont..

public class FirstExample


{
public static void main(String[] args)
What goes in a class? {
}
 A class has one or more methods . }
 Your methods must be declared inside
a class (in other words, within the curly
braces of the class)

Method
7

Cont..

public class FirstExample


{
What goes in a method? public static void main(String[] args)
{
System.out.println(“Welcome To First Java
Program”);
 Within the curly braces of a method, write your
}
instructions for how that method should be }
performed.
 Method code is basically a set of statements

Statements
Cont.… 8

Example 2

class FirstProgram
{
public static void main(String[] args)
{
System.out.println("This is my first program");
}
}
Cont.… 9

 The file should be named “FirstProgram.java” to equivalent the class name


containing the main method
 Since Java is case sensitive a class name defines “FirstProgram”.
 A class is an object oriented term & it is designed to perform a specific task.
 A Java class is defined by its class name, an open curly brace, a list of methods
and fields, and a close curly brace
Cont.… 10

 The name of the class is made of alphabetical characters and digits without spaces, the
first character must be alphabetical.
 The line “public static void main (String[] args )”‖ shows where the program will start
running.
 Java system handling begins from the main() function, which is a required piece of each
Java program.
 The JVM starts running any program by executing this method first.
 The main method in “FirstProgram.java”‖ consists of a single statement

System.out.println("This is my first program");


Cont.… 11
Cont.… 12

Life Cycle of java code


Cont.… 13

Steps for Developing a Java program


Basically there are five steps to execute a java application or program .

Create Load Verify Execute


Compile
Cont.… 14

Phase 1: Creating a program

 It deals with editing or writing a java source code program using different
editor platforms.
 Examples of IDEs: Apache NetBeans, Eclipse, Notepad++, JCreator etc.
 Java source code files are given a name ending with.java extension to indicate
that the file contains a java source code.
Cont.… 15

Phase 2: Compiling a java program


 A java compiler is a program that takes the source code file and compiles it into a platform-
independent java file.
 The java compiler translates Java source code into bytecodes that represent the tasks to
execute in the execution phase.
 In this phase you use the command javac( the Java compiler) to compile a program.
 For example to compile the previous java program in example 2: FirstProgram.java
You would type javac FirstProgram.java
If the program is compiled, the compiler produces a .class file called FirstProgram.class
Cont.… 16

 A java compiler is a program that takes the source code file and compiles it into a platform-
independent java file.
 The java compiler translates Java source code into bytecodes that represent the tasks to
execute in the execution phase.
 In this phase you use the command javac( the Java compiler) to compile a program.
 For example to compile the previous java program in example 2: FirstProgram.java
You would type javac FirstProgram.java
If the program is compiled, the compiler produces a .class file called FirstProgram.class
Cont.… 17

 The JVM is an abstract machine that provides a runtime environment in which


java bytecode can be executed.
 The JVM is invoked by the java command
 For example, to execute a java program which is called FirstProgrm
You should type java FirstProgram
 In this stage phase, 3 is started
Cont.… 18

Phase 3: Loading a java program

 In this phase the JVM places the program in memory to execute it, this is known as
loading
 The JVM class loader takes the .class files containing the program’s bytecodes and
transfers them to primary memory.
 The class loader also loads any of the .class files provided by Java that your program
uses
 The .class files can be loaded from a disk on your system or over a network
Cont.… 19

Phase 4: Bytecode Verification

 In Phase 4, as the classes are loaded, the bytecode verifier examines their
bytecodes to ensure that they’re valid and do not violate Java’s security
restrictions.
 Java enforces strong security to make sure that Java programs arriving over the
network do not damage your files or your system (as computer viruses and
worms might)
Cont.… 20

Phase 5: Execution

 In phase 5, the JVM executes the program’s bytecodes, thus performing the
actions specified by the program.
 Today’s JVMs typically execute bytecodes using a combination of
interpretation and so-called just-in-time(JIT) compilation.
 In this process, the JVM analyzes the bytecodes as they’re interpreted,
searching for hotspot parts of the bytecode.
Cont.… 21

 A just-in-time compiler known as the java HotSpot compiler translates the


bytecodes into the underlying computer’s machine language.
 When the JVM encounters these compiled parts again, the faster machine-
language code executes.
 Thus java programs go through two compilation phases

1 Source code is translated into bytecodes

2 During execution, the bytecodes are translated into machine language


for the actual computer on which the program executes
Cont.… 22

Java Variables

 A variable is a container that holds the value while the java program is executed.
 A variable is assigned with a data type
 A variable is the name of the reserved area allocated in memory.

 int data=50;//Here data is variable


RAM

Reserved Area
50
Cont.… 23

Types of variables
Several types of variables are supported by Java. These types of variables include:

1 Instance variables (Non-static variables)

2 Local variables

3 Class variables (Static variables)


Cont.… 24

1
Instance variable (Non-static variables)
 A variable that is declared inside a class but outside the method is called instance
variable
 Can be accessed directly by calling the variable name inside the class
 Instance variables are created when an object is created with the use of the keyword
‘new’ and destroyed when the object is destroyed.
 Holds values that must be referenced by more than one method, constructor or block, or
essential parts of an object’s state that must be present throughout the class.
Example 1: 25

public class InstanceExample1 {


String myInstanaceVar = "Instance Variable";
Instance variable
public static void main(String[] args) {
InstanceExample1 obj1 = new InstanceExample1();
InstanceExample1 obj2 = new InstanceExample1(); Object instantiations
System.out.println(obj1.myInstanaceVar);
System.out.println(obj2.myInstanaceVar);
Output:
obj1.myInstanaceVar = "Updated Instance Variable";
System.out.println(obj1.myInstanaceVar);
System.out.println(obj2.myInstanaceVar); Instance Variable
} Instance Variable
}
Updated Instance Variable
N.B: Instance variables have default values. For Numbers default is 0 Instance Variable
for Booleans it is false and for object references it is null.
Cont.… 26

2 Local variable
 A variable that is declared inside the body of a method is called local variable
 Local variables are declared in methods, constructors or blocks.
 Local variables are created when the method, constructor or block is entered and the
variable will be destroyed once it exists the method, constructor or block
 Access modifiers can be used in local variables
 Can be visible only within the declared method, constructor or block.
 There is no default value for local variables so local variables should be declared and
an initial value should be assigned before the first use
Example 2: 27

public class LocalExample2


{
public String myVar = "Instance Variable";
public void lMethod()
{
String myVar = "Local Variable"; Local variable
System.out.println(myVar);
}
public static void main(String args[])
{
Output:
LocalExample2 lobj = new LocalExample2();
System.out.println("This Is Calling"); This Is Calling
lobj.lMethod(); Local Variable
System.out.println(lobj.myVar); Instance Variable
}
}
Cont.… 28

2
Static variable (class variable)
 Static variables are also known as class variable because they are associated with the class
and common for all the instances of class.
 Static variables are declared with the static keyword in a class.
 You can create a single copy of the static variable and share it among all the instances of the
class.
 Static variables are rarely used other than being declared as constants.
 Constants are variables that are declared as public or private, final and static.
Cont.… 29

 There would only be one copy of each class variable per class, regardless of how many
objects are created from it.
 Static variables are created when the program stars and destroyed when the program stops
 Visibility is similar to instance variables. However, most static variables are declared public
since they must be available for the users of the class
 Default values are the same as instance variables.
 Static variables can be accessed by calling the class name. ClassName.VariableName
Example 3: 30

public class StaticExam2 {


public static String statVar = "Static Variable"; Static variable
public static void main(String[] args) {
StaticExam2 sobj1 = new StaticExam2();
System.out.println(sobj1.statVar);
sobj1.statVar = "Changed Static Variable";
Output:
System.out.println(sobj1.statVar);
System.out.println(StaticExam2.statVar);
Static Variable
} Changed Static Variable
} Changed Static Variable
Cont.… 31

Identifiers in java
Identifiers are used to name things, such as classes, variables, and methods.
Identifiers must respect a few rules to allow the code to compile and also common-sense
programming rules, called Java coding conventions.
In Java, there are a few focuses to recall about identifiers. They are as per the following
standard

1 All identifiers ought to start with a letter, underscore (_) or special


character ($).
2 An identifier cannot be one of the Java reserved words
Cont.… 32

Literals in java
A constant value in Java is created by using a literal representation
It can be digits, letters, or others that represent constant value to be stored in variables.
Literals are used to create values that are assigned to variables, used in expressions, and
passed to methods
A literal can be used anywhere a value of its type is allowed
For example, here are some literals:

Left to right, the first literal specifies an integer, the next is a floating-point value, the third is
a character constant, and the last is a string.
Cont.… 33

Data types in java


Java has two basic data types
1
Primitive Data Types

2 Non-Primitive-Data Types

1 Primitive Data Types

There are eight primitive information types, which are supported by Java.
Primitive data types are predefined by the dialect and named by a catchphrase
Data types in java 34

Primitive Non-Primitive

Boolean Arrays
boolean

Character Strings
char

Floating Point float doubl Classes


e
Interfaces
Integer byte short int long
Objects
Cont.… 35

 Integers This group includes byte, short, int, and long, which are for whole-valued signed
numbers.
 Floating-point numbers This group includes float and double, which represent numbers
with fractional precision.
 Characters This group includes char, which represents symbols in a character set, like
letters and numbers.
 Boolean This group includes boolean, which is a special type for representing true/false
values.
Cont.… 36

Comments in java
Java comments refer to pieces of explanatory text that are not part of the code executed and
are ignored by the compiler.
There are three types of comments defined by Java

1 Single Line Comment // is used for single line


comments
2 Multiline Comment /* ... */ used for multiline comments

3 Documentation Comment /** ... */ Javadoc comments


Cont.… 37

Java Reserved Words


 These keywords, combined with the syntax of the operators and separators, form the
definition of the Java language
 These keywords cannot be used as names for a variable, class, or method
abstract assert boolean byte char
short int long float double
break continue switch case default
try finally throw throws class
catch
interface extends implements enum const
final do while for goto
if else import instanceof native
new package public private protected
return static stricfp super this
synchronized transient volatile void _(underscore)
Java Reserved Words 38

Reserved words for data types: (8) Reserved words for flow control:(11)
1) byte 1) if
2) else
2) short
3) switch
3) int
4) case
4) long 5) default
5) float 6) for
6) double 7) do
8) while
7) char
9) break
8) boolean
10) continue
11) return
Java Reserved Words 39

Keywords for modifiers:(11) Keywords for exception handling:(6)


1) public 1) try
2) private
2) catch
3) protected
3) finally
4) static
5) final 4) throw
6) abstract 5) throws
7) synchronized 6) assert
8) native
9) strictfp
10) transient
11) volatile
Java Reserved Words 40

Class related keywords:(6)


Object related keywords:(4)
1) class
1) new
2) package
2) instanceof
3) import
3) super
4) extends
4) this
5) implements
 Void return type keyword: (1)
6) interface
1) Void
 Void return type keyword: (2)
 Reserved literals: (1) enum (1)
1) goto 1) true
2) false
2) const 3) null
Cont.… 41

Escape Sequences
 Java support some special character constant which are given in following table.

Escape Sequence Description


\’ Single Quote
\” Double Quote
\\ Backslash
\r Carriage return
\n New line
\f Form feed
\t Tab
\b Backspace
Operators in Java 42
1 Arithmetic Operators

2 Relational Operators

 The operator set in Java is extremely rich Logical Operators


3
 Operators are used in programs to operate data and variables
 Operators in Java are divided in the following categories:
4 Bitwise Operators

5
Assignment Operators

6 Conditional operators

7 Increment & Decrement Operators


Cont.… 43

Arithmetic Operators
Operations in Java are used in essentially the same manner as in algebra.
 They are used with variables for performing arithmetic operations
Here is a list of arithmetic operators available in Java.

Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
Cont.. 44

Examples
Addition Subtraction
class AdditionInt { class SubtractionInt {
public static void main(String args[]) public static void main(String args[])
{ {
int num1 = 10; int a = 20;
int num2 =20; int b =10;
int sum; int sub;
sum = num1+num2; sub = a-b;
System.out.println("Addition =:"+sum); System.out.println("Subtraction =:"+sub);
} }
} }
Output: Addition=:30 Output: Subtraction=:10
Cont.. 45

Examples
Multiplication Division
class MultiplicationInt { class DivisionInt {
public static void main(String args[]) public static void main(String args[])
{ {
int a = 6; int a = 10;
int b =2; int b =2;
int mult; int div;
sum = a*b; div = a/b;
System.out.println(“Multiplication =:"+mult); System.out.println(“Division =:"+div);
} }
} }
Output: Multiplication=:12 Output: Division=:5
Cont.… 46

Relational Operators
Java also supports several relational operators.
The list of relational operators that are supported by Java are given below

Operator Operation

== Equal To

=! Not Equal To

> Greater Than

< Lesser Than

>= Greater Than Or Equal To

<= Less than or Equal To


Cont.… 47

Relational operators Example 1


public class Truth{

Now, following examples show the actual public static void main(String[] args) {
int a = 10;
use of operators. int b = 30;
System.out.println("a>b = " +(a>b));
1) If 10 > 30 then result is false System.out.println("a<b = "+(a<b));
System.out.println("a<=b = "+(a<=b));
2) If 40 > 17 then result is true }
3) If 10 >= 300 then result is false }
. Output:
4) If 10 <= 10 then result is true a>b = false
a<b = true
a<=b = true
Cont.… 48

Logical Operators
Logical operators are an integral part of any operator set.
The logical operators supported by Java are listed in the table below
public class BooleanLogic{
Operator Operation public static void main(String[] args) {
boolean a = true;
&& Logical AND boolean b = false;
System.out.println("a||b = " +(a||b));
System.out.println("a&&b = "+(a&&b));
|| Logical OR System.out.println("a! = "+(!a));
}
} Output:
! Logical NOT
. a||b = true
a&&b = false
a! = false
49

Input/Output Statements in Java

Syntax
Scanner Object_name = new Scanner(System.in);
Variable_name = object_name.nextDatatype();
Example:
Scanner input = new Scanner(System.in);//an object used to access the methods of
input
int int_number=input.nextInt();//to read integer number from keyboard
byte byte_number=input.nextByte();//to read integer number from keyboard
char c =input.next().charAt(0); //to read a single character
Cont.… 50

short short_number=input.nextShort();//to read integer number from keyboard


long long_number=input.nextLong();//to read integer number from keyboard
double double_number=input.nextDouble();//to read float number from keyboard
float float_number=input.nextFloat();//to read float number from keyboard
boolean condition=input.nextBoolean();to read string of true/false from keyboard

Example
 Write a java program that displays the sum of two numbers?
 Write a java program that calculates the square of any number?
Cont.… 51

import java.util.Scanner;

public class Sum {


public static void main(String[] args) {
int first_number;
int second_number; Output
int sum;
Scanner input = new Scanner(System.in);
System.out.println("Enter The First Number:");
first_number = input.nextInt(); Enter The First Number: 10
System.out.println("Enter The Second Number:");
Enter The Second Number: 20
second_number = input.nextInt();
The Sum of Numbers
sum = first_number+second_number;
is:=30
System.out.println("The Sum of Numbers is:="+sum);
}
}
Type conversion and Casting 52

In programming, it is common to assign one type of variable to another.


It is fairly common to assign a value of one type to a variable of another type
If the two types are compatible, then Java will perform the conversion automatically
For example, it is always possible to assign an int value to a long variable
 However, not all types are compatible, and thus, not all type conversions are allowed
For instance, there is no conversion defined from double to byte.
Fortunately, it is still possible to obtain a conversion between incompatible types.
To do so, you must use a cast, which performs an explicit conversion between incompatible
types
Java’s Automatic Conversions 53

When one type of data is assigned to another type of variable, an automatic type conversion
will take place if the following two conditions are met:
1 The two types are compatible.

2 The destination type is larger than the source type

When these two conditions are met, a widening conversion takes place
For example, the int type is always large enough to hold all valid byte values
For widening conversions, integer and floating-point types, are compatible with each other.
However, there are no automatic conversions from the numeric types to char or boolean.
Also, char and boolean are not compatible with each other.
Examples 54
Casting Incompatible Types 55

Although the automatic type conversions are helpful, they will not fulfill all needs
This kind of conversion is sometimes called a narrowing conversion, since you are explicitly
making the value narrower so that it will fit into the target type
To create a conversion between two incompatible types, you must use a cast
A cast is simply an explicit type conversion.
It has a general form: (target-type) value
Here, target-type specifies the desired type to convert the specified value to
For example int a;
byte b;
b = (byte) a;
Example 56

class ConversionDemo
{
public static void main(String args[])
{
byte b;
int i = 257;
double d = 323.142; Output
System.out.println("\nConversion of int to byte.");
b = (byte) i; Conversion of int to byte.
System.out.println("i and b " + i + " " + b); i and b 257 1
System.out.println("\nConversion of double to int.");
i = (int) d;
System.out.println("d and i " + d + " " + i); Conversion of double to int.
System.out.println("\nConversion of double to byte."); d and i 323.142 323
b = (byte) d;
System.out.println("d and b " + d + " " + b); Conversion of double to byte.
}
}
d and b 323.142 67
Control Statements 57

In Java, program is a set of statements and which are executed sequentially in order in which
they appear
A programming language uses control statements to cause the flow of execution to advance
and branch based on changes to the state of a program.
Java’s program control statements can be put into the following categories :

1 Selection Statement

2 Iteration Statement

3 Jump Statement
Selection Statements 58

Java supports two selection statements: if and switch

1 If Statement 2 If ……else Statement

Syntax:
If (condition)
{
Statement block;
}
Selection Statements 59

3 Nested ifs …Statement 4 If-else-if …Statement


Syntax:
if (condition1)
{
If(condition2)
{
Statement block1;
}
else
{
Statement block2;
}
else
{
Statement block3;
}
}
Selection Statements 60

5 Switch Statement
In Java, switch statement check the value of given variable or statement against a list of case
values and when the match is found a statement-block of that case is executed .
switch(expression)
{
case constant1:
Statement sequence
break;
case constant2:
statement sequence
break;
case constant3:
statement sequence
break;
……….
default:
statement sequence
}
Selection Statements 61

Example:
public class Switch_Example1 {
public static void main(String[] args) {
for (int i = 0; i<6; i++){
switch (i) {
case 0:
System.out.println("Value is:"+i);
break; Output
case 1:
System.out.println("Value is:"+i);
break;
case 2:
Value is:0
System.out.println("Value is:"+i); Value is:1
break;
case 3: Value is:2
System.out.println("Value is:"+i); Value is:3
break;
default: Here is default value
System.out.println("Here is default value");
}
Here is default value
}
}
}
Iteration Statement 62

Java’s iteration statements are for, while, and do-while. These statements create what we
commonly call loops

Syntax: Syntax: Syntax:


for(initialization; condition ;iteration) While(condition) do
{ { {
Statement block; Statement block; Statement block;
}
} }
While(condition);

02 03
1 For loop 2 while loop Do-while loop
3
Iteration Examples 63

Example: to display from 1 up to 10 integer number

class Number
{
public static void main(String args[])
{
int i;
System.out.println("list of 1 to 10 numbers:");
for(i=1;i<=10;i++)
{
System.out.print(" "+i);
}
} list of 1 to 10 numbers:
} 1 2 3 4 5 6 7 8 9 10
Iteration Examples 64

Example: to display from 1 up to 10 integer number

class Number
{
public static void main(String args[])
{
int i=1;
System.out.println("list of 1 to 10 numbers");
while(i<=10)
{
System.out.print(""+i);
i++;
list of 1 to 10 numbers:
}
1 2 3 4 5 6 7 8 9 10
}
}
Iteration Examples 65

Example: to display from 1 up to 10 integer number


class Number
{
public static void main(String args[])
{
int i=1;
System.out.println("list of 1 to 10 numbers");
do
{
System.out.print(" "+i);
i++;
}
list of 1 to 10 numbers:
while(i<=10);
1 2 3 4 5 6 7 8 9 10
}
}
Jump Statements 66

Java supports three jump statements:


 break
 continue
 return
1 Using break

 In Java, the break statement has two uses


 It terminates a statement sequence in a switch statement
 It can be used to exit a loop
Jump Statements 67

 Using break to exit a loop


 By using break, you can force immediate termination of a loop, bypassing the conditional
expression and any remaining code in the body of the loop
public class BreakLoop {

public static void main(String[] args) {


for (int i = 0; i<100; i++) {
i: 0
if (i == 5)
i: 1
break;
i: 2
System.out.println("i: " +i);
i: 3
}
i: 4
System.out.println("Loop Complete");
Loop Complete
}
}
Jump statements 68

2 Using continue

 It is possible to force an early iteration of a loop, bypassing the loop’s normal control structure
 The continue statement forces the next iteration of the loop to take place, skipping any code between itself and
the conditional expression that controls the loop

public class TestContinue {

public static void main(String[] args) {


for (int i=0; i<10; i++)
01
{
System.out.print(i +" "); 23
if (i%2 == 0) 45
continue;
67
System.out.println("");
} 89
}
}
Arrays 69

An array is an indexed collection of fixed number of homogeneous data elements..


Arrays of any type can be created and may have one or more dimensions.
A specific element in an array is accessed by its index
Arrays offer a convenient means of grouping related information.
1 Single-Dimensional-Array
To create an array, you first must create an array variable of the desired type.
 The general form of a one-dimensional array declaration is
type var-name[];
var-name = new type[size]
type var-name[] = new type[size]
Array Example 1 70

public class TestArrays {


public static void main(String[] args) {
int month_days[];
month_days = new int[12];
month_days[0] = 31;
month_days[1] = 28;
month_days[2] = 31;
month_days[3] = 30; April has 30 days.
month_days[4] = 31;
month_days[5] = 30;
month_days[6] = 31;
month_days[7] = 31;
month_days[8] = 30;
month_days[9] = 31;
month_days[10] = 30;
month_days[11] = 31;
System.out.println("April has " + month_days[3] + " days.");
}
}
Array Example 2 71

public class ArrayAverage {

public static void main(String[] args) {


double num[] = {5.2,12.5,8.4,20.2,18.6};
double average;
double sum = 0;
for (int i=0; i<5;i++)
{
sum = sum+num[i]; The Average of numbers is: 12.98
}
average = sum/5;
System.out.println("The Average of numbers is: "+average);
}
}
Arrays 72

2 Multidimensional Arrays

In Java, multidimensional arrays are implemented as arrays of arrays.


To declare a multidimensional array variable, specify each additional index using another set
of square brackets.
Syntax to Declare Multidimensional Array in Java
 datatype[][] arrayRefVar; (or)
 datatype [][]arrayRefVar; (or)
 datatype arrayRefVar[][]; (or)
 datatype []arrayRefVar[];
Arrays 73

Example to instantiate Multidimensional Array in Java


int[][] arr=new int[4][5];//4 row and 5 column
This allocates a 4 by 5 array and assigns it to arr. Internally, this matrix is implemented as
an array of arrays of int
Array Example 1 74

public class MultidimenstionalArray {

public static void main(String[] args) {


// declaring and initializing 2D array
int arr[][] = { {2,7,9},{3,6,1},{7,4,2} };

// printing 2D array
for (int i=0; i< 3 ; i++)
{
for (int j=0; j < 3 ; j++) 279
System.out.print(arr[i][j] + " "); 361
System.out.println(); 742
}
}
}
Strings 75

 Generally, a String is a sequence of characters. But in Java, a string is an object that represents a sequence of
characters.
 Syntax : String variabl_name; Or String variable_name= new String(“statement ”);
class MainString {
public static void main(String[] args) {

// create strings
String first = "Java";
String second = "Python";
String third = "JavaScript";

// print strings
System.out.println(first); // print Java
System.out.println(second); // print Python
System.out.println(third); // print JavaScript
}
}
Strings 76

1 Java String Operations


 Java String provides various methods to perform different operations on strings.
 Get the length of a String
 To find the length of a string, we use the length() method of the String
 Join Two Java Strings
 We can join two strings in Java using the concat() method
 Compare two Strings
 In Java, we can make comparisons between two strings using the equals() method
 Java String toUpperCase()
 Java String toLowerCase()
String Examples 77
String Example 2 78

You might also like