Java1 - COP 3503 Computer Science II Java Notes#1 Introduction To Java Introduction Whenever you begin to learn a new programming language the

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction Whenever you begin to learn a new programming language the first program that you should write in the new language is the classic “Hello world” program. This program is shown below. Enter this program and execute it before you attempt to do any other Java program. This very simple program will allow you to use the text editor to enter the program, compile and execute your program. The Class The class is the foundation of the Java language. The class defines the nature of an object . As such, the class forms the basis for object-oriented programming in Java. Within a class are defined data and code that acts upon that data. The code is contained in methods . Classes, objects, and methods are fundamental to Java. All Java program activity occurs within a class. A class is a template (prototype, blueprint, etc.) that defines the form of an object. It specifies both the data and the code that will operate on that data. Java uses a class specification to construct objects. Objects are instances of a class. Thus, a class is essentially a set of plans that specify how to build an object. The process of creating or building an instance of a class is called instantiation. An object has no physical representation in memory until it has been instantiated. Just like an architect’s blueprint for a house, until a house is built according to the blueprint, it doesn’t exist. The methods and variables that constitute a class are called members of the class. The data members are also referred to as instance variables . When COP 3503 – Java Notes #1 - 1 COP 3503 – Computer Science II – Java Notes #1 Introduction To Java /* This is a simple Java program called the “Hello World” program. Name the text file in which you store this code: Example.java */ class Example { //A Java program begins with a call to main( ). public static void main (String args[]) { System.out.println(“Hello World!”); }// end main }//end class Example
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
you define a class, you are declaring its exact form and nature. You do this by specifying the instance variables that it contains and the methods that operate on those instance variables. A class in Java is created using the following class definition form: Class declaration in Java Although there are no syntactic rules that enforce it, a well-designed class should define one and only one logical entity. For example, a class which stores student names and telephone numbers would not normally also store the average amount of rainfall in Orlando. A well-designed class groups logically connected information. Putting unrelated information into the same class will very quickly destructure your program. Notice that the general form of a class does not specify a main( ) method. A main( ) method is required only if that class is the starting point for your program. (Also, applets don’t require a main( ).) To illustrate the concept of a class, we’ll develop a class the encapsulates information about vehicles, such as cars, vans, and trucks. We’ll call this class
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 13

Java1 - COP 3503 Computer Science II Java Notes#1 Introduction To Java Introduction Whenever you begin to learn a new programming language the

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online