1 / 55

V2012.13

V2012.13. Agenda. Old Business Delete Files New Business Week 19 Topics: Intro to HTML/CSS: Questions? Group E xecutive Committee Website Help Introduction to Python Review Intro to Java. HTML/CSS Class. QUESTIONS?. Tech Club Executive Committee. Next Year: Election of Officers

joey
Download Presentation

V2012.13

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. V2012.13

  2. Agenda • Old Business • Delete Files • New Business • Week 19 Topics: • Intro to HTML/CSS: Questions? • Group Executive Committee • Website Help • Introduction to Python Review • Intro to Java

  3. HTML/CSS Class QUESTIONS?

  4. Tech Club Executive Committee • Next Year: • Election of Officers • President • Vice President • Secretary • Treasurer • Send me an email with interest

  5. Website Help • Two Projects • Non-Profit • Realtor • Contact me if you are interested

  6. Upcoming Schedule • Today: Intro to Java • May 14th: Intro to C# (Guest Speaker) • May 21st: Embedded Programming • May 28th: TBD

  7. Python review

  8. INTRO TO JAVA

  9. Intro to Java • History • Brief Overview • Installation/Tools • Getting Started • Examples • Resources

  10. Java Overview • Over 17 years old • Used in mobile, desktop and enterprise apps • Emphasizes code portability • Statically typed • Runs on multiple platforms (via JVM) • Did you know Android is Java-based?

  11. More on Java • Object-Oriented programming language • How we think about the world (nouns and verbs) • Java is the 1st or 2nd most popular, depending on who you ask and when

  12. Java Variables • Variable Naming Conventions: • Variable names must start with a lowercase letter • Variable names can’t have spaces in them • Variable names can have numbers in them, but they can’t start with them • Variables can’t have any symbols in them except for an underscore ( the _ character) • Achieved in Java using Types

  13. Java Types … called Primitives

  14. Comparing Java to Python Python Java

  15. Java Conditionals if(this is true){ do this } else{ do this instead }

  16. Java Conditionals if(x > 10){ System.out.println(“x is big!”); } else{ System.out.println(“x is small!”); } /* System.out.println() just tells Java to print what’s in the quotes. */

  17. Java Loops /* Keep doing this until it isn’t true anymore */ while(this is true){ do domething } /* Or repeat something an exact number of times */ for(counter = 0; counter < 10; counter = counter + 1){ do this every time }

  18. Java Loops /* Find the average of 10 of numbers */ intcounter; float sum = 0; for(counter = 0; counter < 10; counter = counter + 1){ sum = sum + nextNumber; } float average = sum / 10; For now, we’ll pretend that nextNumber comes from somewhere

  19. Java Functions/Methods • There are many situations where you will write code that you want to use again, executing the same instructions but on a different set of data. • This is why we use functions/methods • In the System.out.println() example, the String in quotes is the argument. The job of System.out.println()is to print its argument to the screen • Arguments can be variables or constants, it depends on the method

  20. Java Functions/Methods • Functions/Methods: • Reusable, named chunks of code • You’ve seen a Method already: • System.out.println() • Methods can take in arguments, represents data that the method will manipulate

  21. Java Functions/Methods Example /* First we must define a method */ intaddTwoIntegers(int a, int b){ intsum = a + b; return sum; } Method Name Arguments Return Type Method Body Return Value

  22. Java Functions/Methods Example /* First we must define a method */ intaddTwoIntegers(int a, int b){ return a + b; } /* Then we use the method */ addTwoIntegers(10,15); /* 25! */ /* We can treat a method like it is a variable of its return type */ int x = addTwoIntegers(10, 15); /* x is 25 */

  23. Java Programming Tips • Increment and Decrement an integer (add or subtract 1) • Instead of x = x + 1 use x++or ++x (use -- for decrement) • All of the arithmetic operators can be “combined” with an equal sign • Instead of x = x + 12we can use x += 12 • Also -=, *=, /= • The - sign is used for subtraction as well as negative numbers

  24. Java Programming Tips • Equals like assignment vs. equals like comparison • We use = to assign a value to a variable, so how do we ask if something is equal to something else? • ==means “is equal to” • When you’re “reading” code, you should read “=” as “becomes” and “==” as “is equal to”

  25. Quiz Time! System.out.println() is an example of a reusable chunk of code called a ________ method

  26. Quiz Time! If we need our code to behave differently depending on some condition, we use the word _____ if

  27. Quiz Time! If we need to repeat an action over and over again but we aren’t sure how many times, we use a _____ loop while

  28. Quiz Time! If we need to repeat an action over and over again and we know how many times, we use a _____ loop for

  29. Quiz Time! True or False: If we want to make a decision based on whether or not a variable is equal to something, we use “=” False We use “==“

  30. Quiz Time! What is wrong with this statement: intx = 2.5; x is an integer but 2.5 is a float/double

  31. Quiz Time! int, double, and floatare examples of _____ Types

  32. Quiz Time! What does this block of code do: inti = 0; while(i< 10) { System.out.println(i); i= i + 1; } a.) Print “i” 10 times b.) Prints the numbers 1 - 10 c.) Prints the numbers 0 - 10 d.) Prints the numbers 0 - 9

  33. GETTING STARTED

  34. Getting Started with Java • Download Java Development Kit (JDK) • http://tinyurl.com/355cx3m • http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html • Download JDK + NetBeans • http://tinyurl.com/76mgogl • Java/NetBeansQuick Start • https://netbeans.org/kb/docs/java/quickstart.html • Tip: Configure PATH

  35. Steps to Creating a Java Application Compiler (javac) Execute (java) Source Code (.java) Bytecode (.class)

  36. Step 1: Source Code class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } }

  37. Step 1: Source Code • Every application begins with a class definition class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } }

  38. Step 1: Source Code • In the Java programming language, every application must contain a mainmethod, where app starts to execute: class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } } • The public keyword is called an access modifier, meaning it can be accessed by code outside the class

  39. Step 1: Source Code • In the Java programming language, every application must contain a mainmethod, where app starts to execute: class HelloWorldApp { publicstatic void main(String[] args) { System.out.println("Hello World!"); } } • The statickeyword means main can be called before an object of the class has been created.

  40. Step 1: Source Code • In the Java programming language, every application must contain a mainmethod, where app starts to execute: class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } } • The void keyword tells the compiler main does not return a value.

  41. Step 1: Source Code • In the Java programming language, every application must contain a mainmethod, where app starts to execute: class HelloWorldApp { public static voidmain(String[] args){ System.out.println("Hello World!"); } } • The String declares a parameter named argsof type String (array)

  42. Step 1: Source Code • The last line uses the Systemclass from the core library to print the "Hello World!" message to standard output. class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } }

  43. Step 1: Source Code • The last line uses the Systemclass from the core library to print the "Hello World!" message to standard output. class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } }

  44. Step 2: Compile Your Code javac HelloWorld.java • Provided there are no compilation errors, you should now have a .class file: HelloWorld.class

  45. Step 3: Execute Your Application java HelloWorld Hello World! Holla! You just created your first Java App!

  46. Creating Rich Clients • Swing • JavaFX/Scene Builder

  47. Resources • Java Tutorial • http://docs.oracle.com/javase/tutorial/ • Learning • http://www.learnjavaonline.org/

  48. Your turn …

  49. Getting Started 1. Download the Java Development Kit (JDK 7) (For Ubuntu: sudoapt-get install openjdk-7-jdk) 2. Open a text editor 3. Write a simple ‘Hello World’ program 4. Save it as “HelloWorld.java” 5. Compile it (javac HelloWorld.java) 6. Run your program (java HelloWorld)

  50. PATH on Windows Enter javacat command prompt, if you receive an error, install the JDK If JDK is installed, you may need to set the PATH At the command prompt: set path=%path%;“C:\Program Files\Java\jdk1.7.0_21\bin"

More Related