0% found this document useful (0 votes)
12 views99 pages

Java M1

Java basics

Uploaded by

sood.vartika9905
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
12 views99 pages

Java M1

Java basics

Uploaded by

sood.vartika9905
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 99

Class Assessment-Tutorial(Practicals (1-16) 5

Group Activity-Powerpoint Presentation/Quiz 5


CA+CT+Viva(Based on Java Project) (10+10+5)=25
Related to java database connectivity
Java Project Ideas For Beginners

•Online Courier Services Java Project •Email Client Software


•Online Voting System •Library Management System
•E-HealthCare Management •Network Packet Sniffer
•Online Banking •Online Medical Management System
•Online Examination •Online Survey System
•Smart-city Project •RSS Feed Reader
•Bug Tracking System •Stock Management System
•Facial Recognition •Supply Chain Management System
•Vehicle Recognition •Virtual private network
•Speech Recognition •Word Count Tools in Java
•Airline Reservation System •Create a Consumer Relationship
•Data Visualization Software Management System
•Electricity Billing System •bFit Cognitive and Memory Testing Game
•Internet Service Provider Automation System
Project Report
1. Introduction
2. Problem Statement
3. Objectives
4. Methodology used-System Design/Data Flow
Diagram/Architecture Diagram
5. Technologies Used
6. Database Schema
7. Implementation
8. Conclusion
9. Future Work
MODULE -1
The latest version of Java is Java 22 or
JDK 22 released on March, 19th 2024
(javac)
(Bytecode)
Java JVM, JRE and JDK

JDK in Java
The Java Development Kit (JDK) is a cross-platformed
software development environment that offers a collection
of tools and libraries necessary for developing Java-based JDK=JRE+Development Tools
software applications and applets. It is a core package used
in Java, along with the JVM (Java Virtual Machine) and the
JRE (Java Runtime Environment).
if you are only interested in running Java programs on your machine then you can easily do it using Java Runtime
Environment. However, if you would like to develop a Java-based software application then along with JRE you
may need some additional necessary tools, which is called JDK.

The Java Development Kit is an implementation of one


of the Java Platform:
•Standard Edition (Java SE),
•Java Enterprise Edition (Java EE),
•Micro Edition (Java ME),

The JDK has a private Java Virtual Machine (JVM) and a few other resources necessary for the development of a
Java Application.
JDK contains:
•Java Runtime Environment (JRE),
•An interpreter/loader (Java),
•A compiler (javac),
•An archiver (jar) and many more.
1. JDK (Java Development Kit) is a Kit that provides the environment to develop and execute(run) the Java
program. JDK is a kit(or package) that includes two things
•Development Tools(to provide an environment to develop your java programs)
•JRE (to execute your java program).

2. JRE (Java Runtime Environment) is an installation package that provides an environment to only run(not
develop) the java program(or application)onto your machine. JRE is only used by those who only want to run Java
programs that are end-users of your system.

3. JVM (Java Virtual Machine) is a very important part of both JDK and JRE because it is contained or inbuilt in
both. Whatever Java program you run using JRE or JDK goes into JVM and JVM is responsible for executing the
java program line by line, hence it is also known as an interpreter.

JVM (Java Virtual Machine) Architecture


1.Java Virtual Machine
2.Internal Architecture of JVM
JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java
bytecode can be executed.
JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).
JIT is a part of the JVM that optimizes the performance of the application. JIT stands for Just-In-Time Compiler. The JIT
compilation is also known as dynamic compilation. Just-In-Time (JIT) Compiler
• A just-in-time (JIT) compiler is a type of compiler that converts instructions into machine code while a program is being
executed.
• These compilers are used to improve the performance of interpreted programs by compiling the most frequently executed
parts of the program into machine code that can be directly executed by the computer’s hardware.
• JIT compilers can also optimize the compiled code by inlining functions and eliminating redundant instructions.
• JIT compilers provide a balance between the speed of compilation and the debugging capabilities of interpreters, and in
some cases may even offer better performance than static compilation.
• This is because many optimization techniques can only be performed at runtime.
• Overall, JIT compilers allow us to enjoy the benefits of both compilation and interpretation: the ability to debug code
easily and the speed of compilation. Examples of common JIT compiled languages are JavaScript, Java and Python can also
be JIT compiled using PyPy.
Java Native Interface
Java Native Interface (JNI) is a framework which provides an interface to communicate with another application written in
another language like C, C++, Assembly etc. Java uses JNI framework to send output to the Console or interact with OS
libraries.

BRIDGE
Increases performance
by using reused codes

affects performance by
line by line
interpretation
Java language features
•Simple: Java was designed with a small number of language constructs so that programmers
could learn it quickly. It eliminates several language features available in C/C++ that are
associated with poor programming practices or rarely used
•Object Oriented: In java everything is Object which has some data and behaviour. Java can be
easily extended as it is based on Object Model.
•Distributed; Java is designed to support various levels of network connectivity. Java
applications are network aware: TCP/IP support is built into Java class libraries. They can open
and access remote objects on the Internet.
•Interpreted: Java is compiled to bytecodes, which are interpreted by a Java run-time
environment.
•Robust: Java is designed to eliminate certain types of programming errors. Java is strongly
typed, which allows extensive compile-time error checking. It does not support memory
pointers, which eliminates the possibility of overwriting memory and corrupting data. In
addition, its automatic memory management (garbage collection) eliminates memory leaks and
other problems associated with dynamic memory allocation/de-allocation.
Java language features
•Secure: Java is designed to be secure in a networked environment. The Java run-time
environment uses a bytecode verification process to ensure that code loaded over the network
does not violate Java security constraints.
•Architecture Neutral: Java applications that are compiled to bytecodes can be interpreted by
any system that implements the Java Virtual Machine. Since the Java Virtual Machine is
supported across most operating systems, this means that Java applications are able to run on
most platforms.
•Portable: In addition to supporting architecture neutrality, Java ensures that other
implementation-dependent aspects of language specification are eliminated. For example, Java
specifies the sizes of primitive data types and their arithmetic behavior.
•High Performance: Although Java is an interpreted language, it was designed to support “just-
in-time” compilers, which dynamically compile bytecodes to machine code.
•Multithreaded: Java supports multiple threads of execution (a.k.a., lightweight processes),
including a set of synchronization primitives. This makes programming with threads much easier.
•Dynamic Language: Java supports dynamic loading of classes (a.k.a. “load on demand”),
dynamic compilation, and automatic memory management (garbage collection)
Secured
Java is best known for its security. With Java, we can develop virus-free
systems. Java is secured because:
•No explicit pointer
•Java Programs run inside a virtual machine sandbox
Architecture-neutral
Java is architecture neutral because there are no implementation dependent features, for example, the size of primitive
types is fixed.
In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 64-bit
architecture. However, it occupies 4 bytes of memory for both 32 and 64-bit architectures in Java.
Difference Between C, C++ and Java
Difference Between C, C++ and Java
Hello Java Program

class Simple
{
public static void main(String args[])
{
System.out.println("Hello Java"); Save the above file as Simple.java.
}
} To compile:
javac Simple.java
To execute:
java Simple
Output:

Hello Java
Parameters used in First Java Program
•class keyword is used to declare a class in Java.
•public keyword is an access modifier that represents visibility. It means it is visible to
all.
•static is a keyword. If we declare any method as static, it is known as the static
method. The core advantage of the static method is that there is no need to create an
object to invoke the static method. The main() method is executed by the JVM, so it
doesn't require creating an object to invoke the main() method. So, it saves memory.
•void is the return type of the method. It means it doesn't return any value.
•main represents the starting point of the program.
•String[] args or String args[] is used for command line argument.
•System.out.println() is used to print statement. Here, System is a class, out is an
object of the PrintStream class, println() is a method of the PrintStream class.

public static void main(String[] args)


public static void main(String []args)
public static void main(String args[])
Java User Input (Scanner)
Java User Input
java.util package.
The Scanner class is used to get user input, and it is found in the
To use the Scanner class, create an object of the class and use any of the available methods found in the Scanner class.

it does not support nextChar in Java


Taking character input in Java isn’t as simple as taking input as a string or integer. The Scanner class in Java
works with nextInt(), nextLong(), nextDouble(), etc. However, it does not support nextChar in Java, which makes
taking character input slightly more complicated. If you’re looking to take char input in Java and nextChar() isn’t
working, here’s how you can take input as char properly.nextChar() scanner class in Java

There is no classical nextChar() method in Java Scanner class. The best and most simple alternative to taking char
input in Java would be the next().charAt(0). The charAt(0) command is used in combination with the simple next()
command which instructs Java to record the next character or string that is input into the command line. This input
can be a string, character, or numeral. The charAt command is a way to filter the unwanted data types and only
restricts the input to char data type. Since charAt only returns output in the form of a char value, it converts any
type of data type to a char type.

Scanner input = new Scanner (system.in);


char a = input.next().charAt(0);
Why is the Size of char 2 bytes in Java?
So, other languages like C/C++ use only ASCII characters, and to represent all ASCII characters 8 bits is
enough. But Java uses the Unicode system not the ASCII code System and to represent the Unicode system 8
bits is not enough to represent all characters so Java uses 2 bytes for characters. Unicode defines a fully
international character set that can represent most of the world’s written languages. It is a unification of dozens
of character sets, such as Latin, Greek, Cyrillic, Katakana, Arabic, and many more.
Why String Is Immutable in Java?

A String in Java that is specified as immutable, as the content shared


storage in a single pool to minimize creating a copy of the same value.
String class and all wrapper classes in Java that include Boolean,
Character, Byte, Short, Integer, Long, Float, and Double are immutable.
The key benefits of keeping this class as immutable are caching,
security, synchronization, and performance.
String Pool
Java String Pool is the special memory region where Strings are stored by the JVM. Since Strings are immutable in Java, the JVM optimizes the amount of
memory allocated for them by storing only one copy of each literal String in the pool.

Security
The String is widely used in Java applications to store sensitive pieces of information like usernames, passwords, connection URLs, network connections,
etc. Hence securing String class is crucial regarding the security of the whole application in general

Synchronization
Being immutable automatically makes the String thread safe since they won’t be changed when accessed from multiple threads.

Hashcode Caching
String objects are also widely used in hash implementations like HashMap, HashTable, HashSet, etc. The immutability guarantees Strings that their value
won’t change.

Performance
String pool exists because Strings are immutable. In turn, it enhances the performance by saving heap memory and faster access of hash implementations
when operated with Strings.
Operators in Java
Java provides many types of operators which can be used according to the need. They are classified based on the
functionality they provide.
What are the Java Operators?
Operators in Java are the symbols used for performing specific operations in Java. Operators make tasks like
addition, multiplication, etc

Types of Operators in Java


There are multiple types of operators in Java all are
mentioned below:
1.Arithmetic Operators
2.Unary Operators
3.Assignment Operator
4.Relational Operators
5.Logical Operators
6.Ternary Operator
7.Bitwise Operators
8.Shift Operators
9.instance of operator
1. Arithmetic Operators
They are used to perform simple arithmetic operations on primitive and non-primitive data types.
* : Multiplication
/ : Division
% : Modulo public static void main (String[] args) {
+ : Addition
– : Subtraction
Arithmetic operators on integers
int a = 10;
int b = 3;

System.out.println("a + b = " + (a + b));


System.out.println("a - b = " + (a - b));
System.out.println("a * b = " + (a * b));
System.out.println("a / b = " + (a / b));
System.out.println("a % b = " + (a % b));

}
}
Java Unary Operator
The Java unary operators require only one operand. Unary operators are used to perform
various operations (Post Increment(a++) and Pre Increment(--a)
Java Unary Operator Example: ++ and --
public class OperatorExample{
public static void main(String args[]){
int x=10;
System.out.println(x++);//10 (11)
System.out.println(++x);//12
System.out.println(x--);//12 (11)
System.out.println(--x);//10
}
}

Output:
10
12
12
10
Java Assignment Operators
Assignment operators are used to assign values to variables.
Java Comparison Operators
Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to
find answers and make decisions.

The return value of a comparison is either true or false. These values are known as Boolean values,
Java Logical Operators
You can also test for true or false values with logical operators.

Logical operators are used to determine the logic between variables or values:
Ternary Operator in Java
Java ternary operator is the only conditional operator that takes three operands. It’s a one-liner replacement for the
if-then-else statement and is used a lot in Java programming. We can use the ternary operator in place of if-else
conditions or even switch conditions using nested ternary operators. Although it follows the same algorithm as of
if-else statement, the conditional operator takes less space and helps to write the if-else statements in the shortest
way possible.
Syntax:
variable = Expression1 ? Expression2: Expression3

if(Expression1)
{
variable = Expression2;
}
else
{
variable = Expression3;
}
class Ternary {
public static void main(String[] args)
{

int n1 = 5, n2 = 10, max;

System.out.println("First num: " + n1);


System.out.println("Second num: " + n2);

max = (n1 > n2) ? n1 : n2;

// Print the largest number


System.out.println("Maximum is = " + max);
}
}
Bitwise Operators
Bitwise operators are used to performing the manipulation of individual bits of a number. They can be used with any
integral type (char, short, int, etc.). They are used when performing update and query operations of the Binary
indexed trees.

1. Bitwise OR (|)
This operator is a binary operator, denoted by ‘|’. It returns bit
by bit OR of input values, i.e., if either of the bits is 1, it gives 1,
else it shows 0.

Example:

a = 5 = 0101 (In Binary)


b = 7 = 0111 (In Binary)

Bitwise OR Operation of 5 and 7


0101
| 0111
________
0111 = 7 (In decimal)
2. Bitwise AND (&)
This operator is a binary operator, denoted by ‘&.’ It returns bit
by bit AND of input values, i.e., if both bits are 1, it gives 1, else
it shows 0.

Example:

a = 5 = 0101 (In Binary)


b = 7 = 0111 (In Binary)

Bitwise AND Operation of 5 and 7


0101
& 0111
________
0101 = 5 (In decimal)
3. Bitwise XOR (^)
This operator is a binary operator, denoted by ‘^.’ It returns bit
by bit XOR of input values, i.e., if corresponding bits are
different, it gives 1, else it shows 0.

Example:

a = 5 = 0101 (In Binary)


b = 7 = 0111 (In Binary)

Bitwise XOR Operation of 5 and 7


0101
^ 0111
________
0010 = 2 (In decimal)
4. Bitwise Complement (~)

This operator is a unary operator, denoted by ‘~.’ It returns the one’s complement
representation of the input value, i.e., with all bits inverted, which means it makes every 0 to
1, and every 1 to 0.

Example:

a = 5 = 0101 (In Binary)

Bitwise Complement Operation of 5

~ 0101
________
1010 = 10 (In decimal)

Note: Compiler will give 2’s complement of that number, i.e., 2’s complement of 10 will be -6.
public class operators {
public static void main(String[] args)
{

int a = 5;
int b = 7;
System.out.println("a&b = " + (a & b));
System.out.println("a|b = " + (a | b));
System.out.println("a^b = " + (a ^ b));
System.out.println("~a = " + ~a);

a &= b;
System.out.println("a= " + a);
}
}
Java Control Statements
In java, the default execution flow of a program is a sequential order. But the sequential order of execution
flow may not be suitable for all situations. Sometimes, we may want to jump from line to another line, we may
want to skip a part of the program, or sometimes we may want to execute a part of the program again and
again. To solve this problem, java provides control statements.
Java Selection Statements
In java, the selection statements are also known as decision making statements or branching statements or
conditional control statements. The selection statements are used to select a part of the program to be
executed based on a condition. Java provides the following selection statements.
•if statement
•if-else statement
•nested if statement
•if-else if statement
•switch statement
if statement in java
In java, we use the if statement to test a condition and decide the execution of a block of statements based on
that condition result. The if statement checks, the given condition then decides the execution of a block of
statements. If the condition is True, then the block of statements is executed and if it is False, then the block of
statements is ignored. The syntax and execution flow of if the statement is as follows.
import java.util.Scanner;

public class IfStatementTest


{
public static void main(String[] args)
{
Scanner read = new Scanner(System.in);
System.out.print("Enter any number: ");
int num = read.nextInt();
if((num % 5) == 0) {
System.out.println("We are inside the if-block!");
System.out.println("Given number is divisible by 5!!");
}

System.out.println("We are outside the if-block!!!");

}
if-else statement in java
In java, we use the if-else statement to test a condition and pick the execution of a block of statements out of two blocks
based on that condition result. The if-else statement checks the given condition then decides which block of statements to be
executed based on the condition result. If the condition is True, then the true block of statements is executed and if it is False,
then the false block of statements is executed. The syntax and execution flow of if-else statement is as follows.
import java.util.Scanner;
public class IfElseStatementTest {

public static void main(String[] args) {

Scanner read = new Scanner(System.in);


System.out.print("Enter any number: ");
int num = read.nextInt();
if((num % 2) == 0)
{
System.out.println("We are inside the true-block!");
System.out.println("Given number is EVEN number!!");
}
else
{
System.out.println("We are inside the false-block!");
System.out.println("Given number is ODD number!!");
}

System.out.println("We are outside the if-block!!!");

}
Nested if statement in java
Writing an if statement inside another if-statement is called nested if statement. The general syntax of the nested
if-statement is as follows.
import java.util.Scanner;
public class NestedIfStatementTest {
public static void main(String[] args) {

Scanner read = new Scanner(System.in);


System.out.print("Enter any number: ");
int num = read.nextInt();

if (num < 100) {


System.out.println("\nGiven number is below 100");
if (num % 2 == 0)
System.out.println("And it is EVEN");
else
System.out.println("And it is ODD");
}
else
System.out.println("Given number is above 100");

System.out.println("\nWe are outside the if-block!!!");

}
}
Java if-else-if ladder Statement
The if-else-if ladder statement executes one condition from multiple statements.

Syntax:
if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}
public class IfElseIfExample {
//Java Program to demonstrate the use public static void main(String[] args) {
of If else-if ladder. int marks=65;
if(marks<50){
//It is a program of grading system for System.out.println("fail");
fail, D grade, C grade, B grade, A grade }
and A+. else if(marks>=50 && marks<60){
System.out.println("D grade");
}
else if(marks>=60 && marks<70){
System.out.println("C grade");
}
else if(marks>=70 && marks<80){
System.out.println("B grade");
}
else if(marks>=80 && marks<90){
System.out.println("A grade");
}else if(marks>=90 && marks<100){
System.out.println("A+ grade");
}else{
System.out.println("Invalid!");
}
}
}
import java.util.Scanner;
public class IfElseIfStatementTest {
public static void main(String[] args) {
int num1, num2, num3;
Scanner read = new Scanner(System.in);
System.out.print("Enter any three numbers: ");
num1 = read.nextInt();
num2 = read.nextInt();
num3 = read.nextInt();

if( num1>=num2 && num1>=num3)


System.out.println("\nThe largest number is " + num1) ;

else if (num2>=num1 && num2>=num3)


System.out.println("\nThe largest number is " + num2) ;

else
System.out.println("\nThe largest number is " + num3) ;

System.out.println("\nWe are outside the if-block!!!");

}
}
switch statement in java
Using the switch statement, one can select only one option from more
number of options very easily. In the switch statement, we provide a
value that is to be compared with a value associated with each option.
Whenever the given value matches the value associated with an option,
the execution starts from that option. In the switch statement, every
option is defined as a case.
The switch statement has the following syntax and execution flow
diagram.
Check whether an alphabet is vowel or consonant using if..else statement
import java.util.Scanner;
public class Vowelif {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
System.out.print("Enter any Alphabet: ");
char ch = read.next().charAt(0);

if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' )


System.out.println(ch + " is vowel");
else
System.out.println(ch + " is consonant");

}
}
import java.util.Scanner;
public class Vowel{
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
System.out.print("Enter any Alphabet: ");
char ch = read.next().charAt(0);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':

System.out.println(ch + " is vowel");


break;
default:
System.out.println(ch + " is consonant");
}
}
}
Java Iterative Statements(looping)
The java programming language provides a set of iterative statements that are used to execute
a statement or a block of statements repeatedly as long as the given condition is true. The
iterative statements are also known as looping statements or repetitive statements. Java
provides the following iterative statements.

while statement
do-while statement
for statement
for-each statement
for statement in java
In Java, for loop is similar to C and C++. It enables us to initialize the loop variable, check the condition, and
increment/decrement in a single line of code. We use the for loop only when we exactly know the number
of times, we want to execute the block of code.

for(initialization, condition, increment/decrement) {


//block of statements
}
public class Calculation {
public static void main(String[] args) {
int sum = 0;
for(int j = 1; j<=10; j++) {
sum = sum + j;
}
System.out.println("The sum of first 10 natural
numbers is " + sum);
}
}
for-each statement in java
The Java for-each statement was introduced since Java 5.0 version. It provides an approach to traverse through
an array or collection in Java. The for-each statement also known as enhanced for statement. The for-each
statement executes the block of statements for each element of the given array or collection.
The while statement is used to execute a single statement or block of statements repeatedly
as long as the given condition is TRUE. The while statement is also known as Entry control looping
statement. The syntax and execution flow of while statement is as follows.
public class WhileTest {

public static void main(String[] args) {

int num = 1;

while(num <= 10) {


System.out.println(num);
num++;
}

System.out.println("Statement after while!");

}
}
Java do-while loop
The do-while loop checks the condition at the end of the loop after executing the loop
statements. When the number of iteration is not known and we have to execute the loop at
least once, we can use do-while loop.
It is also known as the exit-controlled loop since the condition is not checked in advance. The
syntax of the do-while loop is given below.

do
{
//statements
} while (condition);

The flow chart of the do-while loop is given in the following image.
public class Calculation {
public static void main(String[] args) {
int i = 0;
System.out.println("Printing the list of first 10 even numbers \n");
do {
System.out.println(i);
i = i + 2;
}while(i<=10);
}
}
Jump Statements
Jump statements are used to transfer the control of the program to the specific statements. In
other words, jump statements transfer the execution control to the other part of the program.
There are two types of jump statements in Java, i.e., break and continue.
Java break statement
As the name suggests, the break statement is used to break the current flow of the program
and transfer the control to the next statement outside a loop or switch statement. However, it
breaks only the inner loop in the case of the nested loop.
The break statement cannot be used independently in the Java program, i.e., it can only be
written inside the loop or switch statement.
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if (i == 4) {
break;
}
System.out.println(i);
}
}
}
Java continue statement
Unlike break statement, the continue statement doesn't break the loop,
whereas, it skips the specific part of the loop and jumps to the next iteration of
the loop immediately.
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if (i == 4) {
continue;
}
System.out.println(i);
}
}
}
Return Statement
Return statements are the jump statements used inside methods (or functions) only. Any code in the method which is written
after the return statement might be treated as unreachable by the compiler.

Then return statement terminates the execution of the current method and passes the control to the calling method.

It can exist in 2 forms:

Return with a Value:


Here, the return statement returns a value to the calling method. The value can be a primitive data type or reference type.

Syntax:

return value;

Return without a Value:


It simply transfers the control back to the calling method without any value.

Syntax:

return;
Example 1: Void Method In a method that doesn't return a value, you can
simply use return; to exit early.

public class Example {


public static void main(String[] args) {
greetUser();
}

public static void greetUser() {


System.out.println("Hello!");
return; // Optional, as it's the end of the method
}
}
Example:

class Break_statement {
public static void main(String[] args) {
int age = 12;
System.out.println("Using Return");
if (age<18)
return; //terminates the method
System.out.println("Will not get executed!");
}
}
Example 2: Returning a Value
In a method that returns a value, you specify the type of value you want to return.

public class Example {


public static void main(String[] args) {
int result = add(5, 10);
System.out.println("Result: " + result);
}

public static int add(int a, int b) {


return a + b; // Returns the sum of a and b
}
}
Program list
1. Program to count vowels, consonants, digits, and spaces
in any sentence
2. Factorial
3. Fibonacci series
4. Sum of digits
5. Prime numbers
6. Reverse a number
7. Tableprint

You might also like