Your SlideShare is downloading. ×
0
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Intro to Java
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Intro to Java

229

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
229
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

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

×