SlideShare a Scribd company logo
1 of 39
Download to read offline
19Z305OBJECT
ORIENTED
PROGRAMMING
Unit 2
Overview
PART
-
1
• Characteristics
of Java
• Data types,
Variables,
Operators
• Control
Statements,
Arrays
PART
-
2
• Classes
• Methods,
Constructors
• Inheritance
• Abstract class
12/1/2020 Vani Kandhasamy,PSG Tech 2
Characteristics
of Java
 Simple
 Secure
 Portable
 Object-oriented
 Robust
 Multithreaded
 Architecture-neutral
 Interpreted & High performance
 Distributed
 Dynamic
12/1/2020 Vani Kandhasamy,PSG Tech 3
12/1/2020 Vani Kandhasamy,PSG Tech 4
Datatypes,Variables,
Operators
Part 1 – Chapter 3 & 4
12/1/2020 Vani Kandhasamy,PSG Tech 5
DataTypes
 Kinds of values that can be stored and manipulated.
 Java - StronglyTyped Language
 Automatic Widening casting
Boolean: boolean (true or false).
Integers: byte, short, int, long (0, 1, -47)
Floating point numbers: float, double (3.14, 1.0, -2.1)
Characters: char (‘X’, 65)
String: String (“hello”, “example”).
12/1/2020 Vani Kandhasamy,PSG Tech 6
12/1/2020 Vani Kandhasamy,PSG Tech 7
public class Example1 {
public static void main(String[] args) {
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to double
System.out.println(myInt); // Outputs 9
System.out.println(myDouble); // Outputs 9.0
}
}
Variables
 Named location that stores a value of one particular type.
 Syntax: type variable ; (0r) type variable = value;
 Example: String rollNo;
rollNo = “19Z30X”;
(or)
String rollNo = “19Z30X”;
12/1/2020 Vani Kandhasamy,PSG Tech 8
12/1/2020 Vani Kandhasamy,PSG Tech 9
class Example2 {
public static void printSquare(int x){
System.out.println("printSquare x = " + x);
x = x * x;
System.out.println("printSquare x = " + x);
}
public static void main(String[] arguments){
int x = 5;
System.out.println("main x = " + x);
printSquare(x);
System.out.println("main x = " + x);
}
}
Practice1
Open repl.it
Debug me!!!
12/1/2020 Vani Kandhasamy,PSG Tech 10
Operators
 Symbols that perform simple computations
 Type Promotion
 Syntax: var = var op expression; (or) var op= expression;
Arithmetic operators: (+, -, *, /, …)
Assignment operators: (=, +=, -=,…)
Relational operators: (==, !=, >, <, …)
Logical operators: (&&, ||, !)
Bitwise operators: (&, |, ~, …)
12/1/2020 Vani Kandhasamy,PSG Tech 11
12/1/2020 Vani Kandhasamy,PSG Tech 12
class Example3 {
public static void main(String args[]) {
byte b = 42;
char c = 'a';
short s = 1024;
int i = 50000;
float f = 5.67f;
double d = .1234;
double result = (f * b) + (i / c) - (d * s);
System.out.println((f * b) + " + " + (i / c) + " - " + (d * s));
System.out.println("result = " + result);
}
}
Output:
238.14 + 515 - 126.3616
result = 626.7784146484375
Practice2
Open repl.it
Compute distance light travels
12/1/2020 Vani Kandhasamy,PSG Tech 13
ControlStatements,
Arrays
Part 1 – Chapter 3 & 5
12/1/2020 Vani Kandhasamy,PSG Tech 14
12/1/2020 Vani Kandhasamy,PSG Tech 15
Conditional Statements
if (CONDITION) {
STATEMENTS
}
if (CONDITION) {
STATEMENTS
} else {
STATEMENTS
}
if (CONDITION) {
STATEMENTS
} else if (CONDITION) {
STATEMENTS
} else {
STATEMENTS
}
12/1/2020 Vani Kandhasamy,PSG Tech 16
public class Example5 {
public static void main(String args[]) {
int month = 4; // April
String season;
if(month == 12 || month == 1 || month == 2)
season = "Winter";
else if(month == 3 || month == 4 || month == 5)
season = "Spring";
else if(month == 6 || month == 7 || month == 8)
season = "Summer";
else if(month == 9 || month == 10 || month == 11)
season = "Autumn";
else
season = "Bogus Month";
System.out.println("April is in the " + season + ".");
}
}
Selection
Statement
switch (expression) {
case value1:
// statement sequence
break;
case value2:
// statement sequence
break;
...
case valueN :
// statement sequence
break;
default:
// default statement sequence
}
12/1/2020 Vani Kandhasamy,PSG Tech 17
12/1/2020 Vani Kandhasamy,PSG Tech 18
public class Example6 {
public static void main(String args[]) {
String str = "two";
switch(str) {
case "one":
System.out.println("one");
break;
case "two":
System.out.println("two");
break;
case "three":
System.out.println("three");
break;
default:
System.out.println("no match");
break;
}
}
}
Overview
12/1/2020 Vani Kandhasamy,PSG Tech 19
Practice3
Open repl.it
Identify season using switch
12/1/2020 Vani Kandhasamy,PSG Tech 20
2
min
12/1/2020 Vani Kandhasamy,PSG Tech 21
Stretch
Break
12/1/2020 Vani Kandhasamy,PSG Tech 22
What if you want to do it for 200 Rules?
12/1/2020 Vani Kandhasamy,PSG Tech 23
Iterative Statements
while (CONDITION) {
STATEMENTS
}
do {
STATEMENTS
} while (CONDITION);
for(initialization;CONDITION;update){
STATEMENTS
}
while
12/1/2020 Vani Kandhasamy,PSG Tech 24
for
12/1/2020 Vani Kandhasamy,PSG Tech 25
12/1/2020 Vani Kandhasamy,PSG Tech 26
S
12/1/2020 Vani Kandhasamy,PSG Tech 27
r
12/1/2020 Vani Kandhasamy,PSG Tech 28
public class Example8 {
public static void main(String args[]) {
int a, b;
for(a=1, b=4; a<b; a++, b--) {
System.out.println("a = " + a);
System.out.println("b = " + b);
}
}
}
Practice4
Open repl.it
Find whether a number is Prime or
not
12/1/2020 Vani Kandhasamy,PSG Tech 29
Overview
12/1/2020 Vani Kandhasamy,PSG Tech 30
Arrays
Syntax: type var_name[ ] = new type [size];
type[ ] var_name;
Example:
double values[ ] = new double [10]
The index starts at zero and ends at length-1
12/1/2020 Vani Kandhasamy,PSG Tech 31
12/1/2020 Vani Kandhasamy,PSG Tech 32
Declaration &
Instantiation
Initialization
Declaration, Instantiation &
Initialization
12/1/2020 Vani Kandhasamy,PSG Tech 36
public class Example7 {
public static void main(String args[]) {
int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = 0;
for(int x =0; x<nums.length; x++){
System.out.println("Value is: " + x);
sum += nums[x];
}
System.out.println("Summation: " + sum);
}
}
12/1/2020 Vani Kandhasamy,PSG Tech 37
public class Example7 {
public static void main(String args[]) {
int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int sum = 0;
// use for-each style for to display and sum the values
for(int x : nums) {
System.out.println("Value is: " + x);
sum += x;
}
System.out.println("Summation: " + sum);
}
}
Practice5
Open repl.it
Search an array using for-each style
12/1/2020 Vani Kandhasamy,PSG Tech 38
Multi-
dimensional
Array
12/1/2020 Vani Kandhasamy,PSG Tech 39
int twoD[][] = new int [4][5]
int[][] twoD= new int [4][5]
int []twoD[] = new int [4][5]
12/1/2020 Vani Kandhasamy,PSG Tech 40
public class Example9 {
public static void main(String args[]) {
int twoD[][]= new int[4][5];
int i, j, k = 0;
for(i=0; i<4; i++)
for(j=0; j<5; j++) {
twoD[i][j] = k;
k++;
}
for(i=0; i<4; i++) {
for(j=0; j<5; j++)
System.out.print(twoD[i][j] + " ");
System.out.println();
}
}
}
Practice6
Open repl.it
Sum of principle diagonal elements
of a matrix
12/1/2020 Vani Kandhasamy,PSG Tech 41
References
 "Java:The Complete Reference” by Schildt H - Part 1 - Chapter 3 , 4 & 5
 https://www.w3schools.com/java/
12/1/2020 Vani Kandhasamy,PSG Tech 42

More Related Content

What's hot

Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQIntro C# Book
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and ClassesIntro C# Book
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text ProcessingIntro C# Book
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
15. Streams Files and Directories
15. Streams Files and Directories 15. Streams Files and Directories
15. Streams Files and Directories Intro C# Book
 
Introduction to julia
Introduction to juliaIntroduction to julia
Introduction to julia岳華 杜
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeGanesh Samarthyam
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulationIntro C# Book
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...Intro C# Book
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge O T
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядомAndrey Akinshin
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks QueuesIntro C# Book
 
Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia岳華 杜
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonTendayi Mawushe
 

What's hot (20)

Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQ
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
PDBC
PDBCPDBC
PDBC
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
15. Streams Files and Directories
15. Streams Files and Directories 15. Streams Files and Directories
15. Streams Files and Directories
 
Introduction to julia
Introduction to juliaIntroduction to julia
Introduction to julia
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
09. Methods
09. Methods09. Methods
09. Methods
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
 
Parameters
ParametersParameters
Parameters
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in Python
 

Similar to Java Basics - Part1

Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...FarhanAhmade
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
What We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingWhat We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingKevlin Henney
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer developmentAndrey Karpov
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.pptMahyuddin8
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeMicrosoft Tech Community
 
A miało być tak... bez wycieków
A miało być tak... bez wyciekówA miało być tak... bez wycieków
A miało być tak... bez wyciekówKonrad Kokosa
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdfactocomputer
 
Chapter 1 Basic Concepts
Chapter 1 Basic ConceptsChapter 1 Basic Concepts
Chapter 1 Basic ConceptsHareem Aslam
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMERAndrey Karpov
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operatorsHarleen Sodhi
 

Similar to Java Basics - Part1 (20)

Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
What We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingWhat We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit Testing
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
ch04-conditional-execution.ppt
ch04-conditional-execution.pptch04-conditional-execution.ppt
ch04-conditional-execution.ppt
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
06slide.ppt
06slide.ppt06slide.ppt
06slide.ppt
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
How to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ CodeHow to Adopt Modern C++17 into Your C++ Code
How to Adopt Modern C++17 into Your C++ Code
 
A miało być tak... bez wycieków
A miało być tak... bez wyciekówA miało być tak... bez wycieków
A miało być tak... bez wycieków
 
FileName EX06_1java Programmer import ja.pdf
FileName EX06_1java Programmer  import ja.pdfFileName EX06_1java Programmer  import ja.pdf
FileName EX06_1java Programmer import ja.pdf
 
Chapter 1 Basic Concepts
Chapter 1 Basic ConceptsChapter 1 Basic Concepts
Chapter 1 Basic Concepts
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
report
reportreport
report
 
C#, What Is Next?
C#, What Is Next?C#, What Is Next?
C#, What Is Next?
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 

More from Vani Kandhasamy

Economic network analysis - Part 2
Economic network analysis - Part 2Economic network analysis - Part 2
Economic network analysis - Part 2Vani Kandhasamy
 
Economic network analysis - Part 1
Economic network analysis - Part 1Economic network analysis - Part 1
Economic network analysis - Part 1Vani Kandhasamy
 
Cascading behavior in the networks
Cascading behavior in the networksCascading behavior in the networks
Cascading behavior in the networksVani Kandhasamy
 
Community detection-Part2
Community detection-Part2Community detection-Part2
Community detection-Part2Vani Kandhasamy
 
Community detection-Part1
Community detection-Part1Community detection-Part1
Community detection-Part1Vani Kandhasamy
 
Representing & Measuring networks
Representing & Measuring networksRepresenting & Measuring networks
Representing & Measuring networksVani Kandhasamy
 

More from Vani Kandhasamy (10)

Introduction to OOP
Introduction to OOPIntroduction to OOP
Introduction to OOP
 
Economic network analysis - Part 2
Economic network analysis - Part 2Economic network analysis - Part 2
Economic network analysis - Part 2
 
Economic network analysis - Part 1
Economic network analysis - Part 1Economic network analysis - Part 1
Economic network analysis - Part 1
 
Cascading behavior in the networks
Cascading behavior in the networksCascading behavior in the networks
Cascading behavior in the networks
 
Community detection-Part2
Community detection-Part2Community detection-Part2
Community detection-Part2
 
Community detection-Part1
Community detection-Part1Community detection-Part1
Community detection-Part1
 
Link Analysis
Link AnalysisLink Analysis
Link Analysis
 
Network Models
Network ModelsNetwork Models
Network Models
 
Representing & Measuring networks
Representing & Measuring networksRepresenting & Measuring networks
Representing & Measuring networks
 
Cache optimization
Cache optimizationCache optimization
Cache optimization
 

Recently uploaded

Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxPurva Nikam
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 

Recently uploaded (20)

Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 

Java Basics - Part1

  • 2. Overview PART - 1 • Characteristics of Java • Data types, Variables, Operators • Control Statements, Arrays PART - 2 • Classes • Methods, Constructors • Inheritance • Abstract class 12/1/2020 Vani Kandhasamy,PSG Tech 2
  • 3. Characteristics of Java  Simple  Secure  Portable  Object-oriented  Robust  Multithreaded  Architecture-neutral  Interpreted & High performance  Distributed  Dynamic 12/1/2020 Vani Kandhasamy,PSG Tech 3
  • 5. Datatypes,Variables, Operators Part 1 – Chapter 3 & 4 12/1/2020 Vani Kandhasamy,PSG Tech 5
  • 6. DataTypes  Kinds of values that can be stored and manipulated.  Java - StronglyTyped Language  Automatic Widening casting Boolean: boolean (true or false). Integers: byte, short, int, long (0, 1, -47) Floating point numbers: float, double (3.14, 1.0, -2.1) Characters: char (‘X’, 65) String: String (“hello”, “example”). 12/1/2020 Vani Kandhasamy,PSG Tech 6
  • 7. 12/1/2020 Vani Kandhasamy,PSG Tech 7 public class Example1 { public static void main(String[] args) { int myInt = 9; double myDouble = myInt; // Automatic casting: int to double System.out.println(myInt); // Outputs 9 System.out.println(myDouble); // Outputs 9.0 } }
  • 8. Variables  Named location that stores a value of one particular type.  Syntax: type variable ; (0r) type variable = value;  Example: String rollNo; rollNo = “19Z30X”; (or) String rollNo = “19Z30X”; 12/1/2020 Vani Kandhasamy,PSG Tech 8
  • 9. 12/1/2020 Vani Kandhasamy,PSG Tech 9 class Example2 { public static void printSquare(int x){ System.out.println("printSquare x = " + x); x = x * x; System.out.println("printSquare x = " + x); } public static void main(String[] arguments){ int x = 5; System.out.println("main x = " + x); printSquare(x); System.out.println("main x = " + x); } }
  • 10. Practice1 Open repl.it Debug me!!! 12/1/2020 Vani Kandhasamy,PSG Tech 10
  • 11. Operators  Symbols that perform simple computations  Type Promotion  Syntax: var = var op expression; (or) var op= expression; Arithmetic operators: (+, -, *, /, …) Assignment operators: (=, +=, -=,…) Relational operators: (==, !=, >, <, …) Logical operators: (&&, ||, !) Bitwise operators: (&, |, ~, …) 12/1/2020 Vani Kandhasamy,PSG Tech 11
  • 12. 12/1/2020 Vani Kandhasamy,PSG Tech 12 class Example3 { public static void main(String args[]) { byte b = 42; char c = 'a'; short s = 1024; int i = 50000; float f = 5.67f; double d = .1234; double result = (f * b) + (i / c) - (d * s); System.out.println((f * b) + " + " + (i / c) + " - " + (d * s)); System.out.println("result = " + result); } } Output: 238.14 + 515 - 126.3616 result = 626.7784146484375
  • 13. Practice2 Open repl.it Compute distance light travels 12/1/2020 Vani Kandhasamy,PSG Tech 13
  • 14. ControlStatements, Arrays Part 1 – Chapter 3 & 5 12/1/2020 Vani Kandhasamy,PSG Tech 14
  • 15. 12/1/2020 Vani Kandhasamy,PSG Tech 15 Conditional Statements if (CONDITION) { STATEMENTS } if (CONDITION) { STATEMENTS } else { STATEMENTS } if (CONDITION) { STATEMENTS } else if (CONDITION) { STATEMENTS } else { STATEMENTS }
  • 16. 12/1/2020 Vani Kandhasamy,PSG Tech 16 public class Example5 { public static void main(String args[]) { int month = 4; // April String season; if(month == 12 || month == 1 || month == 2) season = "Winter"; else if(month == 3 || month == 4 || month == 5) season = "Spring"; else if(month == 6 || month == 7 || month == 8) season = "Summer"; else if(month == 9 || month == 10 || month == 11) season = "Autumn"; else season = "Bogus Month"; System.out.println("April is in the " + season + "."); } }
  • 17. Selection Statement switch (expression) { case value1: // statement sequence break; case value2: // statement sequence break; ... case valueN : // statement sequence break; default: // default statement sequence } 12/1/2020 Vani Kandhasamy,PSG Tech 17
  • 18. 12/1/2020 Vani Kandhasamy,PSG Tech 18 public class Example6 { public static void main(String args[]) { String str = "two"; switch(str) { case "one": System.out.println("one"); break; case "two": System.out.println("two"); break; case "three": System.out.println("three"); break; default: System.out.println("no match"); break; } } }
  • 20. Practice3 Open repl.it Identify season using switch 12/1/2020 Vani Kandhasamy,PSG Tech 20
  • 21. 2 min 12/1/2020 Vani Kandhasamy,PSG Tech 21 Stretch Break
  • 22. 12/1/2020 Vani Kandhasamy,PSG Tech 22 What if you want to do it for 200 Rules?
  • 23. 12/1/2020 Vani Kandhasamy,PSG Tech 23 Iterative Statements while (CONDITION) { STATEMENTS } do { STATEMENTS } while (CONDITION); for(initialization;CONDITION;update){ STATEMENTS }
  • 28. 12/1/2020 Vani Kandhasamy,PSG Tech 28 public class Example8 { public static void main(String args[]) { int a, b; for(a=1, b=4; a<b; a++, b--) { System.out.println("a = " + a); System.out.println("b = " + b); } } }
  • 29. Practice4 Open repl.it Find whether a number is Prime or not 12/1/2020 Vani Kandhasamy,PSG Tech 29
  • 31. Arrays Syntax: type var_name[ ] = new type [size]; type[ ] var_name; Example: double values[ ] = new double [10] The index starts at zero and ends at length-1 12/1/2020 Vani Kandhasamy,PSG Tech 31
  • 32. 12/1/2020 Vani Kandhasamy,PSG Tech 32 Declaration & Instantiation Initialization Declaration, Instantiation & Initialization
  • 33. 12/1/2020 Vani Kandhasamy,PSG Tech 36 public class Example7 { public static void main(String args[]) { int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int sum = 0; for(int x =0; x<nums.length; x++){ System.out.println("Value is: " + x); sum += nums[x]; } System.out.println("Summation: " + sum); } }
  • 34. 12/1/2020 Vani Kandhasamy,PSG Tech 37 public class Example7 { public static void main(String args[]) { int nums[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int sum = 0; // use for-each style for to display and sum the values for(int x : nums) { System.out.println("Value is: " + x); sum += x; } System.out.println("Summation: " + sum); } }
  • 35. Practice5 Open repl.it Search an array using for-each style 12/1/2020 Vani Kandhasamy,PSG Tech 38
  • 36. Multi- dimensional Array 12/1/2020 Vani Kandhasamy,PSG Tech 39 int twoD[][] = new int [4][5] int[][] twoD= new int [4][5] int []twoD[] = new int [4][5]
  • 37. 12/1/2020 Vani Kandhasamy,PSG Tech 40 public class Example9 { public static void main(String args[]) { int twoD[][]= new int[4][5]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } }
  • 38. Practice6 Open repl.it Sum of principle diagonal elements of a matrix 12/1/2020 Vani Kandhasamy,PSG Tech 41
  • 39. References  "Java:The Complete Reference” by Schildt H - Part 1 - Chapter 3 , 4 & 5  https://www.w3schools.com/java/ 12/1/2020 Vani Kandhasamy,PSG Tech 42