CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 645-4739 1.

Slides:



Advertisements
Similar presentations
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Advertisements

Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall NEW   NEW 1.
Java Swing Recitation – 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University.
Agenda –interfaces and realization –type hierarchy –introduction to graphics and event handling.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE116: Introduction to Computer Science 2 Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Things to mention public static void main(String [] args) imports comments –block comments /* … */ –single-line comments // –javadoc comments and tags.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Slides prepared by Rose Williams, Binghamton University Chapter 17 Swing I.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
Io package as Java’s basic I/O system continue’d.
Laboratory Study October, The very first example, traditional "Hello World!" program: public class first { public static void main (String[ ]
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 1.
Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Comp 248 Introduction to Programming Chapter 6 Arrays Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Thanks, Andrew. Reminders: –wear the wireless mike –combination is 1-31 –speak slowly, pause for questions –I’d rather you get through less material than.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Anatomy.1 Anatomy of a Class & Terminology. Anatomy.2 The Plan Go over MoveTest.java from Big Java Basic coding conventions Review with GreeterTest.java.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
CS 415 N-Tier Application Development By Umair Ashraf June 25,2013 National University of Computer and Emerging Sciences Lecture # 4 Web Presentation Patterns.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
By Mr. Muhammad Pervez Akhtar
Lesson 28: More on the GUI button, frame and actions.
Constructors, GUI’s(Using Swing) and ActionListner
CiS 260: App Dev I Chapter 6: GUI and OOD.
Presentation transcript:

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall

Agenda Announcements – Cell phones / laptops off & away / Name signs out Last time –interfaces and realization –type hierarchy –introduction to graphics and event handling Today –main method –import directive –java.lang package –System.out.println –Observer pattern for event handling

Announcements Exam 2 –covers material from exam 1 up to & including 10/19 –review on Monday 10/22 –exam on Wednesday 10/24 No recitations in exam week: 10/22 – 10/26

main method public static void main(String[] args) { … } main method is standard entry point for a Java program main method is invoked by Java runtime system static –reserved word –indicates member is associated with CLASS not INSTANCE parameter of main –square brackets are special syntax used with arrays we will discuss arrays at start of CSE116 –the parameter ‘args’ is initialized with ‘command line arguments’ – arguments given on the command line when the program is run

static members: methods and variables static methods –a static method is invoked on a class, rather than an object –a static method has no access to instance variables –its invocation record has no ‘this’ static variables –a static variable is accessed via a class, rather than an object –a static variable is often declared ‘public’ –a static variable is often given a name of all upper- case letters, as in java.awt.Color.RED

import directive an import directive is used to allow unqualified use of a name which would otherwise need to be fully qualified form: import ; examples: import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; These examples allow the names GridLayout, JButton, JFrame and Jlabel to be used without full qualification. This improves both the writability and readability of code.

java.lang package the java.lang package is special in that its elements are all imported by default

System.out.println The System class is defined in the java.lang package. The name ‘System’ can therefore be used in an unqualified way, even without an explicit import directive. ‘out’ is a public and static variable of the System class, whose type is PrintStream The ‘PrintStream’ class defines a static method named ‘println’ ‘println’ accepts an argument of any type, and prints a textual representation of the argument on the console (see the output in the console view if running in Eclipse, or the terminal window from which the program was started if running outside of Eclipse).

String concatenation ‘+’ is the name of the String concatenation operator ‘+’ is a binary operator, meaning it takes two arguments (also called operands) ‘+’ is an infix operator, meaning it is written between its two arguments “Hi” + “there” is an expression whose value is “Hithere”. “The answer is ”+17 is an expression whose value is “The answer is 17”. The int expression 17 is converted to a textual equivalent, the String “17” (which consists of the two characters ‘1’ and ‘7’)

Observer pattern for event handling Invariant – Variant decomposition –good software design practice Invariant –the part of the system that does not change from one usage scenario to the next –for event-handling, this is the event-generating component (e.g. JButton) –a JButton has the same basic functionality no matter how it is being used visual representation the ability to register mouse-clicks over top of it the ability to respond to mouse-clicks in some way (as defined by the (variant) event handler) Variant part: the event-handling code –the part of the system that can change from one usage scenario to the next –for event-handling, this is the event handler itself (e.g. the ActionListener implementor) –the ActionListener interface introduces a point of flexibility into the software: different implementations of the interface can exist all implementations MUST adhere to the ‘contract’ that the interface defines (i.e. all event handlers for a JButton must define the actionPerformed method, as specified in the ActionLIstener interface.