SlideShare una empresa de Scribd logo
1 de 24
Computational Problem
Solving
Table of Contents
 Java Introduction
 Features of Java
 Applications of Java
 Data types
 Conditional Control Structures
 Loops in Java
 Arrays in Java
Introduction
 Java is a general-purpose, high-level programming language.It is
owned by Oracle, and more than 3 billion devices run Java.
 Java is a programming language that James Gosling developed at
Sun Microsystems_Inc in the year 1995.
 Java Virtual Machine interprets the bytecode and converts it to
platform specific machine code. Hence, Java is also called a
platform-independent programming language.
 Java is a class-based object-oriented programming language that
implements the principle of write once code anywhere.
JDK- Java Development kit
Java development kit that includes everything including compiler, Java
Runtime Environment (JRE), java debuggers, java docs, etc. For the
program to execute in java, we need to install JDK on our computer in
order to create, compile and run the java program.
JRE- Java Runtime Environment
The Java Runtime Environment is a software layer that runs on top of a
computer’s operating system software and provides the class libraries and
other resources that a specific Java program needs to run.
JVM- Java Virtual Machine
JVM is an abstract machine. It is a specification that provides runtime
environment in which java bytecode can be executed.
JAVA
Features of Java
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10.Multithreaded
11.Distributed
12.Dynamic
Applications of Java
o Mobile App Development
o Desktop GUI Applications
o Web-based Applications
o Gaming Applications
o Big Data Technologies
o Distributed Applications
o Cloud-based Applications
o IoT Applications
o Enterprise Applications
o Scientific Applications
Data Types
There are two types of data types in Java:
Primitive data types : The primitive data types include:
o boolean data type
o byte data type
o char data type
o short data type
o int data type
o long data type
o float data type
o double data type
Non-primitive data types : The non-primitive data types include :
o Classes
o Interfaces
o Arrays.
Example
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99f; // Floating point number
char myLetter = 'D’; // Character
boolean myBool = true; // Boolean
double d2 = 1.234e2 // Double
String myText = "Hello"; // String
int arr[] = new int[100]; // Array
If-else Statement
The if Statement:
If(condition) {
//block of code to be executed if the condition is true
}
Example :
int x = 20;
int y = 18;
if (x > y)
{
System.out.println("x is greater than y");
}
The else Statement:
If(condition) {
//block of code to be executed if the condition is true
}
else {
// block of code to be executed if the condition is false
}
Example :
int x = 20;
if (x > 18){
System.out.println("x is greater than 18");
}
else {
System.out.println("x is less than 18");
}
The else if Statement:
If(condition 1) {
//block of code to be executed if the condition 1 is true
} else if (condition 2) {
// block of code to be executed if the condition 1 is false and condition 2 is true
} else {
// block of code to be executed if the condition 1 is false and condition 2 is false
}
Example : int x = 0;
if (x > 0){
System.out.println("x is greater than 0");
} else if (x < 0) {
System.out.println("x is less than 0");
} else {
System.out.println("x is 0");
}
Loops in Java
for Loop:
for(initializing statement;testing condition;increment/decrement)
{
//code to be iterated
}
Example :
for (i = 0; i <= 10; i++)
{
System.out.println("Value of i = " + i);
}
while Loop:
while(boolean condition)
{
//statements;
}
Example :
while (i < 5) {
System.out.println("The value of i is = " + i);
i++;
}
do while Loop:
do {
statement(s);
} while(test-expression) ;
Example :
char ch = 'A' ;
do
{
System.out.println( ch + " " );
ch++;
} while(ch <= 'Z');
Problem:
Given the number of terms of series N. Write a Java program to
print the Fibonacci series of N.
Code: Output:
Arrays in Java
• In Java, all arrays are dynamically allocated.
• Arrays are stored in contagious memory.
• Since arrays are objects in Java, we can find their length using the
object property length.
• A Java array variable can also be declared like other variables with
[] after the data type.
• Java array can also be used as a static field, a local variable, or a
method parameter.
• The size of an array must be specified by int or short value and not
long.
Instantiating array:
var-name = new type [size];
int intArray[]; //declaring array
intArray = new int[20]; // allocating memory to array
int[] intArray = new int[20]; // combining both statements in one
Array Literal:
int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
// Declaring array literal
Problem:
Given N numbers,write a java program to find the sum.
Constraints :
1 <= N <= 106
Input Format :
First line contains N numbers separated by comma
Output Format :
Sum
Code:
Output:
Strings:
Syntax of Strings(Creation):
char[]ch={‘h’,’e’,’l’,’l’,’o’};
String s=new String(ch);
(or)
String s="hello";
String method:
Length() –returns the length of the string
concat() – used to concat two or more strings
toCharArray()– converts string to a character array
charAt(int i) – returns character at index i in given string
compareTo() – compares two strings based on dictionary order
THANK YOU

Más contenido relacionado

Similar a Computational Problem Solving 016 (1).pptx

Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introductionchnrketan
 
Java Intro
Java IntroJava Intro
Java Introbackdoor
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)Nuzhat Memon
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptxRobertCarreonBula
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slidesunny khan
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptxssuserb1a18d
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenGraham Royce
 
Java_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptJava_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptGovind Samleti
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My HeartBui Kiet
 

Similar a Computational Problem Solving 016 (1).pptx (20)

Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 
Java Intro
Java IntroJava Intro
Java Intro
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
 
Class 8 - Java.pptx
Class 8 - Java.pptxClass 8 - Java.pptx
Class 8 - Java.pptx
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptx
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
 
OOP-java-variables.pptx
OOP-java-variables.pptxOOP-java-variables.pptx
OOP-java-variables.pptx
 
Java Basics 1.pptx
Java Basics 1.pptxJava Basics 1.pptx
Java Basics 1.pptx
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
Java tut1
Java tut1Java tut1
Java tut1
 
Javatut1
Javatut1 Javatut1
Javatut1
 
JAVA LESSON-02.pptx
JAVA LESSON-02.pptxJAVA LESSON-02.pptx
JAVA LESSON-02.pptx
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptJava_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.ppt
 
JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 

Último

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Último (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Computational Problem Solving 016 (1).pptx

  • 2. Table of Contents  Java Introduction  Features of Java  Applications of Java  Data types  Conditional Control Structures  Loops in Java  Arrays in Java
  • 3. Introduction  Java is a general-purpose, high-level programming language.It is owned by Oracle, and more than 3 billion devices run Java.  Java is a programming language that James Gosling developed at Sun Microsystems_Inc in the year 1995.  Java Virtual Machine interprets the bytecode and converts it to platform specific machine code. Hence, Java is also called a platform-independent programming language.  Java is a class-based object-oriented programming language that implements the principle of write once code anywhere.
  • 4. JDK- Java Development kit Java development kit that includes everything including compiler, Java Runtime Environment (JRE), java debuggers, java docs, etc. For the program to execute in java, we need to install JDK on our computer in order to create, compile and run the java program. JRE- Java Runtime Environment The Java Runtime Environment is a software layer that runs on top of a computer’s operating system software and provides the class libraries and other resources that a specific Java program needs to run. JVM- Java Virtual Machine JVM is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JAVA
  • 5.
  • 6. Features of Java 1. Simple 2. Object-Oriented 3. Portable 4. Platform independent 5. Secured 6. Robust 7. Architecture neutral 8. Interpreted 9. High Performance 10.Multithreaded 11.Distributed 12.Dynamic
  • 7. Applications of Java o Mobile App Development o Desktop GUI Applications o Web-based Applications o Gaming Applications o Big Data Technologies o Distributed Applications o Cloud-based Applications o IoT Applications o Enterprise Applications o Scientific Applications
  • 8. Data Types There are two types of data types in Java: Primitive data types : The primitive data types include: o boolean data type o byte data type o char data type o short data type o int data type o long data type o float data type o double data type Non-primitive data types : The non-primitive data types include : o Classes o Interfaces o Arrays.
  • 9.
  • 10. Example int myNum = 5; // Integer (whole number) float myFloatNum = 5.99f; // Floating point number char myLetter = 'D’; // Character boolean myBool = true; // Boolean double d2 = 1.234e2 // Double String myText = "Hello"; // String int arr[] = new int[100]; // Array
  • 11. If-else Statement The if Statement: If(condition) { //block of code to be executed if the condition is true } Example : int x = 20; int y = 18; if (x > y) { System.out.println("x is greater than y"); }
  • 12. The else Statement: If(condition) { //block of code to be executed if the condition is true } else { // block of code to be executed if the condition is false } Example : int x = 20; if (x > 18){ System.out.println("x is greater than 18"); } else { System.out.println("x is less than 18"); }
  • 13. The else if Statement: If(condition 1) { //block of code to be executed if the condition 1 is true } else if (condition 2) { // block of code to be executed if the condition 1 is false and condition 2 is true } else { // block of code to be executed if the condition 1 is false and condition 2 is false } Example : int x = 0; if (x > 0){ System.out.println("x is greater than 0"); } else if (x < 0) { System.out.println("x is less than 0"); } else { System.out.println("x is 0"); }
  • 14. Loops in Java for Loop: for(initializing statement;testing condition;increment/decrement) { //code to be iterated } Example : for (i = 0; i <= 10; i++) { System.out.println("Value of i = " + i); }
  • 15. while Loop: while(boolean condition) { //statements; } Example : while (i < 5) { System.out.println("The value of i is = " + i); i++; }
  • 16. do while Loop: do { statement(s); } while(test-expression) ; Example : char ch = 'A' ; do { System.out.println( ch + " " ); ch++; } while(ch <= 'Z');
  • 17. Problem: Given the number of terms of series N. Write a Java program to print the Fibonacci series of N. Code: Output:
  • 18. Arrays in Java • In Java, all arrays are dynamically allocated. • Arrays are stored in contagious memory. • Since arrays are objects in Java, we can find their length using the object property length. • A Java array variable can also be declared like other variables with [] after the data type. • Java array can also be used as a static field, a local variable, or a method parameter. • The size of an array must be specified by int or short value and not long.
  • 19. Instantiating array: var-name = new type [size]; int intArray[]; //declaring array intArray = new int[20]; // allocating memory to array int[] intArray = new int[20]; // combining both statements in one Array Literal: int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 }; // Declaring array literal
  • 20. Problem: Given N numbers,write a java program to find the sum. Constraints : 1 <= N <= 106 Input Format : First line contains N numbers separated by comma Output Format : Sum
  • 22. Strings: Syntax of Strings(Creation): char[]ch={‘h’,’e’,’l’,’l’,’o’}; String s=new String(ch); (or) String s="hello"; String method: Length() –returns the length of the string concat() – used to concat two or more strings toCharArray()– converts string to a character array charAt(int i) – returns character at index i in given string compareTo() – compares two strings based on dictionary order
  • 23.