SlideShare una empresa de Scribd logo
1 de 41
Java: Building Blocks
       Cate Huston
       @kittenthebad
What We’ll Cover
•   Java: an Object Oriented Language

•   The Eclipse IDE

•   Writing your first program

•   Primitive Types

•   Strings

•   Conditions

•   Loops
Java: an Object
Oriented Language
What Does Object
Oriented Mean?
• If Ikea were made of code, it would totally
   be written in an Object Oriented language.
• Object-Oriented means that we break our
   code down into components (objects) with
   properties (fields), that can be used to
   make other objects, or interact with each
   other.
• (See? It’s a little bit like Ikea furniture!)
OK, Give Me an
Example!
•   Imagine a bike. If we wanted to “code” a bike, it
    would be a lot easier if we split it down into its
    component parts.

    •   wheels (x2)

    •   breaks

    •   seat

    •   frame

    •   peddles...
Another?
•   How about a ToDo list?

•   It’s make up of tasks.

•   Each task should have things associated with it, such as:

    •   It’s name

    •   The date it’s due

    •   The date we actually complete it

    •   An estimate of how long it will take

    •   The date we started it
Try It!

• Think of a complex object
• Break it down into it’s component parts
• What information does each component
  need to know about itself?
The Eclipse IDE
Eclipse is a powerful, free and open source Java IDE
(Integrated Development Environment). It has some
    very useful features for learning to program.
Let’s start by making a new project.
    File => New => Java Project
Let’s call it “Hello World”.
It’s a programming tradition.
Now we make a new “class”. Java classes
are where we represent our “objects”.
Let’s call this “HelloWorld”. Notice how
 there are no spaces? That’s important.
Our first class!
It should look like this.
Writing Your First
    Program
Finally! Write Some
Code

• For our first program, we’re going to write
  something that prints out “Hello World” in
  the terminal.
• (Sorry, programmer tradition)
Click on “Run” (the green “play
button), and see what happens.
What Does It All Mean?
•   public class HelloWorld {

    •   Declares our class/object with name “HelloWorld”. Everything inside the “{“ is part of the
        class. Public is to do with it’s visibility (don’t worry about that for now).

•   
       public static void main(String[] args) {

    •   This is our “main” method, what’s called when we click “run”. The String[] args means
        we can pass arguments to it, if we want to. Everything inside the “{“ is part of the main
        method.

•   
       
     System.out.println("Hello World");

    •   This means - print out “Hello World” to the terminal. The “;” is important, it denotes the
        end of the line of code. We’re going to be using a lot of these.

•   
       }                                  }

    •   The first closing bracket denotes the end of the “main” method, the second the end of the
        HelloWorld class.
Primitive Types
Building Blocks
• Primitives are the most basic kinds of “type”
  in Java (a building block!)
• You can also think of them as like atoms in
  chemistry.
• A “type” is where we say what kind of thing
  a variable is.
• Objects are made up of other objects and
  primitives.
For Example...
• Whole numbers, like 42, or 926 are of type
  int (or short, or long).

• Decimal numbers, like 2.34376 or 1.203 are
  float, or double.
• True or False are boolean.
• A character like ‘a’ or ‘c’ is a char. Notice
  the single quotes? Those are important.
Declaring Variables
•   We can declare a variable of a primitive type in Java as
    follows:

    •   int i = 42;

    •   double d = 735.27;

    •   boolean b = true;

    •   char c = ‘h’;

•   So:

    •   type variable_name = value;
See how we can use the “+” sign to
     include it in our output?
Strings
Strings

•   A String is not a primitive, it’s an Object,
    but we can declare it like a primitive.

•   It’s a little more complex to declare
    Objects (but we’ll look at that later)
    •   String s = “hello world”;
    •   String s = “hello world” + “nhow are you?”
Conditions
Comparing Things
•   We compare things in          •   Equals: ==
    Java using conditional
    logic.                        •   Greater Than: >

•   We can put this in an “if     •   Less Than: <
    statement”
                                  •   Greater Than or
    •   if (a == b ) { ... }          Equal To: >=

    •   else if (a < b) { ... }   •   Less Than or Equal
                                      To: <=
    •   else { ... }
Try this for different values of a
              and b
Loops
Repeating Things
• Loops are helpful for sections of code
  that we want to repeat.
• There are three kinds of loop.
 • while
 • do while
 • for
For Loops
• For when we know how many times
  we want to repeat something.
• 10 times
 • for(int i = 0; i < 10; i++)
• For each character in a string
 • for(int i = 0; i < stringname.length(); i++)
Repeat Something 10 Times
For each character in a string. s.charAt(i) gets
   the character in the string at position i.
While and Do-While
Loops
•   When we want to repeat something until a
    condition changes.

•   In a while loop we check that condition at the
    start of the loop

    •   while(a == b) { ... }

•   In a do-while loop we check that condition at
    the end of the loop.

    •   do { ... } while (a == b)
Example While Loop
Example Do-While
Whitespace
Tidy Code
•   Tidy code is much easier to read (and debug!)

    •   Debug - fix when it’s not working.

•   As a rule, indent in one inside each set of {}.

•   In longer sections of code, we can use // to denote a
    comment.

    •   A comment is code that is ignored by the compiler.

•   The Java compiler ignores whitespace, so use line breaks
    wherever you think it will make your code clearer.
Finally...
Finally

• This slide deck covers the very basics of
  Java - the building blocks.
• It’s important to understand these, because
  everything else builds upon them.
• Next, we’re going to look at Processing.
@kittenthebad
http://kittenthebad.wordpress.com/

  catehuston@googlewave.com

Más contenido relacionado

La actualidad más candente

Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency InjectionNir Kaufman
 
Hybrid application development
Hybrid application developmentHybrid application development
Hybrid application developmentKnoldus Inc.
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium Zoe Gilbert
 
Using Mountebank to inject behavior into test stubs
Using Mountebank to inject behavior into test stubsUsing Mountebank to inject behavior into test stubs
Using Mountebank to inject behavior into test stubsAndré Diegues Rodrigues
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageAnıl Sözeri
 
API Testing With Katalon Studio
API Testing With Katalon StudioAPI Testing With Katalon Studio
API Testing With Katalon StudioKnoldus Inc.
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 
Waits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | EdurekaWaits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | EdurekaEdureka!
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introMaurice De Beijer [MVP]
 
Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...
Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...
Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...Moataz Nabil
 
Lesson 4...Bug Life Cycle
Lesson 4...Bug Life CycleLesson 4...Bug Life Cycle
Lesson 4...Bug Life Cyclebhushan Nehete
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular AnimationsGil Fink
 

La actualidad más candente (20)

Test Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and CucumberTest Automation Framework with BDD and Cucumber
Test Automation Framework with BDD and Cucumber
 
Angular Dependency Injection
Angular Dependency InjectionAngular Dependency Injection
Angular Dependency Injection
 
Hybrid application development
Hybrid application developmentHybrid application development
Hybrid application development
 
Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium  Page Object Model and Implementation in Selenium
Page Object Model and Implementation in Selenium
 
Using Mountebank to inject behavior into test stubs
Using Mountebank to inject behavior into test stubsUsing Mountebank to inject behavior into test stubs
Using Mountebank to inject behavior into test stubs
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
API Testing With Katalon Studio
API Testing With Katalon StudioAPI Testing With Katalon Studio
API Testing With Katalon Studio
 
Postman
PostmanPostman
Postman
 
TestCraft
TestCraftTestCraft
TestCraft
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Waits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | EdurekaWaits in Selenium | Selenium Wait Commands | Edureka
Waits in Selenium | Selenium Wait Commands | Edureka
 
Api testing
Api testingApi testing
Api testing
 
Testing Tools
Testing ToolsTesting Tools
Testing Tools
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
 
Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...
Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...
Build your QA Pipeline using Serenity , Selenium WebDriver , Rest Assured and...
 
Angular material
Angular materialAngular material
Angular material
 
API TESTING
API TESTINGAPI TESTING
API TESTING
 
Lesson 4...Bug Life Cycle
Lesson 4...Bug Life CycleLesson 4...Bug Life Cycle
Lesson 4...Bug Life Cycle
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular Animations
 

Similar a Java Building Blocks

Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object OrientationMichael Heron
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_reviewEdureka!
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 
C++ Introduction brown bag
C++ Introduction brown bagC++ Introduction brown bag
C++ Introduction brown bagJacob Green
 
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...Julie Meloni
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramMichael Heron
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like PythonistaChiyoung Song
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java BasicsFayis-QA
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеSergey Platonov
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++Dmitri Nesteruk
 
Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)Thinkful
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 

Similar a Java Building Blocks (20)

2CPP02 - C++ Primer
2CPP02 - C++ Primer2CPP02 - C++ Primer
2CPP02 - C++ Primer
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
 
Javascript
JavascriptJavascript
Javascript
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
C++ Introduction brown bag
C++ Introduction brown bagC++ Introduction brown bag
C++ Introduction brown bag
 
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...Speaking 'Development Language' (Or, how to get your hands dirty with technic...
Speaking 'Development Language' (Or, how to get your hands dirty with technic...
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
CPP02 - The Structure of a Program
CPP02 - The Structure of a ProgramCPP02 - The Structure of a Program
CPP02 - The Structure of a Program
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI веке
 
python.pdf
python.pdfpython.pdf
python.pdf
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 

Más de Cate Huston

15 Tools to Make University Easier
15 Tools to Make University Easier15 Tools to Make University Easier
15 Tools to Make University EasierCate Huston
 
Holiday Science Lecture: Art, Life and Programming
Holiday Science Lecture: Art, Life and ProgrammingHoliday Science Lecture: Art, Life and Programming
Holiday Science Lecture: Art, Life and ProgrammingCate Huston
 
Art, Life and Programming
Art, Life and ProgrammingArt, Life and Programming
Art, Life and ProgrammingCate Huston
 
Thinking Like a Programmer
Thinking Like a ProgrammerThinking Like a Programmer
Thinking Like a ProgrammerCate Huston
 
An Introduction to Processing
An Introduction to ProcessingAn Introduction to Processing
An Introduction to ProcessingCate Huston
 
Art, Life and Programming
Art, Life and ProgrammingArt, Life and Programming
Art, Life and ProgrammingCate Huston
 
Microsoft Vista: A Usability Problem
Microsoft Vista: A Usability ProblemMicrosoft Vista: A Usability Problem
Microsoft Vista: A Usability ProblemCate Huston
 

Más de Cate Huston (10)

15 Tools to Make University Easier
15 Tools to Make University Easier15 Tools to Make University Easier
15 Tools to Make University Easier
 
Holiday Science Lecture: Art, Life and Programming
Holiday Science Lecture: Art, Life and ProgrammingHoliday Science Lecture: Art, Life and Programming
Holiday Science Lecture: Art, Life and Programming
 
Art, Life and Programming
Art, Life and ProgrammingArt, Life and Programming
Art, Life and Programming
 
Thinking Like a Programmer
Thinking Like a ProgrammerThinking Like a Programmer
Thinking Like a Programmer
 
An Introduction to Processing
An Introduction to ProcessingAn Introduction to Processing
An Introduction to Processing
 
Art, Life and Programming
Art, Life and ProgrammingArt, Life and Programming
Art, Life and Programming
 
Web 2.0
Web 2.0Web 2.0
Web 2.0
 
Processing
ProcessingProcessing
Processing
 
iPhone Commerce
iPhone CommerceiPhone Commerce
iPhone Commerce
 
Microsoft Vista: A Usability Problem
Microsoft Vista: A Usability ProblemMicrosoft Vista: A Usability Problem
Microsoft Vista: A Usability Problem
 

Último

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 

Último (20)

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 

Java Building Blocks

  • 1. Java: Building Blocks Cate Huston @kittenthebad
  • 2. What We’ll Cover • Java: an Object Oriented Language • The Eclipse IDE • Writing your first program • Primitive Types • Strings • Conditions • Loops
  • 4. What Does Object Oriented Mean? • If Ikea were made of code, it would totally be written in an Object Oriented language. • Object-Oriented means that we break our code down into components (objects) with properties (fields), that can be used to make other objects, or interact with each other. • (See? It’s a little bit like Ikea furniture!)
  • 5. OK, Give Me an Example! • Imagine a bike. If we wanted to “code” a bike, it would be a lot easier if we split it down into its component parts. • wheels (x2) • breaks • seat • frame • peddles...
  • 6. Another? • How about a ToDo list? • It’s make up of tasks. • Each task should have things associated with it, such as: • It’s name • The date it’s due • The date we actually complete it • An estimate of how long it will take • The date we started it
  • 7. Try It! • Think of a complex object • Break it down into it’s component parts • What information does each component need to know about itself?
  • 9. Eclipse is a powerful, free and open source Java IDE (Integrated Development Environment). It has some very useful features for learning to program.
  • 10. Let’s start by making a new project. File => New => Java Project
  • 11. Let’s call it “Hello World”. It’s a programming tradition.
  • 12. Now we make a new “class”. Java classes are where we represent our “objects”.
  • 13. Let’s call this “HelloWorld”. Notice how there are no spaces? That’s important.
  • 14. Our first class! It should look like this.
  • 16. Finally! Write Some Code • For our first program, we’re going to write something that prints out “Hello World” in the terminal. • (Sorry, programmer tradition)
  • 17. Click on “Run” (the green “play button), and see what happens.
  • 18. What Does It All Mean? • public class HelloWorld { • Declares our class/object with name “HelloWorld”. Everything inside the “{“ is part of the class. Public is to do with it’s visibility (don’t worry about that for now). • public static void main(String[] args) { • This is our “main” method, what’s called when we click “run”. The String[] args means we can pass arguments to it, if we want to. Everything inside the “{“ is part of the main method. • System.out.println("Hello World"); • This means - print out “Hello World” to the terminal. The “;” is important, it denotes the end of the line of code. We’re going to be using a lot of these. • } } • The first closing bracket denotes the end of the “main” method, the second the end of the HelloWorld class.
  • 20. Building Blocks • Primitives are the most basic kinds of “type” in Java (a building block!) • You can also think of them as like atoms in chemistry. • A “type” is where we say what kind of thing a variable is. • Objects are made up of other objects and primitives.
  • 21. For Example... • Whole numbers, like 42, or 926 are of type int (or short, or long). • Decimal numbers, like 2.34376 or 1.203 are float, or double. • True or False are boolean. • A character like ‘a’ or ‘c’ is a char. Notice the single quotes? Those are important.
  • 22. Declaring Variables • We can declare a variable of a primitive type in Java as follows: • int i = 42; • double d = 735.27; • boolean b = true; • char c = ‘h’; • So: • type variable_name = value;
  • 23. See how we can use the “+” sign to include it in our output?
  • 25. Strings • A String is not a primitive, it’s an Object, but we can declare it like a primitive. • It’s a little more complex to declare Objects (but we’ll look at that later) • String s = “hello world”; • String s = “hello world” + “nhow are you?”
  • 27. Comparing Things • We compare things in • Equals: == Java using conditional logic. • Greater Than: > • We can put this in an “if • Less Than: < statement” • Greater Than or • if (a == b ) { ... } Equal To: >= • else if (a < b) { ... } • Less Than or Equal To: <= • else { ... }
  • 28. Try this for different values of a and b
  • 29. Loops
  • 30. Repeating Things • Loops are helpful for sections of code that we want to repeat. • There are three kinds of loop. • while • do while • for
  • 31. For Loops • For when we know how many times we want to repeat something. • 10 times • for(int i = 0; i < 10; i++) • For each character in a string • for(int i = 0; i < stringname.length(); i++)
  • 33. For each character in a string. s.charAt(i) gets the character in the string at position i.
  • 34. While and Do-While Loops • When we want to repeat something until a condition changes. • In a while loop we check that condition at the start of the loop • while(a == b) { ... } • In a do-while loop we check that condition at the end of the loop. • do { ... } while (a == b)
  • 38. Tidy Code • Tidy code is much easier to read (and debug!) • Debug - fix when it’s not working. • As a rule, indent in one inside each set of {}. • In longer sections of code, we can use // to denote a comment. • A comment is code that is ignored by the compiler. • The Java compiler ignores whitespace, so use line breaks wherever you think it will make your code clearer.
  • 40. Finally • This slide deck covers the very basics of Java - the building blocks. • It’s important to understand these, because everything else builds upon them. • Next, we’re going to look at Processing.