J A V A SHASHI BHUSHAN. MAIN ISSUES Object Oriented Concepts Examples FAQs.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Object Oriented Programming
Written by: Dr. JJ Shepherd
Object Oriented Programming in Java. Characteristics of Object Oriented Programming  Object Programming classes  Encapsulation  Polymorphism  Inheritance.
GENESIS OF JAVA & AN OVERVIEW SHASHI BHUSHAN SOCIS, IGNOU.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
Java Syntax Primitive data types Operators Control statements.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
Java Interfaces Overview Java Interfaces: A Definition.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
JAVA PROGRAMMING PART II.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
CSC3170 Introduction to Database Systems
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Computer Science [3] Java Programming II - Laboratory Course Lab 3-1: Creating and Using Interfaces Exception Faculty of Engineering & IT Software Engineering.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 21 Generics 1. Generics - Overview Generic Methods specify a set of related methods Generic classes specify a set of related types Software reuse.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
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 - Polymorphism ITI 1121 Nour El Kadri.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 CS 177 Week 3 Recitation Slides Basic Math Operations, Booleans, and Character Operations.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
1 Review of Java Basic Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – conditional statements –Flow of Control.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
CS111 Computer Programming Department of Computer Science Wellesley College Classic Recursion Examples Plus Class Methods and Applications Tuesday, October.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Converting string to integer class StringToInt { public static void main (String arg[]) { // Assume arg[0] is the input string int result = 0, pos; int.
Programming With Java ICS201 University Of Ha’il1 Chapter 11 Recursion.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
OOP Basics Classes & Methods (c) IDMS/SQL News
Object Oriented Programming Lecture 2: BallWorld.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Modern Programming Tools And Techniques-I
Sixth Lecture ArrayList Abstract Class and Interface
Interface.
Yanal Alahmad Java Workshop Yanal Alahmad
Lecture 2: Data Types, Variables, Operators, and Expressions
Multiple variables can be created in one declaration
CS 177 Week 3 Recitation Slides
Unit-2 Objects and Classes
null, true, and false are also reserved.
Interface.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Java so far Week 7.
Software Design Lecture : 12.
Scope of variables class scopeofvars {
Agenda Types and identifiers Practice Assignment Keywords in Java
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

J A V A SHASHI BHUSHAN

MAIN ISSUES Object Oriented Concepts Examples FAQs

Abstract Classes & Methods  An abstract class is a class that can only be sub-classed - it can not be instantiated.  It contains abstract methods with no implementation. Contd.

Abstract Classes & Methods  Used to create a template class or methods.  Similar to function prototypes in C or C++.

Abstract Classes & Methods abstract class GraphicsObject { int x, y; : void moveTo (int newX, int newY) { : } abstract void draw ( ) ; // to be implemented by all subclasses // } Contd.

Abstract Classes & Methods: Each non-abstract subclass of Graphic object such as circle and rectangle has to provide an implementation for the draw method. class Circle extends GraphicObject { void draw ( ) { : } Contd.

Abstract Classes & Methods: class Rectangle extends GraphicObject { void draw ( ) { : } Contd.

OOP : Interface  An interface is a collection of abstract methods (without implementations) and constant values  Interfaces add most of the functionality that is required for many applications which would normally resort to using multiple inheritance in a language such as C++. Contd. …

OOP : Interface Interfaces are useful for:  Capturing similarities between unrelated classes without forcing a class relationship.  Declaring methods that one or more classes are expected to implement.

Interfaces Do Not Provide Multiple Inheritance:  The interface hierarchy is independent of the class hierarchy – classes that implement the same interface may or may not be related through the class hierarchy. This is not true for multiple inheritance.

OOP : Interface Declaration  [Public] interface InterfaceName [extends list of SuperInterfaces]{ the interface body }

OOP : The Interface Body interface Collection { int MAXIMUM = 500; void add(Object obj); void delete(Object obj); Object find(Object obj); int currentCount( ); }

OOP : Implementing an Interface class FIFOQueue implements Collection { ……… void add(Object obj) { ……… } Contd.

OOP : Implementing an Interface void delete(Object obj) { ……… } Contd.

OOP : Implementing an Interface Object find (Object obj) { ……… } Contd.

OOP : Implementing an Interface int currentCount( ) { ……… }

Example 1 (The Math Class) Below is a small program that uses some of the Math class methods: public class MyMath { public static void main(String args[ ] ) { int x; double rand, y, z; float max; Contd.

Example 1 (The Math Class) rand = Math.random( ); x = Math.abs (-123); y = Math.round ( ); z = Math.pow (2, 4); Contd.

Example 1 (The Math Class) System.out.println(rand); System.out.println(x); System.out.println(y); System.out.println(z); System.out.println(max); } Contd.

Example 1 (The Math Class) This program produces the following output: $ java MyMath le+10

Example 2 (The Character Class) This program below uses some of the methods in the Character class: public class Mychar { public static void main (String args[ ]) { char c1 = ‘A’; char c2 = ‘z’; char c3 = ‘5’; Contd.

Example 2 (The Character Class) System.out.println(“Is character” + c1 +” uppercase?” + Character.isUpperCase(c1)); System.out.println(“Is character” + c2 +” uppercase?” + Character.isUpperCase(c2)); Contd.

Example 2 (The Character Class) System.out.println(“Is character” + c3 +” a digit? ” + Character.isDigit(c3)); System.out.println(“Convert” + c1 +” to lowerercase:” + Character.toLowerrCase(c1)); } Contd.

Example 2 (The Character Class) This program produces the following output: $ java Mychar Is character A uppercase? true Is character z uppercase? false Is character 5 a digit? true Convert A to lowercase: a

Example 3 (Using Command-Line Parameters) In this example, a program is written that will perform binary operations on integers. The program receives three parameters: an operator and two integers. For example, to add two integers, the following command could be used: java TestCommandParameters Contd.

Example 3 (Using Command-Line Parameters) This program will display the following output: = 5 Contd.

Example 3 (Using Command-Line Parameters) public class TestCommandParametrs { public static void main (String [ ] args) { int result = 0; if (args.length ! = 3) { System.out.println( “please use java operator operand1 operand2”); System.exit(0); } Contd.

Example 3 (Using Command-Line Parameters) switch (args[0].charAt(0)) { case ‘+’ : result = Integer.parseInt(args[1]) + Integer.parseInt(args[2]); break; { case ‘ - ’ : result = Integer.parseInt(args[1]) - Integer.parseInt(args[2]); break; Contd.

Example 3 (Using Command-Line Parameters) { case ‘ * ’ : result = Integer.parseInt(args[1]) * Integer.parseInt(args[2]); break; { case ‘ / ’ : result = Integer.parseInt(args[1]) / Integer.parseInt(args[2]); break; Contd.

Example 3 (Using Command-Line Parameters) System.out.println(args[1] + args[0] + args[2]+”=“ +result); }

Example 4 (Computing Fibonacci Numbers) public class TestFibonacci{ public static void main ( String args[ ] ) { int n = 5; System.out.println (“fibonacci number at index “+n” is+ fib (n)); }

Example 4 (Computing Fibonacci Numbers) public long fib (long n) { if (n == 0) || (n==1) return 1 else return fib(n-1) + fib(n-2); }

Recursive Calls fib(5) fib(4) fib(3) fib(2) fib(1) fib(2)fib(1) fib(0)fib(1)fib(0) fib(1)fib(0)

F A Q s What is the relationship between java and JavaScript? What is the difference between instance variables and methods and class variables and methods? Contd.

F A Q s Where can I learn more about java and find applets and applications to play? Contd.

F A Q s 1. obtaining source for java information for applets 3. Newsgroups *Comp.lang.java *Comp.lang.java.programme *Comp.lang.java.tech Contd.

F A Q s 1. If arrays are objects and you use new to create them and they have an instance variable length, where is the array class? Contd.

F A Q s 2.What are the differences between objects and primitive data types such as int and booleans ?