Java Program Coding Standards 4002-217-9 Programming for Information Technology



Similar documents
Moving from CS 61A Scheme to CS 61B Java

Creating a Simple, Multithreaded Chat System with Java

Install Java Development Kit (JDK) 1.8

Lecture 5: Java Fundamentals III

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Programming Languages CIS 443

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

The C Programming Language course syllabus associate level

Example of a Java program

Java CPD (I) Frans Coenen Department of Computer Science

Some Scanner Class Methods

AppendixA1A1. Java Language Coding Guidelines. A1.1 Introduction

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

CSE 308. Coding Conventions. Reference

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Object Oriented Software Design

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Object Oriented Software Design

Introduction to Java

Object-Oriented Programming in Java

Chapter 5. Recursion. Data Structures and Algorithms in Java

AP Computer Science Java Subset

Official Android Coding Style Conventions

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Java Crash Course Part I

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Sample CSE8A midterm Multiple Choice (circle one)

Computer Programming I & II*

Java Classes. GEEN163 Introduction to Computer Programming

Computer Programming I

Figure 1: Graphical example of a mergesort 1.

Sources: On the Web: Slides will be available on:

CS 106 Introduction to Computer Science I

Chapter 2 Introduction to Java programming

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur

Exception Handling In Web Development DevelopIntelligence LLC

PL / SQL Basics. Chapter 3

ProfBuilder: A Package for Rapidly Building Java Execution Profilers Brian F. Cooper, Han B. Lee, and Benjamin G. Zorn

LAB4 Making Classes and Objects

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Introduction to Programming System Design. CSCI 455x (4 Units)

Taxi Service Coding Policy. Version 1.2

ECE 341 Coding Standard

Hypercosm. Studio.

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 111 Classes I 1. Software Organization View to this point:

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Pseudo code Tutorial and Exercises Teacher s Version

13 File Output and Input

Curriculum Map. Discipline: Computer Science Course: C++

Computer Programming I

CS170 Lab 11 Abstract Data Types & Objects

Chapter 5 Names, Bindings, Type Checking, and Scopes

LINKED DATA STRUCTURES

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Iteration CHAPTER 6. Topic Summary

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

Python Loops and String Manipulation

An Incomplete C++ Primer. University of Wyoming MA 5310

10 Java API, Exceptions, and Collections

Introduction to Object-Oriented Programming

Computing Concepts with Java Essentials

An Overview of Java. overview-1

LOOPS CHAPTER CHAPTER GOALS

Homework/Program #5 Solutions

General Software Development Standards and Guidelines Version 3.5

CS 241 Data Organization Coding Standards

Explain the relationship between a class and an object. Which is general and which is specific?

C Compiler Targeting the Java Virtual Machine

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

CSC230 Getting Starting in C. Tyler Bletsch

Creating a Java application using Perfect Developer and the Java Develo...

1001ICT Introduction To Programming Lecture Notes

Introduction to programming

6.1. Example: A Tip Calculator 6-1

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Introduction to Programming

Dinopolis Java Coding Convention

Javadoc like technical documentation for CAPRI

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Java Interview Questions and Answers

Java Programming Fundamentals

Glossary of Object Oriented Terms

10CS35: Data Structures Using C

JavaScript: Control Statements I

Creating a 2D Game Engine for Android OS. Introduction

Week 2 Practical Objects and Turtles

Transcription:

Java Program Coding Standards 4002-217-9 Programming for Information Technology Coding Standards: You are expected to follow the standards listed in this document when producing code for this class. Whether you agree with the use of standards or not, most companies are starting to apply them, so you might as well get used to dealing with them. Naming Conventions: 1. Names used for classes, methods and variables are expected to be meaningful. 2. Do not use names that differ only in case. (Example: SQLStatement vs. SqlStatement) 3. We are following the Sun naming conventions used in their Java development: Class names are always capitalized. (Example: public class Ticket ) Method names always are lowercase for the first word, but all other words are capitalized. (Example: mortgageescrowcalculation() would be a valid method name.) Underscores are not used to separate words in a name. (Exception: constant names) Only the first character of an embedded acronym is capitalized. (Example: selectsqlstatement) Exception: when the acronym is the first word in a name, it s all lowercase. (Example: xmldata) Constant names should be all uppercase. Constant names are the only place in Java where underscores are used as part of the name. (Example: static final float MINIMUM_RADIUS = 6.7f;) 1

Names for exceptions should have each word capitalized. The exception name must end with the word Exception. (Example: InvalidDataException) Comments: 1. You are expected to comment your code. Some percentage of each project s grade will be based on the documentation provided. 2. Each file should have a header associated with it. This header will contain the following information: (1) Author and course section, (2) Purpose of the file, (3) Caveats: any restrictions on the classes use or known errors. The name of the author and the course section should appear as the first item in the header. (Exception: It is not necessary to put a class header with an inner class. However, there should be a comment about the purpose of the inner class, unless it s blindingly obvious.) 3. Each class should have a header associated with it. This header should describe the purpose of the class. The header should appear ahead of the class definition. 4. If command line arguments are used, this information should appear in a comment that appears ahead of the main method in the class. 5. Sections of code where you are doing something clever, unusual, or where you are making use of some obscure feature need to be commented. 6. Don t comment the obvious. (Example: j++; // increment j ) Miscellaneous: 1. Use indentation to indicate the scope of methods and various control structure, like loops, and if statements. 2. I expect that any work submitted for grading has been tested fully. You will lose a significant number of points if your program fails to compile or fails with a stack trace during a run. 3. You are expected to use the SDK1.4.1 and an editor as your development environment. 2

4. Labs are required to be individual projects. Group efforts are absolutely forbidden. 5. The book The Elements of Java Style by Allan Vermeulen, et al. Cambridge Press 2000, has a very good discussion of coding and documentation standards. It s only 128 pages long and gives different rules along with examples. 3

Coding Example: This program shows the way code should be written for this course: // Author: A.T. Hun 4002-217-03 // Date: June 24, 2001 // Description: This program accepts one number as a command line argument and prints // the Fibinocci sequence that contains the requested number of elements. // // Caveats: Invalid values will be ignored. (i.e. negative numbers or text strings.) // The program will not accept a value greater then 45. // If more than 1 argument is entered, all arguments after the first are ignored // This class generates a Fibinocci sequence with the requested number of terms class FibSequence { private int maxiterations; // Constructor public FibSequence(String arg){ // convert the value from a String to a number if possible int iterations = 0; try { Integer argvalue = new Integer(arg); iterations = argvalue.intvalue(); catch(numberformatexception nfe) { // not a number - exit System.exit(2); Header comments expected for each class // see if the number is <= 45 and > 0 - exit otherwise if(iterations > 45 iterations <= 0) { System.exit(3); maxiterations = iterations; // This method is called recursively to calculate // and print out the Fibonacci sequence public void calc(int firstvalue, int secondvalue, int counter) { if(counter > maxiterations) return; // end of recursion // calculate and print the next term in sequence int nextterm = firstvalue + secondvalue; System.out.println(nextTerm); Method comments expected for each method in the class // call fibo to get next term counter++; calc(secondvalue, nextterm, counter); 4

// This class tests the Sequence class by accepting a command line argument of the // number of terms from the sequence and then calls the calc method of the Sequence class to // generate the required list of terms. public class SequenceTest { // Command line usage: java SequenceTest numberofelements // Example: java SequenceTest 12 public static void main(string[] args) { // test for at least 1 argument entered if(args.length <= 0) { // no arguments entered - exit System.exit(1); // create the sequence object and initialize FibSequence seq = new FibSequence(args[0]); // call the recursive routine to calculate the values and // print them out System.out.println("1\n1"); // print first two terms int count = 3; // first two terms are fixed seq.calc(1,1,count); 5