SlideShare a Scribd company logo
CS324e - Elements of Graphics
and Visualization
A Little Java
A Little Python
From Python to Java
• Most students have taken CS303e and CS313e
which are taught using Python
• CS324E uses Java
• First couple of lectures and first two
assignments an intro and review of Java
• First - look at common techniques in Python
and Java equivalent
• Second - implement an interesting Java
program
Learning Another Language
• "The first programming language to learn is
the second hardest programming language to
learn.
• The hardest programming language to learn is
the second programming language."
Java
• A general purpose programming language
– so is Python
• More geared towards object oriented
programming
– encapsulation, inheritance, polymorphism
• strongly typed
• braces used to distinguish blocks of code
• all code is part of some class (programmer
defined data type)
Identifiers
• Identifiers composed of letters, digits, _, and $
– must start with letter or _
– by convention variable and method (function) names
start with lower case and use camel case
typicalMethodName
– by convention class names start with a capital letter
and use camel case
ArrayList
– constants use all upper case with _ between words
DAYS_PER_WEEK
Basic Program
public class Hello {
/**
* Where the program starts
*/
public static void main(String[] args) {
System.out.println("Hello World!!");
System.out.println("This is a Java program.");
}
}
• {} for code blocks
• main is called when program run
• ; at the end of statements
• System.out.println is standard output
– analogous to print statement in Python
• comments, /* stuff */ or // stuff
Variables
Python
i = 10
j = 20
k = i * j + i / j
x = 1.7526
name = "Olivia"
list = [1, 2, 3, 4]
blank = [0] * 10
Java
int i = 10;
int j = 20;
int k = i * j + i / j;
double x = 1.7526;
String name = "Olivia";
int[] list = [1, 2, 3, 4];
int[] blank = new int[10];
Variables
• Data Type of variable must be declared when
variable declared
• Type can not be changed
– sort of
• Can not assign an inappropriate (different
data type) value to variable
• Typical: int, double, boolean, String, ArrayList
• Many more we will learn and use
Arrays vs. Lists
• Java has built in arrays, not lists
• Size is fixed and cannot be changed
• indices from 0 to length - 1
• no negative indices or wrap around
• The Java ArrayList and LinkedList classes are
more like the Python list data type
– classes, programmer defined data types
– call methods on variables of type ArrayList
Example: get sum of squares
Example: get sum of squares
Example: Count number of chars
Example: Count number of chars
Example: Search list for values
Example: Search list for values

More Related Content

Similar to 1_5_Python_to_Java.pptx

Python ppt
Python pptPython ppt
Python ppt
Mohita Pandey
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
Jayfee Ramos
 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptx
Francis Densil Raj
 
JavaBasicsCore1.ppt
JavaBasicsCore1.pptJavaBasicsCore1.ppt
JavaBasicsCore1.ppt
buvanabala
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ayshwarya Baburam
 
Java (1).ppt seminar topics engineering
Java (1).ppt  seminar topics engineeringJava (1).ppt  seminar topics engineering
Java (1).ppt seminar topics engineering
4MU21CS023
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
FerdieBalang
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptx
SmitNikumbh
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
TamalSengupta8
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Unit 1
Unit 1Unit 1
Java
JavaJava
Dictionary.pptx
Dictionary.pptxDictionary.pptx
Dictionary.pptx
RishuVerma34
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf
2b75fd3051
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
deivanayagamramachan
 
bhaskars.pptx
bhaskars.pptxbhaskars.pptx
bhaskars.pptx
NaveenShankar34
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
Unmesh Baile
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
vibrantuser
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 

Similar to 1_5_Python_to_Java.pptx (20)

Python ppt
Python pptPython ppt
Python ppt
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Python Programming 1.pptx
Python Programming 1.pptxPython Programming 1.pptx
Python Programming 1.pptx
 
JavaBasicsCore1.ppt
JavaBasicsCore1.pptJavaBasicsCore1.ppt
JavaBasicsCore1.ppt
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Java (1).ppt seminar topics engineering
Java (1).ppt  seminar topics engineeringJava (1).ppt  seminar topics engineering
Java (1).ppt seminar topics engineering
 
demo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.pptdemo1 java of demo 1 java with demo 1 java.ppt
demo1 java of demo 1 java with demo 1 java.ppt
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptx
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Unit 1
Unit 1Unit 1
Unit 1
 
Java
JavaJava
Java
 
Dictionary.pptx
Dictionary.pptxDictionary.pptx
Dictionary.pptx
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
 
bhaskars.pptx
bhaskars.pptxbhaskars.pptx
bhaskars.pptx
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 

More from ShivamChaturvedi67

ddc cinverter control design process.ppt
ddc cinverter control design process.pptddc cinverter control design process.ppt
ddc cinverter control design process.ppt
ShivamChaturvedi67
 
ffCCMPFCInductorDesignwithPowderCore.ppt
ffCCMPFCInductorDesignwithPowderCore.pptffCCMPFCInductorDesignwithPowderCore.ppt
ffCCMPFCInductorDesignwithPowderCore.ppt
ShivamChaturvedi67
 
transformer-and-dc-motor control designs
transformer-and-dc-motor control designstransformer-and-dc-motor control designs
transformer-and-dc-motor control designs
ShivamChaturvedi67
 
magnetism_qr.pptx
magnetism_qr.pptxmagnetism_qr.pptx
magnetism_qr.pptx
ShivamChaturvedi67
 
Update7622.pptx
Update7622.pptxUpdate7622.pptx
Update7622.pptx
ShivamChaturvedi67
 
_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt
_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt
_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt
ShivamChaturvedi67
 
02_Design.pptx
02_Design.pptx02_Design.pptx
02_Design.pptx
ShivamChaturvedi67
 
Education_selecting key discovery tools for education research_v1_2021.pptx
Education_selecting key discovery tools for education research_v1_2021.pptxEducation_selecting key discovery tools for education research_v1_2021.pptx
Education_selecting key discovery tools for education research_v1_2021.pptx
ShivamChaturvedi67
 
Ch05.pdf
Ch05.pdfCh05.pdf
Ch05-converted.pptx
Ch05-converted.pptxCh05-converted.pptx
Ch05-converted.pptx
ShivamChaturvedi67
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
ShivamChaturvedi67
 
android.ppt
android.pptandroid.ppt
android.ppt
ShivamChaturvedi67
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
ShivamChaturvedi67
 
Lecture-3.ppt
Lecture-3.pptLecture-3.ppt
Lecture-3.ppt
ShivamChaturvedi67
 
Lecture-2.ppt
Lecture-2.pptLecture-2.ppt
Lecture-2.ppt
ShivamChaturvedi67
 
Lecture-1.ppt
Lecture-1.pptLecture-1.ppt
Lecture-1.ppt
ShivamChaturvedi67
 

More from ShivamChaturvedi67 (16)

ddc cinverter control design process.ppt
ddc cinverter control design process.pptddc cinverter control design process.ppt
ddc cinverter control design process.ppt
 
ffCCMPFCInductorDesignwithPowderCore.ppt
ffCCMPFCInductorDesignwithPowderCore.pptffCCMPFCInductorDesignwithPowderCore.ppt
ffCCMPFCInductorDesignwithPowderCore.ppt
 
transformer-and-dc-motor control designs
transformer-and-dc-motor control designstransformer-and-dc-motor control designs
transformer-and-dc-motor control designs
 
magnetism_qr.pptx
magnetism_qr.pptxmagnetism_qr.pptx
magnetism_qr.pptx
 
Update7622.pptx
Update7622.pptxUpdate7622.pptx
Update7622.pptx
 
_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt
_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt
_8_EE462L_Fall2011_DC_DC_BuckBoost_PPT.ppt
 
02_Design.pptx
02_Design.pptx02_Design.pptx
02_Design.pptx
 
Education_selecting key discovery tools for education research_v1_2021.pptx
Education_selecting key discovery tools for education research_v1_2021.pptxEducation_selecting key discovery tools for education research_v1_2021.pptx
Education_selecting key discovery tools for education research_v1_2021.pptx
 
Ch05.pdf
Ch05.pdfCh05.pdf
Ch05.pdf
 
Ch05-converted.pptx
Ch05-converted.pptxCh05-converted.pptx
Ch05-converted.pptx
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
android.ppt
android.pptandroid.ppt
android.ppt
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
Lecture-3.ppt
Lecture-3.pptLecture-3.ppt
Lecture-3.ppt
 
Lecture-2.ppt
Lecture-2.pptLecture-2.ppt
Lecture-2.ppt
 
Lecture-1.ppt
Lecture-1.pptLecture-1.ppt
Lecture-1.ppt
 

Recently uploaded

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
zubairahmad848137
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 

Recently uploaded (20)

Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Casting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdfCasting-Defect-inSlab continuous casting.pdf
Casting-Defect-inSlab continuous casting.pdf
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 

1_5_Python_to_Java.pptx

  • 1. CS324e - Elements of Graphics and Visualization A Little Java A Little Python
  • 2. From Python to Java • Most students have taken CS303e and CS313e which are taught using Python • CS324E uses Java • First couple of lectures and first two assignments an intro and review of Java • First - look at common techniques in Python and Java equivalent • Second - implement an interesting Java program
  • 3. Learning Another Language • "The first programming language to learn is the second hardest programming language to learn. • The hardest programming language to learn is the second programming language."
  • 4. Java • A general purpose programming language – so is Python • More geared towards object oriented programming – encapsulation, inheritance, polymorphism • strongly typed • braces used to distinguish blocks of code • all code is part of some class (programmer defined data type)
  • 5. Identifiers • Identifiers composed of letters, digits, _, and $ – must start with letter or _ – by convention variable and method (function) names start with lower case and use camel case typicalMethodName – by convention class names start with a capital letter and use camel case ArrayList – constants use all upper case with _ between words DAYS_PER_WEEK
  • 6. Basic Program public class Hello { /** * Where the program starts */ public static void main(String[] args) { System.out.println("Hello World!!"); System.out.println("This is a Java program."); } } • {} for code blocks • main is called when program run • ; at the end of statements • System.out.println is standard output – analogous to print statement in Python • comments, /* stuff */ or // stuff
  • 7. Variables Python i = 10 j = 20 k = i * j + i / j x = 1.7526 name = "Olivia" list = [1, 2, 3, 4] blank = [0] * 10 Java int i = 10; int j = 20; int k = i * j + i / j; double x = 1.7526; String name = "Olivia"; int[] list = [1, 2, 3, 4]; int[] blank = new int[10];
  • 8. Variables • Data Type of variable must be declared when variable declared • Type can not be changed – sort of • Can not assign an inappropriate (different data type) value to variable • Typical: int, double, boolean, String, ArrayList • Many more we will learn and use
  • 9. Arrays vs. Lists • Java has built in arrays, not lists • Size is fixed and cannot be changed • indices from 0 to length - 1 • no negative indices or wrap around • The Java ArrayList and LinkedList classes are more like the Python list data type – classes, programmer defined data types – call methods on variables of type ArrayList
  • 10. Example: get sum of squares
  • 11. Example: get sum of squares
  • 14. Example: Search list for values
  • 15. Example: Search list for values