Metody. public final class Ucet {... } public final void print() {... } tato metoda nemůže být překryta (overloaded) v

Size: px
Start display at page:

Download "Metody. public final class Ucet {... } public final void print() {... } tato metoda nemůže být překryta (overloaded) v"

Transcription

1 Seminář Java Speciální třídy, výčtový typ Radek Kočí Fakulta informačních technologií VUT Únor 2008 Radek Kočí Seminář Java Speciální třídy, výčtový typ 1/ 25

2 Téma přednášky Abstraktní třídy Vnořené třídy Anonymní třídy Výčtový typ (enums) Proměnný počet parametrů (varargs) Statický import Radek Kočí Seminář Java Speciální třídy, výčtový typ 2/ 25

3 Modifikátor final Deklaruje konečný (neměnný) stav Třídy public final class Ucet {... od této třídy nelze dědit (vytvářet její potomky) Metody public final void print() {... tato metoda nemůže být překryta (overloaded) v odvozených třídách (potomci) Proměnné protected final int i = 10; protected final String s = "řetězec"; protected final Banka b = new Banka(); obsah proměnné je neměnný konstanta Radek Kočí Seminář Java Speciální třídy, výčtový typ 3/ 25

4 Abstraktní třída Abstraktní třída třída, která danou specifikaci implementuje jen částečně nemůže mít instance klíčové slovo abstract Abstraktní třída = částečná implementace Třída = úplná implementace Radek Kočí Seminář Java Speciální třídy, výčtový typ 4/ 25

5 Abstraktní třída Příklad public class Vehicle {... public int price(int km) {??? public class Car extends Vehicle { protected int price(int km) { // podle osobniho auta... public class Bus extends Vehicle { protected int price(int km) { // podle autobusu... Radek Kočí Seminář Java Speciální třídy, výčtový typ 5/ 25

6 Abstraktní třída Příklad public abstract class Vehicle {... public Vehicle(int weight, int capacity) { this.weight = weight; this.capacity = capacity; protected abstract int price(int km); public class Car extends Vehicle { public Car() { super(2000, 5); protected int price(int km) {... Radek Kočí Seminář Java Speciální třídy, výčtový typ 6/ 25

7 Top-level classes Třídy nejvyšší úrovně (top-level classes) normální třídy jsou přímými členy nějakého balíku package balik; public class TopLevel1 {... Radek Kočí Seminář Java Speciální třídy, výčtový typ 7/ 25

8 Vnořené třídy (inner classes) Lokální třídy vnořené v jiné třídě (na úrovni lokálních proměnných) uváděné uvnitř bloku (platné pouze v uvedeném bloku) nesmí být public, private a protected Radek Kočí Seminář Java Speciální třídy, výčtový typ 8/ 25

9 Vnořené třídy (inner classes) public class TopLevel1 { private String text = "interni promenna"; public void test() { { class A { public A() { System.out.println(text); A a = new A(); // tady uz neni trida A dostupna Radek Kočí Seminář Java Speciální třídy, výčtový typ 9/ 25

10 Vnořené třídy (inner classes) Členské třídy (member classes) vnořené v jiné třídě (na úrovni vlastností objektu) public class TopLevel1 { private String text = "interni promenna"; class Inner { public Inner() { System.out.println("Inner: " + text); public m() { Inner i = new Inner();... Radek Kočí Seminář Java Speciální třídy, výčtový typ 10/ 25

11 Vnořené třídy (inner classes) Vnořené top-level třídy členské třídy s modifikátorem static vnořená rozhraní mohou být public, private a protected Radek Kočí Seminář Java Speciální třídy, výčtový typ 11/ 25

12 Vnořené třídy (inner classes) public class TopLevel1 { private String text = "interni promenna"; static public class TopLevel2 { public TopLevel2() { TopLevel1 t = new TopLevel1(); System.out.println(t.text); interface Cool {... Radek Kočí Seminář Java Speciální třídy, výčtový typ 12/ 25

13 Vnořené třídy (inner classes) Vnořené top-level třídy používá se k seskupení souvisejících tříd bez nutnosti vytvářet nový balík přístup k vnořeným top-level třídám (rozhraním) new TopLevel1.TopLevel2(); Radek Kočí Seminář Java Speciální třídy, výčtový typ 13/ 25

14 Anonymní třídy Anonymní třídy (anonymous classes) zvláštní případ vnořené třídy new Typ ( parametry ) { tělo anonymní třídy Typ představuje jméno konstruktoru rodičovské(!) třídy, od které je anonymní třída odvozena (následují jeho parametry) jméno rozhraní anonymní třída jako jediná může přímo instanciovat rozhraní (zde se parametry neuvádějí) Radek Kočí Seminář Java Speciální třídy, výčtový typ 14/ 25

15 Anonymní třídy class NejakaTrida { Runnable r = new Runnable() { public void run() { //... Radek Kočí Seminář Java Speciální třídy, výčtový typ 15/ 25

16 Enums Reprezentace výčtového typu (Java < 5.0) int Enum pattern public static final int SEASON WINTER = 0; public static final int SEASON SPRING = 1; public static final int SEASON SUMMER = 2; public static final int SEASON FALL = 3; není typově bezpečný hodnoty nejsou informativní (vždy int; jiné názvy, stejná hodnota) Radek Kočí Seminář Java Speciální třídy, výčtový typ 16/ 25

17 Enums Výčtový typ (Java >= 5.0) typově bezpečný enum Season {WINTER, SPRING, SUMMER, FALL plnohodnotná třída! rozšiřuje třídu java.lang.enum Radek Kočí Seminář Java Speciální třídy, výčtový typ 17/ 25

18 Enums class EnumsDemo { public enum Season { WINTER, SPRING, SUMMER, FALL ; private Season season; public static void main(string[] args) { new EnumsDemo(); public EnumsDemo() { season = Season.WINTER; System.out.println(season); for (Season s : Season.values()) System.out.println("Value of Season: " + s); Radek Kočí Seminář Java Speciální třídy, výčtový typ 18/ 25

19 Enums public enum Planet { MERCURY (3.303e+23, e6), VENUS (4.869e+24, e6), EARTH (5.976e+24, e6); private final double mass; // in kilograms private final double radius; // in meters Planet(double mass, double radius) { this.mass = mass; this.radius = radius; Radek Kočí Seminář Java Speciální třídy, výčtový typ 19/ 25

20 Enums public static final double G = E-11; double surfacegravity() { return G * mass / (radius * radius); double surfaceweight(double othermass) { return othermass * surfacegravity(); Radek Kočí Seminář Java Speciální třídy, výčtový typ 20/ 25

21 Enums public static void main(string[] args) { double earthweight = Double.parseDouble(args[0]); double mass = earthweight/planet.earth.surfacegravity(); for (Planet p : Planet.values()) System.out.printf("Your weight on %s is %f%n", p, p.surfaceweight(mass)); language/enums.html Radek Kočí Seminář Java Speciální třídy, výčtový typ 21/ 25

22 Varargs Varargs metoda s proměnným počtem parametrů pole objektů třídy Object Object[] arguments = { new Integer(7), new Date(), "a disturbance in the Force" ; String result = MessageFormat.format( "At {1,time on {1,date, there was {2 " + "on planet {0,number,integer.", arguments); Radek Kočí Seminář Java Speciální třídy, výčtový typ 22/ 25

23 Varargs Varargs (Java >= 5.0) vlastnost skrývající nutnost obalení polem poslední argument: Object... name Radek Kočí Seminář Java Speciální třídy, výčtový typ 23/ 25

24 Varargs class Args { public static void main(string[] args) { Args a = new Args(); a.print("hi ", "hou ", "ha"); public void print(string s, Object... args) { String str = ""; System.out.println(args.length); for (Object o : args) str += (String) o; System.out.println(s + str); Radek Kočí Seminář Java Speciální třídy, výčtový typ 24/ 25

25 Static import Přístup ke statickým členům double r = Math.cos(Math.PI * theta); Využití statického importu import static java.lang.math.pi; //import static java.lang.math.*;... double r = cos(pi * theta); používat velice opatrně! (kolize identifikátorů, těžko čitelný kód,...) Radek Kočí Seminář Java Speciální třídy, výčtový typ 25/ 25

package balik; public class TopLevel1 {... }

package balik; public class TopLevel1 {... } Seminář Java Speciální třídy, výčtový typ Radek Kočí Fakulta informačních technologií VUT Březen 2010 Radek Kočí Seminář Java Speciální třídy, výčtový typ 1/ 20 Téma přednášky Vnořené třídy Anonymní třídy

More information

Java Lectures. Enhancements in Java 1.5

Java Lectures. Enhancements in Java 1.5 1 Enhancements in Java 1.5 2 Generics Enhancement to the type system: a type or method can operate on objects of various types with compile-time type safety, compile-time type safety to the Collections

More information

Avoiding magic numbers

Avoiding magic numbers Avoiding magic numbers Variables takes on a small set of values Use descriptive names instead of literal values Java enumerations Using in a switch statement 2 Magic numbers Where did the value come from?

More information

Taming the Tiger. Joshua Bloch, Distinguished Engineer Neal Gafter, Senior Staff Engineer Sun Microsystems. java.sun.

Taming the Tiger. Joshua Bloch, Distinguished Engineer Neal Gafter, Senior Staff Engineer Sun Microsystems. java.sun. Taming the Tiger java.sun.com/javaone/sf Joshua Bloch, Distinguished Engineer Neal Gafter, Senior Staff Engineer Sun Microsystems 1 Watch Out for Tigers! J2SE 1.5 platform Code name Tiger Beta2 available

More information

CS 251 Intermediate Programming More on classes

CS 251 Intermediate Programming More on classes CS 251 Intermediate Programming More on classes Brooke Chenoweth University of New Mexico Spring 2018 Empty Class public class EmptyClass { Has inherited methods and fields from parent (in this case, Object)

More information

Taming the Tiger Joshua Bloch Neal Gafter

Taming the Tiger Joshua Bloch Neal Gafter Joshua Bloch Neal Gafter 1 Watch Out for Tigers! Java TM 2 Platform, Standard Edition 5.0 Code named Tiger Beta2 Available for download now! A major theme ease of development Seven new language features

More information

COMP6700/2140 Enums. Alexei B Khorev and Josh Milthorpe. Research School of Computer Science, ANU. March 2017

COMP6700/2140 Enums. Alexei B Khorev and Josh Milthorpe. Research School of Computer Science, ANU. March 2017 COMP6700/2140 Enums Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU March 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Enums March 2017 1 / 15 Topics 1

More information

JAVA V Assertions Java, winter semester

JAVA V Assertions Java, winter semester JAVA Assertions 1 Assertion since Java 1.4 the statement with a boolean expression a developer supposes that the expression is always satisfied (evaluates to true) if it is evaluated to false -> error

More information

Topic 5: Enumerated Types and Switch Statements

Topic 5: Enumerated Types and Switch Statements Topic 5: Enumerated Types and Switch Statements Reading: JBD Sections 6.1, 6.2, 3.9 1 What's wrong with this code? if (pressure > 85.0) excesspressure = pressure - 85.0; else safetymargin = 85.0 - pressure;!

More information

Sat 1/6/2018. MULTITHREAD... 5 THREADS What do you mean by Multithreaded program?... 5 LIFE CYCLE OF A THREAD:... 5

Sat 1/6/2018. MULTITHREAD... 5 THREADS What do you mean by Multithreaded program?... 5 LIFE CYCLE OF A THREAD:... 5 MULTITHREAD... 5 THREADS... 5 1. What do you mean by Multithreaded program?... 5 LIFE CYCLE OF A THREAD:... 5 THREAD METHODS:... 5 2. Implement Runnable method Example:... 6 3. class which extends Thread

More information

University of Palestine. Mid Exam Total Grade: 100

University of Palestine. Mid Exam Total Grade: 100 First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

Chapter 1b Classes and Objects

Chapter 1b Classes and Objects Data Structures for Java William H. Ford William R. Topp Chapter 1b Classes and Objects Bret Ford 2005, Prentice Hall Object-Oriented Programming An object is an entity with data and operations on the

More information

Everything You Ever Wanted To Know About Java O-O. 7-Dec-15

Everything You Ever Wanted To Know About Java O-O. 7-Dec-15 Everything You Ever Wanted To Know About Java O-O 7-Dec-15 Types Java has eight primitive types: short, byte, char, int, long all integral types float, double both real types, but with limited precision

More information

SUN Sun Certified Associate for the Java Platform.

SUN Sun Certified Associate for the Java Platform. SUN 310-019 Sun Certified Associate for the Java Platform http://killexams.com/exam-detail/310-019 QUESTION: 234 Given: 1. abstract class A { 2. class B { 3. interface C { 4. interface D { 5. // insert

More information

Java Application Development

Java Application Development In order to learn which questions have been answered correctly: 1. Print these pages. 2. Answer the questions. 3. Send this assessment with the answers via: a. FAX to (212) 967-3498. Or b. Mail the answers

More information

Lab Solutions: Experimenting with Enumerated Types

Lab Solutions: Experimenting with Enumerated Types 1 of 5 2/16/2007 11:07 AM Lab Solutions: Experimenting with Enumerated Types 1 Instructions: Omitted. 2 Getting Ready: Omitted. 3 Using Integer Constants Instead of Enumerated Types: It is common practice

More information

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1

Module Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are

More information

Forthcoming Java Programming Language Features. Joshua Bloch and Neal Gafter Senior Staff Engineers Sun Microsystems, Inc.

Forthcoming Java Programming Language Features. Joshua Bloch and Neal Gafter Senior Staff Engineers Sun Microsystems, Inc. Forthcoming Java Programming Language Features Joshua Bloch and Neal Gafter Senior Staff Engineers Sun Microsystems, Inc. A Brief History of the Java Programming Language 1995 (1.0) First public release

More information

OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK. COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK

OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK. COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK OLLSCOIL NA heireann THE NATIONAL UNIVERSITY OF IRELAND, CORK COLAISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK Mock Exam 2010 Second Year Computer Science CS2500: Software Development Dr Mock

More information

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 1

1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring Quiz 1 1.00/1.001 Introduction to Computers and Engineering Problem Solving Spring 2011 - Quiz 1 Name: MIT Email: TA: Section: You have 80 minutes to complete this exam. For coding questions, you do not need

More information

University of Tokyo Java Class September 22-26, 2003 Forthcoming Java Language Features

University of Tokyo Java Class September 22-26, 2003 Forthcoming Java Language Features University of Tokyo Java Class September 22-26, 2003 Forthcoming Java Language Features Marc Hamilton Director of Technology Global Education and Research Sun Microsystems, Inc Watch Out for Tigers! Java

More information

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none

CSC 207H Fall L Java Quiz Duration 25 minutes Aids allowed: none CSC 207H Fall L0101 2011 Java Quiz Duration 25 minutes Aids allowed: none Last Name: Student Number: First Name: (Please fill out the identification section above and read the instructions below.) Good

More information

JAVA Unit testing Java, winter semester

JAVA Unit testing Java, winter semester JAVA Unit testing Introduction unit testing testing small units of functionality a unit independent on other ones tests are separated creating helper objects for tests context typically in OO languages

More information

Introduction to Programming (Java) 4/12

Introduction to Programming (Java) 4/12 Introduction to Programming (Java) 4/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

*Java has included a feature that simplifies the creation of

*Java has included a feature that simplifies the creation of Java has included a feature that simplifies the creation of methods that need to take a variable number of arguments. This feature is called as varargs (short for variable-length arguments). A method that

More information

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003 1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS1004: Intro to CS in Java, Spring 2005 Lecture #13: Java OO cont d. Janak J Parekh janak@cs.columbia.edu Administrivia Homework due next week Problem #2 revisited Constructors, revisited Remember: a

More information

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

BSc. (Hons.) Software Engineering. Examinations for / Semester 2 BSc. (Hons.) Software Engineering Cohort: BSE/04/PT Examinations for 2005-2006 / Semester 2 MODULE: OBJECT ORIENTED PROGRAMMING MODULE CODE: BISE050 Duration: 2 Hours Reading Time: 5 Minutes Instructions

More information

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace

More information

Object-Oriented Concepts

Object-Oriented Concepts JAC444 - Lecture 3 Object-Oriented Concepts Segment 2 Inheritance 1 Classes Segment 2 Inheritance In this segment you will be learning about: Inheritance Overriding Final Methods and Classes Implementing

More information

CompSci 125 Lecture 11

CompSci 125 Lecture 11 CompSci 125 Lecture 11 switch case The? conditional operator do while for Announcements hw5 Due 10/4 p2 Due 10/5 switch case! The switch case Statement Consider a simple four-function calculator 16 buttons:

More information

Java 1.5 in a Nutshell

Java 1.5 in a Nutshell Java 1.5 in a Nutshell Including Generics, Enumerated Types, Autoboxing/Unboxing, and an Enhanced for Loop http://java.sun.com/j2se/1.5.0/docs/guide/language/ CS 2334 University of Oklahoma Brian F. Veale

More information

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable? Peer Instruction 8 Classes and Objects How can multiple methods within a Java class read and write the same variable? A. Allow one method to reference a local variable of the other B. Declare a variable

More information

Following is the general form of a typical decision making structure found in most of the programming languages:

Following is the general form of a typical decision making structure found in most of the programming languages: Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined

More information

Course information. Petr Hnětynka 2/2 Zk/Z

Course information. Petr Hnětynka  2/2 Zk/Z JAVA Introduction Course information Petr Hnětynka hnetynka@d3s.mff.cuni.cz http://d3s.mff.cuni.cz/~hnetynka/java/ 2/2 Zk/Z exam written test zápočet practical test in the lab max 5 attempts zápočtový

More information

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes

COMP200 - Object Oriented Programming: Test One Duration - 60 minutes COMP200 - Object Oriented Programming: Test One Duration - 60 minutes Study the following class and answer the questions that follow: package shapes3d; public class Circular3DShape { private double radius;

More information

Notes on Chapter Three

Notes on Chapter Three Notes on Chapter Three Methods 1. A Method is a named block of code that can be executed by using the method name. When the code in the method has completed it will return to the place it was called in

More information

Functional Java Lambda Expressions

Functional Java Lambda Expressions Functional Java Lambda Expressions 1 Functions as a First Class Citizen If there was just some way of packaging the compare function And then passing that function as an argument to sort Then we wouldn

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming 1. Review 2. Exam format OOPReview - M. Joldoş - T.U. Cluj 1 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one

More information

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question) CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers

More information

Data Reference Searcher. Documentation

Data Reference Searcher. Documentation Documentation Martin Dráb 8/19/2010 TABLE OF CONTENT Table of content... 1 Basic information... 2 Supported versions of Microsoft Dynamics AX... 2 Supported languages... 2 Installation... 3 User guide...

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

Encapsulation in Java

Encapsulation in Java Encapsulation in Java EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Encapsulation (1.1) Consider the following problem: A person has a name, a weight, and a height. A person s

More information

Course information. Petr Hnětynka 2/2 Zk/Z

Course information. Petr Hnětynka  2/2 Zk/Z JAVA Introduction Course information Petr Hnětynka hnetynka@d3s.mff.cuni.cz http://d3s.mff.cuni.cz/~hnetynka/java/ 2/2 Zk/Z exam written test zápočet practical test in the lab zápočtový program "reasonable"

More information

Exceptions Questions https://www.journaldev.com/2167/java-exception-interview-questionsand-answers https://www.baeldung.com/java-exceptions-interview-questions https://javaconceptoftheday.com/java-exception-handling-interviewquestions-and-answers/

More information

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013 CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013 Name: This exam consists of 6 problems on the following 6 pages. You may use your two-sided hand-written 8 ½ x 11 note sheet during the exam.

More information

CS 61B Discussion 5: Inheritance II Fall 2014

CS 61B Discussion 5: Inheritance II Fall 2014 CS 61B Discussion 5: Inheritance II Fall 2014 1 WeirdList Below is a partial solution to the WeirdList problem from homework 3 showing only the most important lines. Part A. Complete the implementation

More information

COMP-202A, Fall 2007, All Sections Assignment 1

COMP-202A, Fall 2007, All Sections Assignment 1 COMP-202A, Fall 2007, All Sections Assignment 1 Due: Monday September 24, 2007 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all the general instructions

More information

cannot be used directly by the class However, a static method can create (or be given) objects, and can send messages to them

cannot be used directly by the class However, a static method can create (or be given) objects, and can send messages to them What is a class? Object Oriented Programming 1. Review 2. Exam format A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create objects

More information

What is a class? Object Oriented Programming. What is a class? Classes. A class is primarily a description of objects, or instances, of that class

What is a class? Object Oriented Programming. What is a class? Classes. A class is primarily a description of objects, or instances, of that class What is a class? Object Oriented Programming 1. Review 2. Exam format A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create objects

More information

Binghamton University. CS-140 Fall Functional Java

Binghamton University. CS-140 Fall Functional Java Functional Java 1 First Class Data We have learned how to manipulate data with programs We can pass data to methods via arguments We can return data from methods via return types We can encapsulate data

More information

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type

More information

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Some Sample AP Computer Science A Questions - Solutions

Some Sample AP Computer Science A Questions - Solutions Some Sample AP Computer Science A Questions - s Note: These aren't from actual AP tests. I've created these questions based on looking at actual AP tests. Also, in cases where it's not necessary to have

More information

Class. Chapter 6: Data Abstraction. Example. Class

Class. Chapter 6: Data Abstraction. Example. Class Chapter 6: Data Abstraction In Java, there are three types of data values primitives arrays objects actually, arrays are a special type of object Class In Java, objects are used to represent data values

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice 01. An array is a (A) (B) (C) (D) data structure with one, or more, elements of the same type. data structure with LIFO access. data structure, which allows transfer between

More information

LECTURE 2 (Gaya College of Engineering)

LECTURE 2 (Gaya College of Engineering) LECTURE 2 (Gaya College of Engineering) 1) CHARACTERISTICS OF OBJECTS: Object is an instance of a class. So, it is an active entity. Objects have three basic characteristics. They are- State: An object

More information

( &% class MyClass { }

( &% class MyClass { } Recall! $! "" # ' ' )' %&! ( &% class MyClass { $ Individual things that differentiate one object from another Determine the appearance, state or qualities of objects Represents any variables needed for

More information

CS180. Exam 1 Review

CS180. Exam 1 Review CS180 Exam 1 Review What is the output to the following code? System.out.println("2 + 2 = " + (2 + 2)); System.out.println("2 + 2 = " + 2 + 2); What is the output to the following code? System.out.println(String.valueOf(15+20));

More information

Advanced Object Oriented Programming EECS2030Z

Advanced Object Oriented Programming EECS2030Z Advanced Object Oriented Programming EECS2030Z 1 Academic Support Programs: Bethune having trouble with your FSC and LSE courses? consider using the Academic Support Programs at Bethune College PASS free,

More information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2 UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2014/15 PROGRAMMING 2 CMP-5015Y Time allowed: 2 hours Answer four questions. All questions carry equal weight. Notes are

More information

CS 302 Week 9. Jim Williams

CS 302 Week 9. Jim Williams CS 302 Week 9 Jim Williams This Week P2 Milestone 3 Lab: Instantiating Classes Lecture: Wrapper Classes More Objects (Instances) and Classes Next Week: Spring Break Will this work? Double d = new Double(10);

More information

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2

More information

COMP15111: Introduction to Architecture

COMP15111: Introduction to Architecture COMP15111 Lecture 9 1/33 COMP15111: Introduction to Architecture Lecture 9: Methods Pete Jinks School of Computer Science, University of Manchester Autumn 2011 COMP15111 Lecture 9 A Java Program 2/33 Lecture

More information

Binghamton University. CS-140 Fall Functional Java

Binghamton University. CS-140 Fall Functional Java Functional Java 1 First Class Data We have learned how to manipulate data with programs We can pass data to methods via arguments We can return data from methods via return types We can encapsulate data

More information

1.00 Lecture 8. Static Class Methods, Data

1.00 Lecture 8. Static Class Methods, Data 1.00 Lecture 8 Static Methods and Data Static Class Methods, Data Static data fields: Only one instance of data item for entire class Not one per object Static is a historic keyword from C and C++ Class

More information

Introduction to the Java T M Language

Introduction to the Java T M Language Introduction to the Java T M Language Jan H. Meinke July 1, 2000 1 Introduction Since its introduction in 1995 Java has become one of the most popular programming language. At first powered by the popularity

More information

AP CS Unit 6: Inheritance Notes

AP CS Unit 6: Inheritance Notes AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything

More information

PASS4TEST IT 인증시험덤프전문사이트

PASS4TEST IT 인증시험덤프전문사이트 PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from

More information

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs. Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java

More information

Common Mistakes with Functions. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Common Mistakes with Functions. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Common Mistakes with Functions CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Common Mistakes with Functions Printing instead of returning. Returning

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University OOP Three main programming mechanisms that constitute object-oriented programming (OOP) Encapsulation Inheritance

More information

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue General Loops in Java Look at other loop constructions Very common while loop: do a loop a fixed number of times (MAX in the example) int

More information

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer STUDENT NAME: ID: The exam consists of five questions. There are a total of 10 points. You may use the back

More information

VYLEPŠOVANIE KONCEPTU TRIEDY

VYLEPŠOVANIE KONCEPTU TRIEDY VYLEPŠOVANIE KONCEPTU TRIEDY Typy tried class - definuje premenné a metódy (funkcie). Ak nie je špecifikovaná inak, viditeľnosť členov je private. struct - definuje premenné a metódy (funkcie). Ak nie

More information

CSE 142 Wi04 Midterm 2 Sample Solution Page 1 of 8

CSE 142 Wi04 Midterm 2 Sample Solution Page 1 of 8 CSE 142 Wi04 Midterm 2 Sample Solution Page 1 of 8 Question 1. (6 points) Complete the definition of method printtriangle(n) below so that when it is executed it will print on System.out an upside down

More information

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding Java Class Design Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding eugeny.berkunsky@gmail.com http://www.berkut.mk.ua Objectives Implement encapsulation Implement inheritance

More information

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions CS211 Spring 2005 Prelim 1 March 10, 2005 Solutions Instructions Write your name and Cornell netid above. There are 6 questions on 9 numbered pages. Check now that you have all the pages. Write your answers

More information

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice Test 01. An array is a ** (A) data structure with one, or more, elements of the same type. (B) data structure with LIFO access. (C) data structure, which allows transfer between

More information

Selected Questions from by Nageshwara Rao

Selected Questions from  by Nageshwara Rao Selected Questions from http://way2java.com by Nageshwara Rao Swaminathan J Amrita University swaminathanj@am.amrita.edu November 24, 2016 Swaminathan J (Amrita University) way2java.com (Nageshwara Rao)

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 5 Anatomy of a Class Outline Problem: How do I build and use a class? Need to understand constructors A few more tools to add to our toolbox Formatting

More information

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005

Lecture 8 Classes and Objects Part 2. MIT AITI June 15th, 2005 Lecture 8 Classes and Objects Part 2 MIT AITI June 15th, 2005 1 What is an object? A building (Strathmore university) A desk A laptop A car Data packets through the internet 2 What is an object? Objects

More information

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring

More information

STATIC, ABSTRACT, AND INTERFACE

STATIC, ABSTRACT, AND INTERFACE STATIC, ABSTRACT, AND INTERFACE Thirapon Wongsaardsakul STATIC When variable is a static type, java allocates memory for it at loading time. Class loader Byte code verifier Static variable has been loaded

More information

Lecture 2: Java & Javadoc

Lecture 2: Java & Javadoc Lecture 2: Java & Javadoc CS 62 Fall 2018 Alexandra Papoutsaki & William Devanny 1 Instance Variables or member variables or fields Declared in a class, but outside of any method, constructor or block

More information

This exam is open book. Each question is worth 3 points.

This exam is open book. Each question is worth 3 points. This exam is open book. Each question is worth 3 points. Page 1 / 15 Page 2 / 15 Page 3 / 12 Page 4 / 18 Page 5 / 15 Page 6 / 9 Page 7 / 12 Page 8 / 6 Total / 100 (maximum is 102) 1. Are you in CS101 or

More information

Nested Loops. A loop can be nested inside another loop.

Nested Loops. A loop can be nested inside another loop. Nested Loops A loop can be nested inside another loop. Nested loops consist of an outer loop and one or more inner loops. Each time the outer loop is repeated, the inner loops are reentered, and started

More information

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming

More information

A Java source file can have the following elements that, if present, must be specified in the following order:

A Java source file can have the following elements that, if present, must be specified in the following order: Access Control A Java source file can have the following elements that, if present, must be specified in the following order: 1. An optional package declaration to specify a package name. 2. Zero or more

More information

A Monitor package for Java

A Monitor package for Java A Monitor package for Java To implement true Hoare-style monitors with a Signal and Wait discipline, I ve created the monitor package for Java. Threads in Java Java provides an easy to use Thread class.

More information

CS2 Assignment A1S The Simple Shapes Package

CS2 Assignment A1S The Simple Shapes Package CS2 Assignment A1S The Simple Shapes Package Overview In this project you will create a simple shapes package consisting of three interfaces and three classes. In abstract terms, you will establish classes

More information

Computer Programming, I. Laboratory Manual. Final Exam Solution

Computer Programming, I. Laboratory Manual. Final Exam Solution Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution

More information

More types, Methods, Conditionals. ARCS Lab.

More types, Methods, Conditionals. ARCS Lab. More types, Methods, Conditionals ARCS Lab. Division Division ( / ) operates differently on integers and on doubles! Example double a = 5.0/2.0; 0; // a = 2.5 int b = 4/2; // b = 2 int c = 5/2; // c =

More information

Listen EECS /40

Listen EECS /40 1/40 Listen EECS 4315 www.eecs.yorku.ca/course/4315/ 2/40 Event listeners 3/40 JPF uses (event) listeners. target=traversal classpath=. cg.enumerate_random=true listener=gov.nasa.jpf.listener.statespacedot

More information

Interfaces. Quick Review of Last Lecture. November 6, Objects instances of classes. Static Class Members. Static Class Members

Interfaces. Quick Review of Last Lecture. November 6, Objects instances of classes. Static Class Members. Static Class Members November 6, 2006 Quick Review of Last Lecture ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev Objects instances of a class with a static variable size

More information