SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Introduction
                                                     to
                                                   Java




http://www.slideshare.net/annagerber/intro-to-java
instructions
Programming languages
.java file




             compile




                       .class file
Integrated Development
Environment (IDE)
Objects & Classes
Objects have:
 State (fields)
 Behaviour (methods)



Classes provide “blueprints” for different kinds of objects
public class MyClass {


}
main method
public class MyClass {
    public static void main(String[] args){
          // This is a comment
    }
}
Statements
String name = “Anna”;

int numberOfThings = 0;



MyClass m = new MyClass();

m.doSomething();

// This is a comment on a single line

/* This is a longer comment
 * that can go over more than one line
 */
Input and Output (IO)
Exercise 1
Write a program to output “Hello, World!”
Exercise 2
Write a program that asks someone to enter their
name and then prints “Hello, <name>”
Conditional behaviour
Boolean logic:
 and            &&
 or             ||   if (anna.isTired) {
 not            !        if (isNightTime && !anna.isWorking) {
                             anna.sleep();
 equals         ==
                          } else {
 not equal      !=          anna.drinkCoffee();
 greater than >          }
                      }
 less than      <
Comparing Strings
 == and != are for basic types like integers

 For objects use equals() e.g. to compare Strings:


 If (string1.equals(string2)) …
 If (string1.equalsIgnoreCase(string2)) …
Loops
while (coffee) {

     person.drink(coffee);

}



for (int i = 0; i < 10; i++) {

    // do something 10 times

}
Exercise 3
 Write a program with the following behaviour:
  Ask the person to enter some text
  If the person says “yay” the program responds with “hey”
  If the person says “boo” the program responds with “hoo”
  If the person says “how” the program responds with “now”

 Challenge:
  Keep prompting and responding until the input is “bye”
Putting it all together:
   Choose your own
   adventure
    Write a choose your own adventure game!




System.out.println(“You are being chased by a T-Rex, do you a) run or b) fight?”);
input = scan.next();
if ( input.equals(“a”)) ...

Weitere ähnliche Inhalte

Was ist angesagt?

Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
Ravi_Kant_Sahu
 
CVJ531: Intro to MySQL
CVJ531: Intro to MySQLCVJ531: Intro to MySQL
CVJ531: Intro to MySQL
Clay Ewing
 

Was ist angesagt? (20)

Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
1.6 oo traits
1.6 oo traits1.6 oo traits
1.6 oo traits
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 
Reflection and Introspection
Reflection and IntrospectionReflection and Introspection
Reflection and Introspection
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
CVJ531: Intro to MySQL
CVJ531: Intro to MySQLCVJ531: Intro to MySQL
CVJ531: Intro to MySQL
 
Nested class in java
Nested class in javaNested class in java
Nested class in java
 
Java
JavaJava
Java
 
Inner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in javaInner classes ,annoumous and outer classes in java
Inner classes ,annoumous and outer classes in java
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
Inner classes
Inner classesInner classes
Inner classes
 
Methods and constructors in java
Methods and constructors in javaMethods and constructors in java
Methods and constructors in java
 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
 
Constructors
ConstructorsConstructors
Constructors
 
Nested classes in java
Nested classes in javaNested classes in java
Nested classes in java
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
 

Andere mochten auch (6)

Annotations Supporting Scholarly Editing
Annotations Supporting Scholarly EditingAnnotations Supporting Scholarly Editing
Annotations Supporting Scholarly Editing
 
Supporting Open Scholarly Annotation
Supporting Open Scholarly AnnotationSupporting Open Scholarly Annotation
Supporting Open Scholarly Annotation
 
Studiereis Beijing Ppt
Studiereis Beijing PptStudiereis Beijing Ppt
Studiereis Beijing Ppt
 
JavaScript Robotics
JavaScript RoboticsJavaScript Robotics
JavaScript Robotics
 
Motivation
MotivationMotivation
Motivation
 
Drugsandthe Brain Part7 Psychedelics
Drugsandthe Brain Part7 PsychedelicsDrugsandthe Brain Part7 Psychedelics
Drugsandthe Brain Part7 Psychedelics
 

Ähnlich wie Intro to Java

Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Java Intro
Java IntroJava Intro
Java Intro
backdoor
 

Ähnlich wie Intro to Java (20)

Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
 
02 - Prepcode
02 - Prepcode02 - Prepcode
02 - Prepcode
 
Scala Quick Introduction
Scala Quick IntroductionScala Quick Introduction
Scala Quick Introduction
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Java
JavaJava
Java
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
Java PPt.ppt
Java PPt.pptJava PPt.ppt
Java PPt.ppt
 
Java Basics V3
Java Basics V3Java Basics V3
Java Basics V3
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Oop java
Oop javaOop java
Oop java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
A Scala tutorial
A Scala tutorialA Scala tutorial
A Scala tutorial
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Java Intro
Java IntroJava Intro
Java Intro
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 

Mehr von Anna Gerber

Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)
Anna Gerber
 

Mehr von Anna Gerber (18)

Internet of Things (IoT) Intro
Internet of Things (IoT) IntroInternet of Things (IoT) Intro
Internet of Things (IoT) Intro
 
How the Web works
How the Web worksHow the Web works
How the Web works
 
Do you want to build a robot
Do you want to build a robotDo you want to build a robot
Do you want to build a robot
 
"Serverless" express
"Serverless" express"Serverless" express
"Serverless" express
 
Iot 101
Iot 101Iot 101
Iot 101
 
Adding Electronics to 3D Printed Action Heroes
Adding Electronics to 3D Printed Action HeroesAdding Electronics to 3D Printed Action Heroes
Adding Electronics to 3D Printed Action Heroes
 
3D Printing Action Heroes
3D Printing Action Heroes3D Printing Action Heroes
3D Printing Action Heroes
 
3D Sculpting Action Heroes
3D Sculpting Action Heroes3D Sculpting Action Heroes
3D Sculpting Action Heroes
 
International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)International NodeBots Day Brisbane roundup (BrisJS)
International NodeBots Day Brisbane roundup (BrisJS)
 
Intro to Electronics in Python
Intro to Electronics in PythonIntro to Electronics in Python
Intro to Electronics in Python
 
Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)Data Visualisation Workshop (GovHack Brisbane 2014)
Data Visualisation Workshop (GovHack Brisbane 2014)
 
Supporting Web-based Scholarly Annotation
Supporting Web-based Scholarly AnnotationSupporting Web-based Scholarly Annotation
Supporting Web-based Scholarly Annotation
 
Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)Annotations Supporting Scholarly Editing (OA European Roll Out)
Annotations Supporting Scholarly Editing (OA European Roll Out)
 
Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)
 
Intro to data visualisation
Intro to data visualisationIntro to data visualisation
Intro to data visualisation
 
Getting started with the Trove API
Getting started with the Trove APIGetting started with the Trove API
Getting started with the Trove API
 
HackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover BrisbaneHackFest Brisbane: Discover Brisbane
HackFest Brisbane: Discover Brisbane
 
Using Yahoo Pipes
Using Yahoo PipesUsing Yahoo Pipes
Using Yahoo Pipes
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Intro to Java

  • 1. Introduction to Java http://www.slideshare.net/annagerber/intro-to-java
  • 4. .java file compile .class file
  • 6. Objects & Classes Objects have:  State (fields)  Behaviour (methods) Classes provide “blueprints” for different kinds of objects public class MyClass { }
  • 7. main method public class MyClass { public static void main(String[] args){ // This is a comment } }
  • 8. Statements String name = “Anna”; int numberOfThings = 0; MyClass m = new MyClass(); m.doSomething(); // This is a comment on a single line /* This is a longer comment * that can go over more than one line */
  • 10. Exercise 1 Write a program to output “Hello, World!”
  • 11. Exercise 2 Write a program that asks someone to enter their name and then prints “Hello, <name>”
  • 12. Conditional behaviour Boolean logic:  and &&  or || if (anna.isTired) {  not ! if (isNightTime && !anna.isWorking) { anna.sleep();  equals == } else {  not equal != anna.drinkCoffee();  greater than > } }  less than <
  • 13. Comparing Strings  == and != are for basic types like integers  For objects use equals() e.g. to compare Strings: If (string1.equals(string2)) … If (string1.equalsIgnoreCase(string2)) …
  • 14. Loops while (coffee) { person.drink(coffee); } for (int i = 0; i < 10; i++) { // do something 10 times }
  • 15. Exercise 3  Write a program with the following behaviour:  Ask the person to enter some text  If the person says “yay” the program responds with “hey”  If the person says “boo” the program responds with “hoo”  If the person says “how” the program responds with “now”  Challenge:  Keep prompting and responding until the input is “bye”
  • 16. Putting it all together: Choose your own adventure  Write a choose your own adventure game! System.out.println(“You are being chased by a T-Rex, do you a) run or b) fight?”); input = scan.next(); if ( input.equals(“a”)) ...