• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Intro to Java
 

Intro to Java

on

  • 300 views

 

Statistics

Views

Total Views
300
Views on SlideShare
300
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Intro to Java Intro to Java Presentation Transcript

    • Introduction to Javahttp://www.slideshare.net/annagerber/intro-to-java
    • instructions
    • Programming languages
    • .java file compile .class file
    • Integrated DevelopmentEnvironment (IDE)
    • Objects & ClassesObjects have: State (fields) Behaviour (methods)Classes provide “blueprints” for different kinds of objectspublic class MyClass {}
    • main methodpublic class MyClass { public static void main(String[] args){ // This is a comment }}
    • StatementsString 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 1Write a program to output “Hello, World!”
    • Exercise 2Write a program that asks someone to enter theirname and then prints “Hello, <name>”
    • Conditional behaviourBoolean 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)) …
    • Loopswhile (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”)) ...