TCU CoSc 10403 Programming with Java

TCU CoSc 10403 Programming with Java

TCU CoSc 10403 Introduction to Programming (with Java) Getting to Know Java Problem Solving The purpose of writing a program is to solve a problem. Problem solving consists of multiple steps: Understanding the problem. Breaking the problem into manageable pieces. Designing a solution. Implementing the solution.

Testing the solution and fixing any problems that exist. The Java Programming Language A programming language defines a set of rules: That determine exactly how a programmer can combine words and symbols of the language into programming statements. Programming statements are the instructions that are carried out when the program is executed. Java is an object-oriented programming language (more about that later). Java is one of the fastest growing programming technologies of all time. Reasons Why Java is Popular Java is the first programming language to deliberately embrace the concept of writing programs that can be executed on the Web.

Moreso, Java is a useful general purpose programming language. The Java language is accompanied by a library of extra software that we can use when developing programs. The library provides the ability to create graphics, communicate over networks, and interact with databases. The set of supporting libraries is huge and versatile. Ive been telling you that Java is an Object Oriented Programming Language - what exactly does that mean? To understand - we need to discuss and understand what an Object is and how it relates to a Class!! Anatomy of a Java class A class is a description of a template (or pattern) that specifies the types of data values that an instance of the class can hold and the operations that it can perform.

In OOP, rather than describe each and every object, the programmer describes the general type of an object (a class) and then uses the class to create (or instantiate) as many of the objects as are needed. Example: a class describinggeneric students at TCU. Instance variables - the data that is maintained for students (ex., name, address, age, ) Constructors - methods that are involved in the construction of an instance of a class. Methods - subprograms that permit instance variables to be accessed and modified (ex., setName(), setMajor(), getAge(), setAge(), ) Example: consider a banking problem A class (the concept) Bank Account

An object (the realization) Johns Bank Account Balance: $5,257 Bills Bank Account Balance: $1,245,069 Multiple objects from the same class Marys Bank Account Balance: $16,833 Lets discuss these concepts further!! A class -- the basic building block of an object-oriented language.

It is a template/pattern that describes the data and behavior associated with instances of that class. When you instantiate a class you create an object that looks and feels like other instances of the same class. The data associated with a class or object is stored in instance variables; the behavior associated with a class or object is implemented with methods. Methods are similar to the functions or procedures in other procedural languages. ** Some author wrote: Julia Child's recipe for rack of lamb is a real-world example of a class. Her rendition of the rack of lamb is one instance of the recipe, and mine is quite another. (While both racks of lamb may "look and feel" the same, I imagine that they "smell and taste" different.) Constructors

A constructor: is a special method that is used to set up a newly created object often sets the initial values of variables (i.e., it can be passed information that can be used to initialize some variables in the object) has the same name as the class does not return a value has no return type, not even void The programmer does not have to define a constructor for a class (there is a default constructor for every class its syntax is: theNameOfTheclass() For example, a class named Student could have a constructor that receives a parameter specifying the Students name: Student tommy = new Student(Tom Jones);

Inheritance Classes are defined in a hierarchy A class can extend (inherit from) some other class Object => Component => Container => Panel => Applet Thus, an Applet can do everything that Panel does and some other things. A Panel can do everything a Container can do, etc Advantage Easy to extend or specialize something that already exists. Note: we take

advantage of this when we write: public class HelloWorld extends Applet { } Disadvantage Sometimes difficult to find everything that a class does; you may have to look up the tree. Inheritance One class can be used to derive another via inheritance. A class can extend (inherit from) some other class Person class (called a superclass) Subclasses or derived classes - may have more

than just 2 levels. Student class (extends Person) Faculty class(extends Person) Administrator class(extends Person) Java Components Package (what the import statement brings in!!) collection of related classes Class description of an object (template) variables + methods Variable name for memory location for a data item Method specifies an action on an object retrieve/return info or change info

Object instance of a class created by the new operator Java program = collection of cooperating objects Creating Objects jackSmith The new operator creates a new object from a class: Example: Person jackSmith = new Person (); Person sallyJones = new Person(); This declaration asserts that jackSmith and sallyJones are variables that refer to objects created

from the Person class. Instance of the Person class containing a copy of all instance variables and all methods sallyJones They are initialized (set to point) to the objects created by the new operator The newly created object is actually created and allocated to memory by a call to a very special method

contained within the class - a constructor of the class. Instance of the Person class containing a copy of all instance variables and all methods Choosing Identifier Names Identifier names should be descriptive. Avoid meaningless names such as a or x. Unless the name is actually descriptive, such as using x and y to represent (x, y) coordinates. Avoid using unnecessarily long names (unless they promote better readability - example: yearToDateSalary).

A name in Java is a series of identifiers separate by the dot (period) character. The name System.out is the name of an object through which we invoke the println method. (println is a method inside the object.)

Recently Viewed Presentations

  • Place and Health

    Place and Health

    Ecological Fallacy. The . ecological fallacy. occurs when you make conclusions about individuals based only on analyses of group data. Scale of Analysis. What is the correct level and unit of analysis? Modifiable Area Unit Problem (MAUP) Changing the level...
  • Walls, Ceilings and Floors - University of Southern Mississippi

    Walls, Ceilings and Floors - University of Southern Mississippi

    Loop Carpets Level Loop (often called a Berber) - In this style, all the loops are the same height. The dense, firm surface of a loop pile carpet makes it ideal for high-traffic areas. Patterned Loop - The yarns in...
  • Laboratory Emergency Planning, Response, and Management

    Laboratory Emergency Planning, Response, and Management

    Alert colleagues and secure area. Assess ability to clean-up spill. Find spill kit. Use appropriate PPE and sorbent material. Protect sinks and floor drains. Clean-up spill, collect/label waste for disposal. Report all spills. Centrally locate spill clean-up kits. 26
  • Enhancing Research Impact Enhancing Research Impact Programme structure:

    Enhancing Research Impact Enhancing Research Impact Programme structure:

    He is a past Chair of both the Medical Schools Council and the UK Healthcare Education Advisory Committee (UKHEAC). Sir John's clinical and research interests focus on diabetes and its vascular complications. In 2007, he received a knighthood in the...
  • The Aztecs and Incas Brenda Luchetti Debbie Bailey

    The Aztecs and Incas Brenda Luchetti Debbie Bailey

    Aztec civilization and society possessed a vibrant culture which included mandatory education and rich and complex mythological and religious traditions. For Europeans, the most striking element of the Aztec culture was the practice of human sacrifice which was conducted throughout...
  • Thick vs. Thin Questions - Mrs. Appling's Wonderful World of ...

    Thick vs. Thin Questions - Mrs. Appling's Wonderful World of ...

    "Someone's been sitting in my chair and they've broken it all to pieces," cried the Baby bear. They decided to look around some more and when they got upstairs to the bedroom, Papa bear growled, "Someone's been sleeping in my...
  • Construction by Activity

    Construction by Activity

    FY 2009 Indian Affairs' President's Budget Mary Jane Miller Director, Office of Budget Management National Budget Meeting Hilton Washington, DC
  • DC Stepper Motor - Heartland Community College

    DC Stepper Motor - Heartland Community College

    DC Stepper Motor Typical Use: Position Control Relative position (without feedback) Easy to control: # Steps moved = number of pulses in Desired Velocity Step Rate Inexpensive Good holding torque No brushes Size Range: 1.3"L 10 oz-in $12. 9"L 2000...