This document provides an overview of object-oriented programming concepts in Java including classes, objects, methods, and variables. It explains that classes are templates that define fields and methods, while objects are instances of classes that contain data and behaviors. Methods are pieces of code that can be called to perform functions, accept parameters, and return values. The document differentiates between instance variables/methods that belong to objects and class (static) variables/methods that belong to the entire class. It also covers creating objects using the new operator and invoking constructors, as well as decomposing problems into methods to solve them.
This document provides an overview of object-oriented programming concepts in Java including classes, objects, methods, and variables. It explains that classes are templates that define fields and methods, while objects are instances of classes that contain data and behaviors. Methods are pieces of code that can be called to perform functions, accept parameters, and return values. The document differentiates between instance variables/methods that belong to objects and class (static) variables/methods that belong to the entire class. It also covers creating objects using the new operator and invoking constructors, as well as decomposing problems into methods to solve them.
This document provides an overview of object-oriented programming concepts in Java including classes, objects, methods, and variables. It explains that classes are templates that define fields and methods, while objects are instances of classes that contain data and behaviors. Methods are pieces of code that can be called to perform functions, accept parameters, and return values. The document differentiates between instance variables/methods that belong to objects and class (static) variables/methods that belong to the entire class. It also covers creating objects using the new operator and invoking constructors, as well as decomposing problems into methods to solve them.
Objectives: Explain object-oriented programming and some of its concepts Diferentiate between classes and objects Diferentiate between instance variables/methods and class (static) variables/methods Explain what methods are and how to call and pass parameters to methods Identif the scope of a variable !ast primitive data tpes and objects !ompare objects and determine the class of an objects Object-Oriented programming or OOP " #evolves aro$nd the concept of objects as the basic elements of o$r programs% " &hese objects are characteri'ed b their properties and behaviors% Example of objects Objects in the phsical world can easil be modeled as software objects $sing the properties as data and the behaviors as methods Classes and Objects Class " can be tho$ght of as a template( a prototpe or a bl$eprint of an object " is the f$ndamental str$ct$re in object-oriented programming Two types of class members: Fields (properties or attributes) " specif the data tpes de)ned b the class Metods! " specif the operations Object " is composed of a set of data (properties) which are variables describing the essential characteristics of the object( and consists of a set of methods (behavior) that describes how an object behaves% " *n object is an instance of a class% To diferentiate between classes and objects !lasses provide the bene)t of re$sabilit% + " C # 2 $ 2 % C & Computer Programming 2 , e r c i v a l * % - e r n a n d e ' .oftware programmers can $se a class over and over again to create man objects Class 'ariables Classes consist of Instance variables Instance methods !lass /ariables (static member variables) " variables that belong to the whole class% " &his means that the have the same val$e for all the objects in the same class% Class (nstantiation &o create an object or an instance of a class( we $se the new operator% -or example( if o$ want to create an instance of the class .tring( we write the following code( String str2 = new String(Hello world!); or also e0$ivalent to( String str2 = "Hello"; Class (nstantiation &he new operator " allocates a memor for that object and ret$rns a reference of that memor location to o$% " 1hen o$ create an object( o$ act$all invo2e the class3 constr$ctor% &he constr$ctor " is a method where o$ place all the initiali'ations( it has the same name as the class% Metods 4ethod " is a separate piece of code that can be called b a main program or an other method to perform some speci)c f$nction% &he following are characteristics of methods5 " It can ret$rn one or no val$es " It ma accept as man parameters it needs or no parameter at all% " ,arameters are also called arg$ments% " *fter the method has )nished exec$tion( it goes bac2 to the method that called it% )y *se Metods+ &he heart of efective problem solving is in problem decomposition% 1e can do this in 6ava b creating methods to solve a speci)c part of the problem% &a2ing a problem and brea2ing it into small( manageable pieces is critical to writing large programs% 7 " C # 2 $ 2 % C & Computer Programming 2 , e r c i v a l * % - e r n a n d e '