Quiz 1 What is this? (explain the use of the reserved word “this” in a class method). Answer each question briefly. – What is a Constructor? –Under what.

Slides:



Advertisements
Similar presentations
Java Review Interface, Casting, Generics, Iterator.
Advertisements

Final Review.
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
1 Review of classes and subclasses M fast through this material, since by now all have seen it in CS100 or the Java bootcamp First packages Then classes.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Previous Exam 1.0. Question 1 - a Is the following statement true or false? Briefly explain your answer. A && B is the same as B && A for any Boolean.
More Arrays Length, constants, and arrays of arrays By Greg Butler.
Java. Why Java? It’s the current “hot” language It’s almost entirely object-oriented It has a vast library of predefined objects It’s platform independent.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 18 Exception Handling.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 9 - Inheritance.
The Java Programming Language
GUI programming Graphical user interface-based programming.
Exceptions Syntax, semantics, and pragmatics Exceptions1.
Chap. 1 Classes, Types, and Objects. How Classes Are Declared [ ] class [extends ] [implements,, … ] { // class methods and instance variable definitions.
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.
Lecture 2 Exception handling Advanced Java Programming 1 dr inż. Wojciech Bieniecki
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
Intro to Applets August 19, 2008 Mrs. C. Furman. Java Applets vs. Java Applications Java Applet: a program that is intended for use on the web. Java Applet:
Even-Driven Programming and basic Graphical User Interface.
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
Programming in Java CSCI-2220 Object Oriented Programming.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Java Applets and other things. Applets Very like usual classes Use init() method instead of main Applets provide 4 methods init() start() stop() destroy()
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
CMSC 202 Arrays 2 nd Lecture. Aug 6, Array Parameters Both array indexed variables and entire arrays can be used as arguments to methods –An indexed.
Computer Science 209 GUIs Model/View/Controller Layouts.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
Cs205: engineering software university of virginia fall 2006 Programming Exceptionally David Evans
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Java Applet What is a Java Applet? How is applet compiled?
“Form Ever Follows Function” Louis Henri Sullivan
GUIs Model/View/Controller Layouts
Chapter 13: Advanced GUIs and Graphics
2/26/12 Quiz Bowl.
Graphical user interface-based programming
CSC 113 Tutorial QUIZ I.
CiS 260: App Dev I Chapter 6: GUI and OOD.
Corresponds with Chapter 5
A type is a collection of values
Presentation transcript:

Quiz 1 What is this? (explain the use of the reserved word “this” in a class method). Answer each question briefly. – What is a Constructor? –Under what circumstances would a Constructor method for a class execute? –Can a class have more than one Constructor? Given String s = "potato"; String v = s.substring(0,3); String w = s.substring(0,3); Is v==w true or false? This is an object reference that refers to the current object for which a method was invoked. Brief answers –A method invoked on object creation. –Typically, a Constructor is executed when an object is created by use of the “new” operator. –Yes, as long as they have different parameters. v == w is false. The substring method will create new objects each time it is invoked.

Quiz 2 The following code creates a 2x2 block of buttons. Add/modify the code to create an applet with 6 buttons arranged in 3 rows and 2 columns.. import javax.swing.*; import java.awt.*; public class ButtonJComponent extends JApplet { public void init() { Container c = getContentPane(); c.setLayout(new GridLayout(2,2); JButton button1 = new JButton("one"); JButton button2 = new JButton("two"); JButton button3 = new JButton("three"); JButton button4 = new JButton("four"); } 2. Discuss the changes necessary to make the program in 1 a stand-alone java app instead of an applet. You may discuss this in words…exact code is not necessary in all cases, but try to cover all the steps. For example: “extends JApplet” changes to “???” The init method changes to…. Must add a main method that does what? Anything else? Change body to: c.setLayout(new GridLayout(3,2); JButton button1 = new JButton("one"); JButton button2 = new JButton("two"); JButton button3 = new JButton("three"); JButton button4 = new JButton("four"); JButton button3 = new JButton("five"); JButton button4 = new JButton("six"); The following two lines are sufficient: for(int i=0; i < b.length; i++) System.out.println(b[i]); -extends JApplet changes to extends JFrame -the init method becomes a constructor ButtonJComponent() -A main method must be added which creates a ButtonJComponent object, and calls the setSize() and show() methods -a windowclosing handler should be added

Quiz What error will Java report from the following code? (That is…what’s wrong with this sequence? You do not need the actual error message.) int[] a; a[3] = 5; 2. Correct any errors in the following declaration. char[] vowel = {a, e, i, o, u}; 3. Consider int v = {23, 44, 78}; int w = v; w[2] = 100; What is the value of v[2]? 4. Write Java code to swap integer array elements a[i] and a[j]. a is a reference to an array, but the array has not been created (with the new operator for instance). The actual error reported is: variable a might not have been initialized char[] vowel = {‘a’,’b’,’c’,’d’,’e’}; v[2] has the value of 100. (w is an alias of v so the statement w[2] = 100 also changes v. Something like this: int I,J,temp; temp = a[I]; a[I] = a[J]; a[I] = temp;

Quiz 4 Show the contents of a stack (of Strings) after the every 5 operations and at the end.Assume the stack is initially empty. Display the stack from Top to bottom. (Commands are listed left to right to conserve space. Push (“Example”) Push (“Bogus”) Push (“Sham”) Pop() Push(“Fine”) Push(“A”) Push(“Of”) Pop() Push(“Heck”) Push(“One”) Pop() Push(“Is”) Push(“List”) Pop() Push(“This”) At the end the stack will have (from top to bottom) This Is A Fine Example The list of operations is intended to be one continuous list, with line breaks. So the final answer is (from left to right): it is a Fine Example Anyway

Quiz 5 Which of the following correctly describes the relation between an abstract class and an interface? –An interface is another name for an abstract class. –An interface is not a class, but is otherwise identical to an abstract class. –Every abstract class implements an interface. –An abstract class must be totally abstract, but an interface may be partially implemented. –None of the above The code public class B extends A { } –defines a class that inherits all the methods of A –defines a class that inherits the public methods of A only –will not compile because the body in empty –none of the above The code public class B extends A { } defines a class B that –implements A –is a superclass of A –is a subclass of A –none of the above None of the above. All of the statements are false. None of the above. B inherits public and protected methods and if they are in the same package, B will inherit methods created with no modifier. B is a subclass of A

Quiz 6 What is displayed on the console when the following code is run? class Test { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i=0; int y=2/i; System.out.println("Exceptions are fun"); } catch(RuntimeException ex) { System.out.println("I take Exception to that"); } finally { System.out.println("End of the block"); } Welcome to Java I take Exception to that End of the block What is displayed on the console when the following code is run? class Test1 { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i=0; System.out.println("Exceptions are fun"); } catch(RuntimeException ex) { System.out.println("I take Exception to that"); } finally { System.out.println("End of the block"); } Welcome to Java Exceptions are fun End of the block