V2012.13. 2 Avon High School Tech Club Agenda Old Business –Delete Files New Business –Week 19 Topics: Intro to HTML/CSS: Questions? Group Executive Committee.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Object Oriented Programming in JAVA
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
Slide 1 of 40. Lecture A The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C,
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Hello, world! Dissect HelloWorld.java Compile it Run it.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
A Short Introduction to JAVA
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Week #2 Java Programming. Enable Line Numbering in Eclipse Open Eclipse, then go to: Window -> Preferences -> General -> Editors -> Text Editors -> Check.
V Avon High School Tech Club Agenda Old Business –Delete Files New Business –Week 16 Topics: Intro to HTML/CSS –Questions? Tech Club Forums.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
V Avon High School Tech Club Agenda Old Business –Delete Files New Business –Week 18 Topics: Intro to HTML/CSS: Questions? Summer Work Letter.
DAT602 Database Application Development Lecture 5 JAVA Review.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
CS107 Introduction to Computer Science Java Basics.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 2: Java Fundamentals
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
1 CS 007: Introduction to Computer Programming Ihsan Ayyub Qazi.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
By Mr. Muhammad Pervez Akhtar
CS 106 Introduction to Computer Science I 01 / 22 / 2007 Instructor: Michael Eckmann.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
introductory lecture on java programming
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
 Prepared by: Eng. Maryam Adel Abdel-Hady
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CompSci 230 S Programming Techniques
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Intro to ETEC Java.
Content Programming Overview The JVM A brief look at Structure
Chapter No. : 1 Introduction to Java.
Primitive Data, Variables, Loops (Maybe)
Variables, Expressions, and IO
Introduction to Programming in Java
Statements, Comments & Simple Arithmetic
An Introduction to Java – Part I, language basics
PHP.
Introduction to Java Brief history of Java Sample Java Program
Introduction to java Part I By Shenglan Zhang.
JAVA. Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of platforms, such.
How to Run a Java Program
Presentation transcript:

V

2 Avon High School Tech Club 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 Avon High School Tech Club HTML/CSS Class QUESTIONS?

4 Avon High School Tech Club Tech Club Executive Committee Next Year: –Election of Officers President Vice President Secretary Treasurer Send me an with interest

5 Avon High School Tech Club Website Help Two Projects –Non-Profit –Realtor Contact me if you are interested

6 Avon High School Tech Club Upcoming Schedule Today: Intro to Java May 14 th : Intro to C# (Guest Speaker) May 21 st : Embedded Programming May 28 th : TBD

7 Avon High School Tech Club Python review

8 Avon High School Tech Club INTRO TO JAVA

9 Avon High School Tech Club Intro to Java History Brief Overview Installation/Tools Getting Started Examples Resources

10 Avon High School Tech Club 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? Java Overview

11 Avon High School Tech Club 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 Avon High School Tech Club 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 Avon High School Tech Club Java Types … called Primitives Java TypeExample bytebyte b = 100;Integer shortshort s = 10000;Integer intint n = 5;Integer longlong ssNum = 999_99_9999L;Integer floatfloat f = (float) 4.5;Decimal doubledouble x = 123.4;Decimal booleanboolean b = false;true or false StringString s = “Hello";Words charchar c = ‘t';Letter

14 Avon High School Tech Club Comparing Java to Python PythonJava

15 Avon High School Tech Club Java Conditionals if(this is true){ do this } else{ do this instead }

16 Avon High School Tech Club 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 Avon High School Tech Club 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 Avon High School Tech Club Java Loops /* Find the average of 10 of numbers */ int counter; 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 Avon High School Tech Club 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 Avon High School Tech Club 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 Avon High School Tech Club Java Functions/Methods Example /* First we must define a method */ int addTwoIntegers(int a, int b){ int sum = a + b; return sum; } Return Type Method Name Arguments Method Body Return Value

22 Avon High School Tech Club Java Functions/Methods Example /* First we must define a method */ int addTwoIntegers(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 Avon High School Tech Club 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 + 12 we can use x += 12 –Also -=, *=, /= –The - sign is used for subtraction as well as negative numbers

24 Avon High School Tech Club 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 Avon High School Tech Club Quiz Time! System.out.println() is an example of a reusable chunk of code called a ________ method

26 Avon High School Tech Club Quiz Time! If we need our code to behave differently depending on some condition, we use the word _____ if

27 Avon High School Tech Club 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 Avon High School Tech Club 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 Avon High School Tech Club 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 Avon High School Tech Club Quiz Time! What is wrong with this statement: int x = 2.5; x is an integer but 2.5 is a float/double

31 Avon High School Tech Club Quiz Time! int, double, and float are examples of _____ Types

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

33 Avon High School Tech Club GETTING STARTED

34 Avon High School Tech Club Getting Started with Java Download Java Development Kit (JDK) – – oads/jdk7-downloads html Download JDK + NetBeans – Java/NetBeans Quick Start – Tip: Configure PATH

35 Avon High School Tech Club Steps to Creating a Java Application Source Code (.java) Compiler (javac) Bytecode (.class) Execute (java)

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

37 Avon High School Tech Club 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 Avon High School Tech Club Step 1: Source Code In the Java programming language, every application must contain a main method, 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 Avon High School Tech Club Step 1: Source Code In the Java programming language, every application must contain a main method, where app starts to execute: class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } The static keyword means main can be called before an object of the class has been created.

40 Avon High School Tech Club Step 1: Source Code In the Java programming language, every application must contain a main method, 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 Avon High School Tech Club Step 1: Source Code In the Java programming language, every application must contain a main method, where app starts to execute: class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } The String declares a parameter named args of type String (array)

42 Avon High School Tech Club Step 1: Source Code The last line uses the System class 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 Avon High School Tech Club Step 1: Source Code The last line uses the System class 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 Avon High School Tech Club Step 2: Compile Your Code javac HelloWorld.java Provided there are no compilation errors, you should now have a.class file: HelloWorld.class

45 Avon High School Tech Club Step 3: Execute Your Application java HelloWorld Hello World! Holla! You just created your first Java App!

46 Avon High School Tech Club Creating Rich Clients Swing JavaFX/Scene Builder

47 Avon High School Tech Club Resources Java Tutorial – Learning –

48 Avon High School Tech Club Your turn …

49 Avon High School Tech Club Getting Started 1. Download the Java Development Kit (JDK 7) (For Ubuntu: sudo apt-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 Avon High School Tech Club PATH on Windows Enter javac at 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"

51 Avon High School Tech Club Write Your Own Java Program Write a program that prints the name of your operating system and Java version. Hint: Search for system properties …

52 Avon High School Tech Club Challenge 1 public class SysInfo { public static void main(String[] args) { String nameOS = "os.name"; String javaVersion = "java.version"; System.out.println("\n General System Information"); System.out.println("\n OS Name: " + System.getProperty(nameOS)); System.out.println(" Java Version: " + System.getProperty(javaVersion)); }

53 Avon High School Tech Club Advanced Challenge … Write a program that prints the name of your operating system and Java version, then writes it to a file called sys.info Hint: Search for setProperty and file I/O …

54 Avon High School Tech Club Challenge 2 import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class PropApp { public static void main( String[] args ) { String nameOS = "os.name"; String javaVersion = "java.version"; Properties prop = new Properties();

55 Avon High School Tech Club Challenge 2 try { //set the properties value prop.setProperty("OperatingSystem", System.getProperty(nameOS)); prop.setProperty("JavaVersion", System.getProperty(javaVersion)); //save properties to project root folder prop.store(new FileOutputStream(“sys.info”), null); System.out.println("\n System info stored in sys.info”); } catch (IOException ex) { ex.printStackTrace(); }