Selected Java Topics
|
|
- Letitia Carpenter
- 6 years ago
- Views:
Transcription
1 Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings and AWT Type Casting Java Development Environments Advanced Java Features 1-1 Introduction Java was introduced in May 1995 by Sun MicroSystems. A pure object oriented programming language. Highly portable - same byte code on all supported platforms. Secure and Internet ready. Just-in-time (JIT) compiler makes it comparable to native language (like C/C++). Based on C++ but removed many dangerous features. Build-in exception handling. 1-2
2 Basic Types, Objects and Pointers Basic types are NOT objects: boolean - true or false char (16-bit Unicode) byte (8-bit signed, from -128 to 127) short (16-bit signed, from -32,768 to 32,767) int (32-bit signed, from -2,147,483,648 to 2,147,483,647) long (64-bit signed, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807) float (32-bit, range roughly ± , 6-7 significant decimal digits) double (64-bit, range roughly ± , 15 significant decimal digits) Anything other than these basic types is an object. All objects are created in the system s memory heap. 1-3 Objects and Pointers Objects cannot be moved out from the memory heap. When we need to use an object, we create, in the local memory, a pointer to the desired object, and use that pointer instead. As a result, when programming Java, we are dealing with pointers most of the time. (Surprise!) 1-4
3 Pointer Arithmetic Pointer arithmetic allows programmers a very high degree of flexibility in programming. However, it will also cause serious problems if used carelessly. Unlike C and C++, Java does NOT allow pointer arithmetic. Therefore, Java is much safer than C and C Parameter Passing In Java, all the parameters passed into a method are passed by value, that means a copy of the variables is made into the method s local memory. If the method changes the values of the parameters, the calling method will NOT be able to see the changes. 1-6
4 Parameter Passing If an object is passed into a method. It is actually the pointer to the object being passed in and copied. The result is that if the method changes the content of object, the calling method will be able to see the change. However, if the method assigns another object to the pointer passed in, the calling method will NOT be able to see the new object. 1-7 Example public class Test public static void toupper (String s) s = s.touppercase (); System.out.println (s); java Test hello HELLO hello public static void main (String [] args) String s = hello ; System.out.println (s); toupper (s); System.out.println (s); 1-8
5 Arrays Java also allows programmers to use arrays to hold collections of information. Arrays are real Java objects. The size of an array cannot be changed. The length member will tell us how many elements are in the array. int size = array.length; Java arrays are safer than C/C++ arrays as the Java Virtual Machine will check for boundary before allowing access to the elements stored in the array. 1-9 Garbage Collection All objects are created in the system s memory heap and are managed by the system s garbage collecting mechanism. If an object is no longer needed, the memory allocated to this object will be reclaimed on the next Garbage Collection. The users (or the programmers) do not have control on when the Garbage Collection will be executed. 1-10
6 Modifiers private friendly protected public final abstract static 1-11 private private class - only useful if defined as inner class (more on inner class later). private method - only the class that defines the method can use it. private variable - only the class that defines the variable can use it. 1-12
7 friendly The default modifier. friendly class - can be extended and instantiated by everyone in the same package. friendly method - can be used by everyone in the same package. friendly variable - can be used by everyone in the same package protected protected class - only useful if defined as inner class. protected method - can only be used by the class itself and its subclass, as well as everyone in the same package. protected variable - can only be used by the class itself and its subclass, as well as everyone in the same package. 1-14
8 public public class - can be extended and instantiated by everyone. There can be at most one public class in each Java file. The name of the file must be the same as the public class, with.java append as extension. public method - can be used by everyone. public variable - can be read and written by everyone final final class - a class that cannot be extended. final method - a method that cannot be overridden. final variable - a variable of which the value cannot be changed - i.e. it is a constant - a value must be provided when the variable is declared. final int PI = ; 1-16
9 abstract abstract class - a class that is declared with the abstract keyword. abstract method - a method that is declared with the abstract keyword, there is no need to provide implementation for abstract method. If a class contains any abstract method, it has to be declared as an abstract class. abstract and final cannot be used at the same time - i.e. a class or method cannot be abstract and final at the same time static static variable - a variable that belongs to the class, not to the object (instance of the class) - if one object changes its value, the change will be effective to all objects of the same class. static method - a method that belongs to the class, not to the object - it does not need an instance to be used. 1-18
10 Inner Class A class that is defined inside another class. Inner class is a member of its defining class, so it can use all other members (variable, method) from that class directly without passing in a reference of the object Abstract Classes and Interfaces An abstract class cannot be instantiated. An interface is a class that has only abstract methods. By default, all the methods in an interface should be public. 1-20
11 Abstract Classes A class that extends an abstract class will not be abstract if and only if it provides implementation to all the abstract methods that are defined in the super classes. Use an abstract class if you have some common implementation that would be beneficial to all the subclasses Interfaces Interfaces can be used to define the operations required to implement a class - we will use this technique extensively in our course. Interfaces are also useful if we have to extend from more than one class - Java does not support multiple inherence - i.e. it does not allow you to extend from more than one class - however, it allows your class to implement more that one interface. 1-22
12 Example Shape Circle Rectang le Triang le Line 1-23 Shape Interface public interface Shape public void draw (Location l, Color c); public void erase (); public void move (Location newlocation); 1-24
13 Shape Abstract Class public abstract class Shape private Location savedlocation; private Color savedcolor; private Color backgroundcolor; public void abstract draw (Location l, Color c); public void erase () draw (savedlocation, backgroundcolor); public void move (Location newlocation) erase (); draw (newlocation, savedcolor); 1-25 Exceptions and Runtime Exceptions Throwable Exception Error RuntimeException 1-26
14 Exceptions An exception condition will occur if: an exception is thrown inside the method the method calls another method that throws an exception. The exception must be handled by either: caught by a try-catch block; or declared in the method signature Java compiler will enforce that every Exception is handled properly Runtime Exceptions RuntimeException is extended from Exception. RuntimeException does not have to be declared in the method signature. RuntimeException can be handled as a regular Exception. However, if you are confident that the RuntimeException will not occur under certain situation, you do not have to catch them or declare them in the method signature. 1-28
15 Static Variables and Static Methods Static variables and static methods belongs to the class, not the object. Static variables and static methods can be used without creating the object first. Useful in implementing the Singleton pattern and in giving each object of the class an unique ID The Singleton Pattern A design pattern provides a ready-made solution to design problems. The singleton pattern is a design pattern in that we only want to have a single instance of the class. A singleton class usually does not allow the user to create the object directly. Instead it provides a method to get the instance. We enforce this by making the constructor of the class private or protected. 1-30
16 Singleton Example public final class Singleton static Singleton theonlyinstance = null; // declare the constructor private so the // user cannot create the instance directly private Singleton () public static Singleton getinstance () if (theonlyinstance == null) theonlyinstance = new Singleton (); return theonlyinstance; 1-31 Unique ID Example public class Student static private int nextid = 1; private int id; public Student () id = nextid++; public int getid () return id; public String tostring () return ( Student + id); 1-32
17 Java Constants Java allows us to define constants: public interface Season public static final int SPRING = 1; public static final int SUMMER = 2; public static final int FALL = 3; public static final int WINTER = 4; public static int gettemperature (int season); 1-33 Java Constants We can use the constants directly: int springtemperature = Season.getTemperature (Season.SPRING); What happens if we pass in a zero or negative number: int currenttemperature = Season.getTemperature (0); int currenttemperature = Season.getTemperature (-1); int currenttemperature = Season.getTemperature (5); All these code will compile correctly, but the code will give us problem during runtime. 1-34
18 Type Safe Constants Java also allows us to define type safe constants: public final class SeasonConstants public static final SeasonConstants SPRING = new SeasonConstants ( spring ); public static final SeasonConstants SUMMER = new SeasonConstants ( summer ); public static final SeasonConstants FALL = new SeasonConstants ( fall ); public static final SeasonConstants WINTER = new final SeasonConstants ( winter ); 1-35 Type Safe Constants private String name; private SeasonConstants (String name) this.name = name; public String tostring () return name; 1-36
19 Usage This is how you can use type safe constants: public interface Season public static int gettemperature (SeasonConstants season); int springtemperature = Season.getTemperature (SeasonConstants.SPRING); 1-37 Oops What happens if we pass in a zero or negative number: int currenttemperature = Season.getTemperature (0); int currenttemperature = Season.getTemperature (-1); int currenttemperature = Season.getTemperature (5); Oops, the compiler will not allow us to do this. 1-38
20 Discussion Why the constructor is defined as a private constructor? What happens if the constructor is not private? Why the class SeasonConstants is defined as a final class? What happens if the class is not a final class? Why the constants is defined as static constants? Will this give us any benefits? 1-39 Swing and AWT Swing is an extension of AWT (Abstract Window Toolkit) Swing has several advantages over AWT: Uniform look-and-feel across different platforms The look-and-feel is configurable More powerful components Fix some bugs on the AWT 1-40
21 Swing Swing was introduced in Java 1.1, but is not part of the Java core distribution until Java 1.2 In Java 1.1, swing components are distributed in the package com.sun.java.swing In Java 1.2 swing components are distributed in the package javax.swing 1-41 Swing and Applet Currently both Netscape 4.7 and Internet Explore 5.0 do NOT support Swing. Appletviewer that comes with JDK is the only browser that support Swing. If you are writing an applet and your target users are the open public, avoid using Swing. 1-42
22 Type Casting Type Casting is used to change an object of one type into another type. ClassCastException will be thrown if converting into an incompatible type. ClassCastException is a RuntimeException and needs to be caught if you are not sure whether the conversion will be successful or not. Two types of casting: upcasting downcasting 1-43 Upcasting Converting an object into one of its super classes. Example: Object obj = new MyClass (); Upcasting is implicit, i.e. you don t have to explicitly write anything to perform an upcasting (although you can.) Upcasting is safe and always possible. 1-44
23 Downcasting Converting an object into one of its subclasses. Example: MyClass myinstance = (MyClass) obj; Downcasting is not always safe. It is possible that an object will be downcast into an incompatible object (and as a result a ClassCastException will be thrown.) Therefore, downcasting is not implicit and needs to be written out (see example above) and ClassCastException needed to be caught if necessary Java Development Environments JDK (Java Development Kit) From Sun MicroSystems ( Current Release Command line interface only free JCreator From Xinox Software ( Current Release 2.5 IDE Need JDK free Lite edition 1-46
24 IDEs DOs and DON Ts Editing Syntax Highlighting Parenthesis Matching Compilation Compile within IDE Errors Locating Debugging Break Points Stepping through Code Code Generation Produce proprietary (nonstandard Java) code Produce unnecessary code Visual Editing Hard to position components precisely Produce non-standard Java Code 1-47 Advanced Java Features Here is a list of some advanced Java features that we will not cover: Thread Programming (Using and programming) Java Beans RMI (Remote Method Invocation) JNI (Java Native Interface) Java2D and Java3D (Advanced Java Graphic Toolkits) For more information about these features, consult any good Java reference available from book stores. Some of these references are listed in the course web page and are available for download. 1-48
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 informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationInheritance. SOTE notebook. November 06, n Unidirectional association. Inheritance ("extends") Use relationship
Inheritance 1..n Unidirectional association Inheritance ("extends") Use relationship Implementation ("implements") What is inherited public, protected methods public, proteced attributes What is not inherited
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More informationThe Sun s Java Certification and its Possible Role in the Joint Teaching Material
The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified
More information2 rd class Department of Programming. OOP with Java Programming
1. Structured Programming and Object-Oriented Programming During the 1970s and into the 80s, the primary software engineering methodology was structured programming. The structured programming approach
More informationCompaq Interview Questions And Answers
Part A: Q1. What are the difference between java and C++? Java adopts byte code whereas C++ does not C++ supports destructor whereas java does not support. Multiple inheritance possible in C++ but not
More informationDOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS
Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationAssumptions. History
Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand
More informationToday. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time
CS2110 Fall 2011 Lecture 25 Java program last time Java compiler Java bytecode (.class files) Compile for platform with JIT Interpret with JVM Under the Hood: The Java Virtual Machine, Part II 1 run native
More informationSpecial Topics: Programming Languages
Lecture #23 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 23 Lecture #23 1 Slide 1 Java: History Spring 1990 April 1991: Naughton, Gosling and Sheridan (
More information15CS45 : OBJECT ORIENTED CONCEPTS
15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?
More information(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days
Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented
More informationBrief Summary of Java
Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java
More informationIntroduction to Java
Introduction to Java Module 1: Getting started, Java Basics 22/01/2010 Prepared by Chris Panayiotou for EPL 233 1 Lab Objectives o Objective: Learn how to write, compile and execute HelloWorld.java Learn
More informationCourse Status Polymorphism Containers Exceptions Midterm Review. CS Java. Introduction to Java. Andy Mroczkowski
CS 190 - Java Introduction to Java Andy Mroczkowski uamroczk@cs.drexel.edu Department of Computer Science Drexel University February 11, 2008 / Lecture 4 Outline Course Status Course Information & Schedule
More informationCMSC 331 Second Midterm Exam
1 20/ 2 80/ 331 First Midterm Exam 11 November 2003 3 20/ 4 40/ 5 10/ CMSC 331 Second Midterm Exam 6 15/ 7 15/ Name: Student ID#: 200/ You will have seventy-five (75) minutes to complete this closed book
More information3. Java - Language Constructs I
Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks
More informationOperators and Expressions
Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More informationProgramming. Syntax and Semantics
Programming For the next ten weeks you will learn basic programming principles There is much more to programming than knowing a programming language When programming you need to use a tool, in this case
More informationChapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.
Chapter 1 GETTING STARTED SYS-ED/ Computer Education Techniques, Inc. Objectives You will learn: Java platform. Applets and applications. Java programming language: facilities and foundation. Memory management
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationIntroduction to Java https://tinyurl.com/y7bvpa9z
Introduction to Java https://tinyurl.com/y7bvpa9z Eric Newhall - Laurence Meyers Team 2849 Alumni Java Object-Oriented Compiled Garbage-Collected WORA - Write Once, Run Anywhere IDE Integrated Development
More informationChapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.
hapter 1 INTRODUTION SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Objectives You will learn: Java features. Java and its associated components. Features of a Java application and applet. Java data types. Java
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More informationCOT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748
COT 3530: Data Structures Giri Narasimhan ECS 389; Phone: x3748 giri@cs.fiu.edu www.cs.fiu.edu/~giri/teach/3530spring04.html Evaluation Midterm & Final Exams Programming Assignments Class Participation
More informationJava for Programmers Course (equivalent to SL 275) 36 Contact Hours
Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the
More informationCore JAVA Training Syllabus FEE: RS. 8000/-
About JAVA Java is a high-level programming language, developed by James Gosling at Sun Microsystems as a core component of the Java platform. Java follows the "write once, run anywhere" concept, as it
More informationUNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED
UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED EXERCISE 11.1 1. static public final int DEFAULT_NUM_SCORES = 3; 2. Java allocates a separate set of memory cells in each instance
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationClass, 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 informationModern Programming Languages. Lecture Java Programming Language. An Introduction
Modern Programming Languages Lecture 27-30 Java Programming Language An Introduction 107 Java was developed at Sun in the early 1990s and is based on C++. It looks very similar to C++ but it is significantly
More informationCS 11 java track: lecture 3
CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces
More informationCH. 2 OBJECT-ORIENTED PROGRAMMING
CH. 2 OBJECT-ORIENTED PROGRAMMING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OBJECT-ORIENTED
More informationAtelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.
marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More information20 Most Important Java Programming Interview Questions. Powered by
20 Most Important Java Programming Interview Questions Powered by 1. What's the difference between an interface and an abstract class? An abstract class is a class that is only partially implemented by
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationB2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA
B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationJava Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.
Java Inheritance Written by John Bell for CS 342, Spring 2018 Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources. Review Which of the following is true? A. Java classes may either
More informationDeclarations and Access Control SCJP tips
Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for
More informationThe design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT
Designing an ADT The design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT What data does a problem require? What operations does a problem
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationObject Oriented Java
Object Oriented Java I. Object based programming II. Object oriented programing M. Carmen Fernández Panadero Raquel M. Crespo García Contents Polymorphism Dynamic binding Casting.
More informationNational University. Faculty of Computer Since and Technology Object Oriented Programming
National University Faculty of Computer Since and Technology Object Oriented Programming Lec (8) Exceptions in Java Exceptions in Java What is an exception? An exception is an error condition that changes
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationPoints To Remember for SCJP
Points To Remember for SCJP www.techfaq360.com The datatype in a switch statement must be convertible to int, i.e., only byte, short, char and int can be used in a switch statement, and the range of the
More informationIntroduction to Java Written by John Bell for CS 342, Spring 2018
Introduction to Java Written by John Bell for CS 342, Spring 2018 Based on chapters 1 to 6 of Learning Java by Patrick Niemeyer and Daniel Leuck, with additional material from other sources. History I
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationC++ Programming: Polymorphism
C++ Programming: Polymorphism 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Run-time binding in C++ Abstract base classes Run-time type identification 2 Function
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationIntroduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview
Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple
More informationJava: introduction to object-oriented features
Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationFundamentals of Object Oriented Programming
INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of
More informationClass 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 informationCS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II
CS2110 Fall 2011 Lecture 25 Under the Hood: The Java Virtual Machine, Part II 1 Java program last time Java compiler Java bytecode (.class files) Compile for platform with JIT Interpret with JVM run native
More informationNOOTAN PADIA ASSIST. PROF. MEFGI, RAJKOT.
NOOTAN PADIA ASSIST. PROF. MEFGI, RAJKOT. Object and Classes Data Abstraction and Encapsulation Inheritance Polymorphism Dynamic Binding Message Communication Objects are the basic runtime entities in
More informationCS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?
CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look
More informationIntroduction to Object-Oriented Programming
Introduction to Object-Oriented Programming Review 2: Object-Oriented Programming Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Review 2: Object-Oriented Programming 1 / 14 Topics
More informationCMSC 331 Second Midterm Exam
1 10/ 2 10/ 3 60/ 331 First Midterm Exam 16 November 2004 4 10/ 5 20/ CMSC 331 Second Midterm Exam 6 30/ 7 10/ Name: Username: 150/ You will have seventy-five (75) minutes to complete this closed book
More informationComputer Science II (20073) Week 1: Review and Inheritance
Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system
More informationPESIT Bangalore South Campus
PESIT Bangalore South Campus 15CS45 : OBJECT ORIENTED CONCEPTS Faculty : Prof. Sajeevan K, Prof. Hanumanth Pujar Course Description: No of Sessions: 56 This course introduces computer programming using
More informationLecture 4: Extending Classes. Concept
Lecture 4: Extending Classes Concept Inheritance: you can create new classes that are built on existing classes. Through the way of inheritance, you can reuse the existing class s methods and fields, and
More informationObjects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes
Based on Introduction to Java Programming, Y. Daniel Liang, Brief Version, 10/E 1 Creating Classes and Objects Classes give us a way of defining custom data types and associating data with operations on
More informationPage 1
Java 1. Core java a. Core Java Programming Introduction of Java Introduction to Java; features of Java Comparison with C and C++ Download and install JDK/JRE (Environment variables set up) The JDK Directory
More informationLecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University
Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types
More informationPolymorphism. return a.doublevalue() + b.doublevalue();
Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces
More informationAnswer1. Features of Java
Govt Engineering College Ajmer, Rajasthan Mid Term I (2017-18) Subject: PJ Class: 6 th Sem(IT) M.M:10 Time: 1 hr Q1) Explain the features of java and how java is different from C++. [2] Q2) Explain operators
More informationSTRUCTURING OF PROGRAM
Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the
More information5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.
Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationSelf-test Java Programming
Self-test Java Programming Document: e0883test.fm 16 January 2018 ABIS Training & Consulting Diestsevest 32 / 4b B-3000 Leuven Belgium TRAINING & CONSULTING INTRODUCTION TO THE SELF-TEST JAVA PROGRAMMING
More informationCS211 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 informationCS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1
P a g e 1 CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 Q1 Describe some Characteristics/Advantages of Java Language? (P#12, 13, 14) 1. Java
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationObject Oriented Programming Exception Handling
Object Oriented Programming Exception Handling Budditha Hettige Department of Computer Science Programming Errors Types Syntax Errors Logical Errors Runtime Errors Syntax Errors Error in the syntax of
More informationWritten by John Bell for CS 342, Spring 2018
Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors
More informationCertified Core Java Developer VS-1036
VS-1036 1. LANGUAGE FUNDAMENTALS The Java language's programming paradigm is implementation and improvement of Object Oriented Programming (OOP) concepts. The Java language has its own rules, syntax, structure
More informationExercise: Singleton 1
Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance
More informationLanguage Features. 1. The primitive types int, double, and boolean are part of the AP
Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are
More informationSyllabus & Curriculum for Certificate Course in Java. CALL: , for Queries
1 CONTENTS 1. Introduction to Java 2. Holding Data 3. Controllin g the f l o w 4. Object Oriented Programming Concepts 5. Inheritance & Packaging 6. Handling Error/Exceptions 7. Handling Strings 8. Threads
More informationCSC207H: Software Design. Java + OOP. CSC207 Winter 2018
Java + OOP CSC207 Winter 2018 1 Why OOP? Modularity: code can be written and maintained separately, and easily passed around the system Information-hiding: internal representation hidden from the outside
More informationChapter 6 Introduction to Defining Classes
Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of
More informationAssoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Marenglen Biba Exception handling Exception an indication of a problem that occurs during a program s execution. The name exception implies that the problem occurs infrequently. With exception
More informationExample: Count of Points
Example: Count of Points 1 public class Point { 2... 3 private static int numofpoints = 0; 4 5 public Point() { 6 numofpoints++; 7 } 8 9 public Point(int x, int y) { 10 this(); // calling Line 5 11 this.x
More informationIntroduction to Programming (Java) 2/12
Introduction to Programming (Java) 2/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 informationCSC207H: Software Design. Exceptions. CSC207 Winter 2018
Exceptions CSC207 Winter 2018 1 What are exceptions? Exceptions represent exceptional conditions: unusual, strange, disturbing. These conditions deserve exceptional treatment: not the usual go-tothe-next-step,
More informationJava 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 informationExample: Count of Points
Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;
More informationCS Exam 1 Review Suggestions
CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;
More informationA Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1
A Third Look At Java Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Little Demo public class Test { public static void main(string[] args) { int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]);
More informationINDEX. 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 informationCHAPTER 1. Introduction to JAVA Programming
CHAPTER 1 Introduction to JAVA Programming What java is Java is high level You can use java to write computer applications that computes number,process words,play games,store data, etc. History of Java.
More informationTypes, Values and Variables (Chapter 4, JLS)
Lecture Notes CS 141 Winter 2005 Craig A. Rich Types, Values and Variables (Chapter 4, JLS) Primitive Types Values Representation boolean {false, true} 1-bit (possibly padded to 1 byte) Numeric Types Integral
More information