JAVA An Introduction to Java OOP Basics

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
1 Classes and Objects Overview l Classes and Objects l Constructors l Implicit Constructors l Overloading methods this keyword l public, private and protected.
Saravanan.G.
UML Basics & Access Modifier
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Announcements Final Exam:TBD. public static void main(String [] args) { final int ASIZE = 5; int [] intArray= new int[ASIZE]; for(int i = 0; i < ASIZE;
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
CS305j Introduction to Computing Classes II 1 Topic 24 Classes Part II "Object-oriented programming as it emerged in Simula 67 allows software structure.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Object Oriented Programming I ( ) Dr. Adel hamdan Part 03 (Week 4) Dr. Adel Hamdan Date Created: 7/10/2011.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Classes and Objects The main advantage of OOP is that you can “grow” the language add our own classes and their behavior how they function, what they can.
Lecture 3: Introduction to Object and Classes
Chapter 15 Abstract Classes and Interfaces
Objects as a programming concept
Today’s topic: Arithmetic expressions.
Java: Base Types All information has a type or class designation
Java’s World in UML Object Shape {abstract} This is done implicitly
CS Week 13 Jim Williams, PhD.
CS 200 Creating Classes Jim Williams, PhD.
CS 302 Week 10 Jim Williams.
EE422C - Software Design and Implementation II
Instance Method Review - CIS 1068 Program Design and Abstraction
CMSC 202 Static Methods.
Can perform actions and provide communication
Initializing Arrays char [] cArray3 = {'a', 'b', 'c'};
Can perform actions and provide communication
null, true, and false are also reserved.
An Introduction to Java – Part II
Chapter 10 Thinking in Objects
An Introduction to Java – Part I, language basics
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Classes and Objects 5th Lecture
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Chapter 9 Objects and Classes
Objects with Functions and Arrays
Can perform actions and provide communication
Arrays of Objects // The following does NOT create memory for
Objects and Classes Creating Objects and Object Reference Variables
OBJECT ORIENTED PROGRAMMING II LECTURE 13_2 GEORGE KOUTSOGIANNAKIS
Introduction to Objects & Classes
Java Basics II Minseok Kwon
Object-Oriented Programming and class Design
Classes and Objects Static Methods
Kinds of methods accessor: A method that lets clients examine object state. Examples: distance, distanceFromOrigin often has a non-void return type mutator: A.
Chapter 6 Objects and Classes
CIS 199 Final Review.
CSS161: Fundamentals of Computing
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
Chapter 11 Inheritance and Polymorphism
CS 200 Creating Classes Jim Williams, PhD.
Chapter 9 Objects and Classes
Object-Oriented Programming and class Design
OO Programming Concepts
CS 200 Creating Classes Jim Williams, PhD.
Chapter 9 Objects and Classes
Introduction to java Part I By Shenglan Zhang.
Chapter 7 Objects and Classes
Chengyu Sun California State University, Los Angeles
Object-Oriented Design AND CLASS PROPERTIES
Presentation transcript:

JAVA An Introduction to Java OOP Basics Mudassir Hasan

Data Types & Operators Data Types: byte, short, int, long, float, double, long , boolean, char Operators: - Arithmetic: +,-,*,/, % ( modulus-remainder ) - Relational: <, >, <=, >=, ==, != - Logical: &&, ||, !

Strings public class LearnJava { public static void main( String [] args ) { String fun = “Java is fun”; System.out.println(fun); } }

Strings (cont’d.) Date columbusDay = new Date(10, 12, 2009); System.out.println(“Columbus day was on “ + columbusDay.getDay() ); Columbus day was on 12 Stores values for columbusDay. int age = 20; // String Concatenation String youth = "He is " + age + " years old."; System.out.println(youth); He is 20 years old.

Modifiers Access Modifiers: Public – access methods of the same class and of other classes Private – access methods of the same class only Protected – access methods in the same class and also in subclasses

Constructors Initializes the fields of the new object It is called when an object is instantiated using the new keyword For example: Auto suv = new Auto( );

Constructors Default Constructor public class Auto { private int drivenMiles; private int modelYear; public Auto ( ) // same name as the class // no parameters passed, auto initialized drivenMiles to 0. modelYear = 2009; }

Constructors (cont’d.) Overloaded Constructors public Auto(int adriven Miles, int amodelYear ) // passes parameter, allows user to set their own values

Class Methods Accessor Methods, also called get Methods Get radius public int getRadius( ) { return radius; }

Class Methods Mutator Methods, also called set Methods Allows the user to set its own values in the client class public Class public void setRadius( int newRadius ) { radius = newRadius; } Client Class Circle circ = new Circle( 4 );

Arrays public class ArrayElements { public static void main(String [] args) double cells = new double [3] cells[0] = 1; cells[1] = 2; cells[2] = 3; } First index is 0. Last index is [array.length – 1]

Swapping Array int temp = array[2]; array[2] = array[4]; array[4] = temp; Value 23 45 7 33 78 Index 1 2 3 4 5

Class public class Circle { private int point; private int radius; public Circle( int newPoint, int newRadius ) { point = newPoint; radius = newRadius; } public int getLocation() { return point; } public void setLocation( int newPoint) { point = newPoint; }

Class (cont’d.) public int getRadius() { return radius; } public void setRadius( int newRadius ) { radius = newRadius; } public double getPerimeter() { return 2 * Math.PI * radius; } public double getArea() { return Math.PI * radius * radius; } public String toString() { return "The point is " + point + "\nThe radius is " + radius + "\nPerimeter of the circle is " + getPerimeter() + "\nArea of the circle is " + getArea();

Client Class public class ClientCircle { public static void main( String [] args ) { Circle circ = new Circle( 4, 5 ); System.out.println( circ.toString() ); } } The point is 4 The radius is 5 Perimeter of the circle is 31.41592653589793 Area of the circle is 78.53981633974483

Bibliography Anderson, Julie and Franceschi, Herve. Java Illuminated.