Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Control Flow: Branches GEORGIOS PORTOKALIDIS
Advertisements

Lecture 1 Introduction to Java Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Written by: Dr. JJ Shepherd
Inheritance Inheritance Reserved word protected Reserved word super
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
ITEC200 – Week03 Inheritance and Class Hierarchies.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Syntax Primitive data types Operators Control statements.
1 CMSC 132: Object-Oriented Programming II Nelson Padua-Perez William Pugh Department of Computer Science University of Maryland, College Park.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
CS102--Object Oriented Programming Review 1: Chapter 1 – Chapter 7 Copyright © 2008 Xiaoyan Li.
1 CMSC 132: Object-Oriented Programming II Java Constructs Department of Computer Science University of Maryland, College Park.
Java Course Outline Kumar Harshit, USW. Course Description Teaches students to program using the Java programming language with the help of the Netbeans.
Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide.
2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Object-Oriented Programming Concepts
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
1 Introduction Modules  Most computer programs solve much larger problem than the examples in last sessions.  The problem is more manageable and easy.
COSC1030 DATA STRUCTURES IN JAVA. Important Notes Final drop date – July 13 Web site is our information center Check web site before raising questions.
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.
Inheritance in the Java programming language J. W. Rider.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Types in programming languages1 What are types, and why do we need them?
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
1 Review of Java Basic Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – conditional statements –Flow of Control.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
By Mr. Muhammad Pervez Akhtar
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Programming Principles Operators and Expressions.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Chapter 5: Java Language Basics Java Statements –Declarations primitive types classes modifiers –Expressions operators –arithmetic, bitwise, comparison,
CSII Final Review. How many bits are in a byte? 8.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Operator Kinds of Operator Precedence of Operator Type Casting.
Information and Computer Sciences University of Hawaii, Manoa
Modern Programming Tools And Techniques-I
JAVA MULTIPLE CHOICE QUESTION.
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
University of Central Florida COP 3330 Object Oriented Programming
Selections Java.
Lecture 2: Data Types, Variables, Operators, and Expressions
University of Central Florida COP 3330 Object Oriented Programming
CS230 Tutorial Week 3.
Creating Your OwnClasses
Java operatoriai
Starting JavaProgramming
null, true, and false are also reserved.
Java Programming Language
An overview of Java, Data types and variables
Java Inheritance.
CIS 199 Final Review.
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Presentation transcript:

Java Tutorial

Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior  methods Class –an implementation of some object Interface –the contract between classes Inheritance –a way to share common aspects of objects Package –a way to organize a set things together.

Object-Oriented Programming Concepts super class (common aspects) subclass (which extends the super class to specialize) extends

Language Basics literals (constants) variables –instance, class, local, parameters –data types (primitive and objects) –assignments and comparisons operators (unary, binary, ternary) expressions –comparisons a = "hello world"; b = "hello world"; (a == b)  TRUE a.equals(b)  TRUE i1 = new Integer(1); i2 = new Integer(1); (i1 == i2)  FALSE i1.equals(i2)  TRUE statements blocks control flow –if/then, switch, while, do/while, for, –branching - break, continue, return

Operator Precedence OperatorsPrecedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift > >>> relational = instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= >= >>>=

public class Factorial { /* The lowest value we can compute factorial for */ public final long FACTORIAL_LOW_VALUE = 0; // constant/literal /* The highest value we can compute factorial for */ public final long FACTORIAL_HIGH_VALUE = 20; // constant/literal /* Error message for out of range values */ public final String INVALID_FACTORIAL_VALUE = "Error: factorial can only be computed for values between " + FACTORIAL_LOW_VALUE + " to " + FACTORIAL_HIGH_VALUE + "."; /** * …. **/ public int factorial(int x) { int factorial = 1; // local variable to this method /* * By definition factorial can only be computed * for non-negative values, hence negative * values are not allowed. */ if((x FACTORIAL_HIGH_VALUE)) { throw new IllegalArgumentException(INVALID_FACTORIAL_VALUE); }/* if */ for(int i = 1; i <= x; ++i) { factorial *= i; }/* for */ return factorial; }/* public int factorial(...) */ }/* public class Factorial */

Classes, Parameters, and Objects Classes –Constructors when they are and not provided –Override vs Overloading Methods override – replaces overloading – augments –don’t get in the habit of using: static initialization blocks unnamed initialization blocks Parameters –passed by value referenced and value type parameters Objects –declaration –instantiation –initialization

Access Levels ModifierClassPackageSubclassWorld public YYYY protected YYYN no modifierYYNN private YNNN