Lessons14-16

Lessons14-16 - CSE115 Course Notes Lesson 14: Basic...

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

View Full Document Right Arrow Icon
CSE115 Course Notes ©2009 C. Alphonce and A. Decker Page 39 Lesson 14: Basic Structure of a Java Source Code File The next piece of syntax we will learn about is the fundamental structure of a Java source code file. In each of the Java source code files we create, we will put the definition of exactly one class. Therefore, we will have one file for each type of object we have identified from our problem description. Since our programs will consist of many different types of objects, our programs will actually consist of many Java files, each containing one class definition. Let us now take a look at the basic structure of a class file. It consists of two elements: Package Declaration Class Definition For example, if we write the minimal definition for a class named chapter2.TopLevel, it looks like this: package chapter2; public class TopLevel { public TopLevel() { } } Let us identify these two elements in the code: package chapter2; public class TopLevel { public TopLevel() { } } The class definition is further broken down into two elements of its own: Class Header Class Body Looking at the code from above, we can identify these two elements: package declaration class definition
Background image of page 1

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

View Full DocumentRight Arrow Icon
©2009 C. Alphonce and A. Decker Page 40 package chapter2; public class TopLevel { public TopLevel() { } } Inside the class body is where we define the properties and capabilities of a class. In this example the class body consists of just one thing: public TopLevel() { } This is a constructor definition. It consists of both a (constructor) header and a (constructor) body: package chapter2; public class TopLevel { public TopLevel() { } } Many definitions in Java consist of these two basic parts: a header and a body. The header generally consists of some important bookkeeping information, such as the name of the thing being defined. Before we explore the structure of these definitions in more detail, it will be very helpful to introduce a few conventions used in describing the structure of formal languages, like Java. class body
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 note was uploaded on 02/13/2011 for the course CSE 115 taught by Professor Decker during the Fall '08 term at SUNY Buffalo.

Page1 / 6

Lessons14-16 - CSE115 Course Notes Lesson 14: Basic...

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