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

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
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
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Recently uploaded (20)

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
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
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
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
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

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