Java Coding style guide 1. Java. Coding Style Guide. (July 2015)

Size: px
Start display at page:

Download "Java Coding style guide 1. Java. Coding Style Guide. (July 2015)"

Transcription

1 Java Coding style guide 1 Java Coding Style Guide (July 2015) This coding style guide provides advices how to design and document your software so that your source code is easier to read, to debug, to maintain, and to port to other environments. Such rules are probably not essential for very small programs which you implement in your programming courses at the university, but are mandatory if you implement large programs in a company. Many companies have their specific coding styles so that their programs have a unique appearance on the one hand (independent of the style of a particular programmer) and can at least be partially reused in other projects in an easy way on the other hand (cost savings). Every computer scientist has to face such rules sooner or later, so that you will learn to deal with a coding style guide in my courses. My rules restrict the freedom of a programming language in a reasonable way and force not necessarily required language constructs to make your program less errorprone and easier to read. Your source code must comply with and respect all listed rules and recommendations. Your program will be marked with failed (5.0), if a significant amount of it doesn t comply with my rules.

2 Java Coding style guide 2 1) Every file starts with a header with the following structure: / Description of the content of the file and important remarks. File: <filename> Author: <name> Date: <...> Version: <version number> History: <WHO has modified / added WHAT and WHEN> Place new entries always at the top of the list before old ones. / You can omit Version and History for small programs. 2) Every Java class starts with a header which describes at least all its private and public data structures, all methods, and the purpose of the class. Each file owns at most one public class. 3) Every larger method starts with a header which describes at least its purpose, its input parameters, its return value, and all error conditions and side effects. Smaller methods (less than 10 lines of code) can be described in the header of the class. 4) Put meaningful comments into your source code which are not obvious from the source code itself, so that your program is easier to read and to understand. Examples: wrong: val = val + 1; / increment val / System.out.printf ("\n"); / print newline / useful: String hostaddr; / name or IP address / 5) Use the same language for all comments. In general, comments in English are shorter than comments in German. 6) A comment after a statement starts in column 41 and ends before column 72 (use the tabulator key!). Closing comment characters start in column 73 where necessary. All opening and closing comment characters are placed in the same column. Long comments (more than about 30 characters) are placed before the statement, are indented to the level of the statement that follows, and end before column 72. Set the tabulator to eight characters. Comments following statements on the same line can be written with / or //. All other comments will be written with /, //, or / (Javadoc comment). Remark: In general, source code is part of the documentation and will probably be printed on DIN A4 sheets of paper in Germany. A line can hold up to 75 characters, if you use 12 characters per inch (10 pt character size) and 3 cm left and 2 cm right margins. 7) All statements must end before column 72 as well. 8) Write block comments (multiline comments) in the following way: /... /... or... / / 9) Write your source code and comments at the same time. It s not allowed to write the code first without any comments and then add comments afterwards, when the program is working as expected. Usually there is no time to add comments afterwards due to new projects.

3 Java Coding style guide 3 10) Indent each new block with exactly two characters. Matching keywords and braces start in the same column. The opening brace of a new block can be placed on a new line below the first character of the above line or at the end of a line. You can choose which version suits you better, but your choice must be consistent across all of your programs All blocks must be embedded in braces, even if they contain only a single statement. Example: if (...) if (...) switch (...) statement(s); statement(s); case...: statement(s); else else break;... statement(s); for (...)... default: statement(s); statement(s); break; or (this style is better supported using indentation with Xemacs) if (...) if (...) switch (...) statement(s); statement(s); case...: else else statement(s); statement(s); for (...) break; statement(s); default: statement(s); break; 11) A method name or keyword followed by a parenthesis as well as items in a comma- or semicolon-separated list must be separated by a space character. Example: System.out.printf ("...", par1, par2,...); for (int i = 0; i <...; ++i) 12) Separate binary and ternary operators and operands with a space character. Example: x = a + b; z = ((x < y)? x : y); 13) Don t use too large statements and expressions, so that they are easy to read. 14) Structure expressions with parentheses (easier to read). The following expression while ((table[i][0]!= c) && (i < tab_len)) is easier to read than the following sufficient expression while (table[i][0]!= c && i < tab_len) or even the following necessary expression while(table[i][0]!=c&&i<tab_len). 15) Only one statement per line is permitted. 16) Avoid statements with side effects. 17) Declare variables as local as possible (modular design, information hiding). 18) Choose names carefully and explain them in a comment if necessary. A name shall point to its usage so that it is helpful in understanding the code. Structure names with the character _ or a mixture of capital and lower letters (CamelCase). Don t choose too long names,

4 Java Coding style guide 4 because they may make arithmetic expressions difficult to read. Special characters of a language, e. g., German umlauts (ä, ö, ü, ß), are prohibited (even within comments)! Example: numthreads / number of parallel threads / WAIT_TIME / waiting time before termination / 19) Class and interface names start with a capital letter and names for methods and variables with a lower letter. Names for constants contain only capital letters. The name of the class containing the method main () should end in Main (e. g., ProducerConsumerMain ). 20) Treat everything in the same way, i. e., write all comments in the same language, choose all names in the same language, and so on. 21) Avoid special solutions (use standard methods if available). 22) Try to program defensively (catch even impossible cases). Add for example a default-case to a switch-statement even if the current version of the program covers all possible cases. That way you will generally detect an error faster, if you extend your program later and forget to add a new case to the switch-statement as well. 23) Don t optimize too early! 24) Display a meaningful message (e. g., Sales (in Euro): or lower interval bound:), if your program needs input from the user. 25) Display a meaningful message which explains an error and the expected input, if you get an incorrect or erroneous user input, before you request the input once more. 26) You have to comment your source code and to provide a good documentation for it. Use a normal text editor or word processor, which is available at our university, for the documentation. 27) The documentation consists of a user manual and a software developer manual. The software developer manual can be created with Javadoc. 28) The user manual must be self-explanatory, so that you can use the program without knowledge of the other documentation or the source code. This manual completely describes the handling and operation of the program (including possible error messages). It is recommended that you add useful examples to the manual to make it understandable and easy to use. 29) The software developer manual must provide all necessary information to maintain the program (trouble-shooting and debugging, updates and enhancements, and so on) in acceptable time. You can assume that the user manual and source code are available so that you can refer to these documents. In general, the manual should cover the following topics: a) A complete description of all data structures and algorithms (variables, constants, tables, working areas, files, and so on). b) The layout of the system, e. g., a coarse flowchart, class diagrams, and so on. In general, you can learn all details directly from the source code. You can use graphical tools (e. g., UML diagrams, Nassi-Shneiderman diagrams, or flowchart diagrams) to visualize complex control structures. c) A description of the development environment: compiler version, special classes or packages, and so on. Make sure that you mention all specific features.

5 Java Coding style guide 5 30) You must show that your program solves the problem and works in an appropriate way (the compiler isn t allowed to report any warnings, even if you activate all warnings at the highest level). You must provide suitable examples (e. g., appropriate input data to show different behaviours or even errors) for the presentation of your program

6 Java Coding style guide 6 Example The following program implements algorithms to compute the greatest common divisor and the least common multiple of two natural numbers. The documentation is embedded in the files and can be generated with Javadoc. / You can automatically generate a documentation with "javadoc" if you use javadoc-style comments. The comments can contain HTML-code. <br><br> The documentation of a class, method, variable or constant (called "field" in Javadoc) must directly precede the corresponding statement. If you don't use packages you may see "<Unnamed>" in some places of the documentation. You can create a directory "doc-files" in each package directory containing images and complete HTML files. Javadoc will copy this directory with all files to the destination directory of your documentation so that you can use these files in your documentation (as you can see in the file "ComputeGcdOne.java"). Javadoc supports a lot more which you can read in the corresponding manual page or on the web.<br><br> This program determines the <b>greatest common divisor</b> (gcd) and <b>least common multiple</b> (lcm) of two natural numbers. The greatest common divisor can be determined with Euclid's algorithm. You can find a description of both algorithms on wikipedia or in the book from Knuth.<br><br> <table style="width:100%" summary=""> <tr> <td style="width:30%" align="left" valign="top"> Class file generation: </td> <td style="width:70%" align="left" valign="top"> <code>javac GcdLcmOneMain.java</code> </td> </tr> <tr> <td style="width:30%" align="left" valign="top"> Usage: </td> <td style="width:70%" align="left" valign="top"> <code>java GcdLcmOneMain</code> </td> </tr> <tr> <td style="width:30%" align="left" valign="top"> Documentation: </td> <td style="width:70%" align="left" valign="top"> <code>javadoc -d html_1 GcdLcmOneMain.java</code><br> <code>javadoc -d html_1 -author -version -private GcdLcmOneMain.java</code> </td> </tr> </table> <br>

7 Java Coding style guide <ol> <li><b>knuth, D.E.:</b> The Art of Computer Programming. Vol. 2: Seminumerical Algorithms. 2nd edition, Addison-Wesley, 1981, ISBN , pp (available: 3rd edition, 2003, ISBN ).</li> <li><b>unix / Windows:</b> javadoc -help</li> <li><b>unix:</b> man javadoc</li> <li><b>wikipedia:</b> <a href=" <a href=" <a href=" <br> S. 1.0 / / File: GcdLcmOneMain.java Date: / public class GcdLcmOneMain / Parse program parameters from the command args args[0] and args[1] should be natural numbers / public static void main (String args[]) int a, // value of 1st parameter b, // value of 2nd parameter result; // result of gcd (), lcm () ComputeGcdOne comgcd = new ComputeGcdOne (); ComputeLcmOne comlcm = new ComputeLcmOne (); a = 0; b = 0; // parse command line switch (args.length) case 2: // both numbers are available try a = Integer.parseInt (args[0]); catch (NumberFormatException e) System.err.println ("Input parameter error"); System.err.println (" \"" + args[0] + "\"" + " isn't an " + "integer value."); System.exit (0);

8 Java Coding style guide 8 try b = Integer.parseInt (args[1]); catch (NumberFormatException e) System.err.println ("Input parameter error"); System.err.println (" \"" + args[1] + "\"" + " isn't an " + "integer value."); System.exit (0); break; default: System.out.println ("I'm computing the greatest common " + "divisor and least common multiple"); System.out.println ("of two integer values."); System.out.println (" Usage: java GcdLcmMain " + "<1st number> <2nd number>"); System.exit (0); // check parameters if (a < 0) System.out.println ("Input parameter error"); System.out.println (" 1st number isn't positive. I use its " + "absolute value."); a = Math.abs (a); if (b < 0) System.out.println ("Input parameter error"); System.out.println (" 2nd number isn't positive. I use its " + "absolute value."); b = Math.abs (b); // compute greatest common divisor result = comgcd.gcd (a, b); System.out.println ("a: " + a + " b: " + b + " gcd (a, b): " + result); // compute least common multiple result = comlcm.lcm (a, b); System.out.println ("a: " + a + " b: " + b + " lcm (a, b): " + result);

9 Java Coding style guide 9 / Determine the <b>greatest common divisor</b> (gcd) of two natural numbers. The greatest common divisor can be determined with Euclid's algorithm. You can find a description of the algorithms on wikipedia or in the book from Knuth.<br><br> This algorithm uses an iterative solution.<br><br>... / / File: ComputeGcdOne.java / public class ComputeGcdOne / temporary value for swap operations or intermediate results / private int tmp; / This version of Euclid's algorithm uses a modulo operation. The original algorithm uses only subtractions and is less efficient. <br><br> <img src="doc-files/gcd.gif" a the first number for the greatest common b the second number for the greatest common the greatest common divisor / int gcd (int a, int b) while (b!= 0) tmp = a % b; a = b; b = tmp; return a; /... This algorithm uses a recursive solution.<br><br>... / / File: ComputeGcdRecursiveOne.java / public class ComputeGcdRecursiveOne /... / int gcd (int a, int b) if (b == 0) return a; else return gcd (b, a % b);

10 Java Coding style guide 10 / Determine the <b>least common multiple</b> (lcm) of two natural numbers. You can find a description of the algorithm on wikipedia or in the book from Knuth.<br><br>... / / File: ComputeLcmOne.java / public class ComputeLcmOne / Determine the smallest natural number which is a multiple of both parameters. You have used this technique already in school when you had to add fractions determining the least common denominator of both a the first number for the least common b the second number for the least common the least common multiple / int lcm (int a, int b) int gcd = (new ComputeGcdRecursiveOne ()).gcd (a, b); if (gcd!= 0) return Math.abs ((a b) / gcd); else return a b; You can define your own tags to make your comments more readable. package javadocexample; /... This version uses packages and self-defined tags. "javadoc" didn't work as expected when the self-defined tags were only defined in the argument <code>cd <package directory><br> javac <code>cd <package directory><br> java <code>cd <package directory><br> javadoc -tag mytag.compiling:pt:"class file generation:" -tag mytag.running:pt:"usage:" -tag mytag.documentation:pt:"documentation:" -tag mytag.todo:a:"to Do:" \@javadocexample/doc_cmds</code>... / / File: GcdLcmTwoMain.java /...

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

Chapter 2 Author Notes

Chapter 2 Author Notes Chapter 2 Author Notes Good Programming Practice 2.1 Every program should begin with a comment that explains the purpose of the program, the author and the date and time the program was last modified.

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

More information

COMP 202 Java in one week

COMP 202 Java in one week COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

4 Programming Fundamentals. Introduction to Programming 1 1

4 Programming Fundamentals. Introduction to Programming 1 1 4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,

More information

CSE 11 Style Guidelines

CSE 11 Style Guidelines CSE 11 Style Guidelines These style guidelines are based off of Google s Java Style Guide and Oracle s Javadoc Guide. Overview: Your style will be graded on the following items: File Headers Class Headers

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

Coding Standards for Java

Coding Standards for Java Why have coding standards? Coding Standards for Java Version 1.3 It is a known fact that 80% of the lifetime cost of a piece of software goes to maintenance; therefore, it makes sense for all programs

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead. Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public

More information

User Interface Programming OOP/Java Primer. Step 3 - documentation

User Interface Programming OOP/Java Primer. Step 3 - documentation User Interface Programming OOP/Java Primer Step 3 - documentation Department of Information Technology Uppsala University What is the documentation? Documentation about program in the program Clearly written

More information

Programming with Java

Programming with Java Programming with Java Variables and Output Statement Lecture 03 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives ü Declare and assign values to variable ü How to use eclipse ü What

More information

2.8. Decision Making: Equality and Relational Operators

2.8. Decision Making: Equality and Relational Operators Page 1 of 6 [Page 56] 2.8. Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. This section introduces a simple version of Java's if statement

More information

Compilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors

Compilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors First Program Compilation and Execution Simplifying Fractions Loops If Statements Variables Operations Using Functions Errors C++ programs consist of a series of instructions written in using the C++ syntax

More information

CSE 142 Su 04 Computer Programming 1 - Java. Objects

CSE 142 Su 04 Computer Programming 1 - Java. Objects Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

A variable is a name that represents a value. For

A variable is a name that represents a value. For DECLARE A VARIABLE A variable is a name that represents a value. For example, you could have the variable myage represent the value 29. Variables can be used to perform many types of calculations. Before

More information

Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

More information

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M tutor Isam M. Al Jawarneh, PhD student isam.aljawarneh3@unibo.it Mobile Middleware

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

CS 251 Intermediate Programming Coding Standards

CS 251 Intermediate Programming Coding Standards CS 251 Intermediate Programming Coding Standards Brooke Chenoweth University of New Mexico Fall 2018 CS-251 Coding Standards All projects and labs must follow the great and hallowed CS-251 coding standards.

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Documentation Requirements Computer Science 2334 Spring 2016

Documentation Requirements Computer Science 2334 Spring 2016 Overview: Documentation Requirements Computer Science 2334 Spring 2016 These requirements are based on official Java coding conventions but have been adapted to be more appropriate to an academic environment.

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData

QueueBlock, ReversalADT, LinkedList,CustomerAccount, not MaintainCustomerData Naming Conventions Rules Classes Use nouns Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML) Begin with upper case

More information

Introduction to Java Applications

Introduction to Java Applications 2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

CS 351 Design of Large Programs Coding Standards

CS 351 Design of Large Programs Coding Standards CS 351 Design of Large Programs Coding Standards Brooke Chenoweth University of New Mexico Spring 2018 CS-351 Coding Standards All projects and labs must follow the great and hallowed CS-351 coding standards.

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi... Contents 1 Introduction 3 1.1 Java, the beginning.......................... 3 1.2 Java Virtual Machine........................ 4 1.3 A First Program........................... 4 1.4 BlueJ.................................

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Supplement D: Expanded Guidelines on Programming Style and Documentation

Supplement D: Expanded Guidelines on Programming Style and Documentation Page 1 of 5 Introduction Supplement D: Expanded Guidelines on Programming Style and Documentation For Introduction to Java Programming Y. Daniel Liang mailto:liang@armstrong.edu Programming style deals

More information

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

More information

Topics. Chapter 5. Equality Operators

Topics. Chapter 5. Equality Operators Topics Chapter 5 Flow of Control Part 1: Selection Forming Conditions if/ Statements Comparing Floating-Point Numbers Comparing Objects The equals Method String Comparison Methods The Conditional Operator

More information

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards

11 Coding Standards CERTIFICATION OBJECTIVES. Use Sun Java Coding Standards 11 Coding Standards CERTIFICATION OBJECTIVES Use Sun Java Coding Standards 2 Chapter 11: Coding Standards CERTIFICATION OBJECTIVE Use Sun Java Coding Standards Spacing Standards The Developer exam is challenging.

More information

Expanded Guidelines on Programming Style and Documentation

Expanded Guidelines on Programming Style and Documentation Page 1 of 5 Expanded Guidelines on Programming Style and Documentation Introduction Introduction to Java Programming, 5E Y. Daniel Liang liang@armstrong.edu Programming style deals with the appearance

More information

1007 Imperative Programming Part II

1007 Imperative Programming Part II Agenda 1007 Imperative Programming Part II We ve seen the basic ideas of sequence, iteration and selection. Now let s look at what else we need to start writing useful programs. Details now start to be

More information

Chapter 2: Programming Concepts

Chapter 2: Programming Concepts Chapter 2: Programming Concepts Objectives Students should Know the steps required to create programs using a programming language and related terminology. Be familiar with the basic structure of a Java

More information

Java Programming Style Guide

Java Programming Style Guide Java Programming Style Guide Computer Science Program Cedarville University Goal: Our goal is to produce well-written code that can be easily understood and will facilitate life-cycle maintenance. These

More information

Section 2.2 Your First Program in Java: Printing a Line of Text

Section 2.2 Your First Program in Java: Printing a Line of Text Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday

More information

CS 302: Introduction to Programming

CS 302: Introduction to Programming CS 302: Introduction to Programming Lectures 2-3 CS302 Summer 2012 1 Review What is a computer? What is a computer program? Why do we have high-level programming languages? How does a high-level program

More information

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be

More information

Chapter 2. C++ Basics

Chapter 2. C++ Basics Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online

More information

Professor Peter Cheung EEE, Imperial College

Professor Peter Cheung EEE, Imperial College 1/1 1/2 Professor Peter Cheung EEE, Imperial College In this lecture, we take an overview of the course, and briefly review the programming language. The rough guide is not very complete. You should use

More information

1.00 Lecture 4. Promotion

1.00 Lecture 4. Promotion 1.00 Lecture 4 Data Types, Operators Reading for next time: Big Java: sections 6.1-6.4 Promotion increasing capacity Data Type Allowed Promotions double None float double long float,double int long,float,double

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Introduction to C Programming

Introduction to C Programming 1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

TACi: Three-Address Code Interpreter (version 1.0)

TACi: Three-Address Code Interpreter (version 1.0) TACi: Three-Address Code Interpreter (version 1.0) David Sinclair September 23, 2018 1 Introduction TACi is an interpreter for Three-Address Code, the common intermediate representation (IR) used in compilers.

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

Math Modeling in Java: An S-I Compartment Model

Math Modeling in Java: An S-I Compartment Model 1 Math Modeling in Java: An S-I Compartment Model Basic Concepts What is a compartment model? A compartment model is one in which a population is modeled by treating its members as if they are separated

More information

Java Style Guide. 1.0 General. 2.0 Visual Layout. Dr Caffeine

Java Style Guide. 1.0 General. 2.0 Visual Layout. Dr Caffeine September 25, 2002 Java Style Guide Dr Caffeine This document defines the style convention the students must follow in submitting their programs. This document is a modified version of the document originally

More information

3chapter C ONTROL S TATEMENTS. Objectives

3chapter C ONTROL S TATEMENTS. Objectives 3chapter C ONTROL S TATEMENTS Objectives To understand the flow of control in selection and loop statements ( 3.2 3.7). To use Boolean expressions to control selection statements and loop statements (

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Scientific Computing

Scientific Computing Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course

More information

More Control Structures

More Control Structures Chapter 8 More Control Structures 1 8.1 Exceptions When a Java program performs an illegal operation, an exception happens. If a program has no special provisions for dealing with exceptions, it will behave

More information

Introduction to Java Applications; Input/Output and Operators

Introduction to Java Applications; Input/Output and Operators www.thestudycampus.com Introduction to Java Applications; Input/Output and Operators 2.1 Introduction 2.2 Your First Program in Java: Printing a Line of Text 2.3 Modifying Your First Java Program 2.4 Displaying

More information

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is

More information

UEE1302 (1102) F10: Introduction to Computers and Programming

UEE1302 (1102) F10: Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,

More information

Write for your audience

Write for your audience Comments Write for your audience Program documentation is for programmers, not end users There are two groups of programmers, and they need different kinds of documentation Some programmers need to use

More information

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Copyright 2011 Pearson Addison-Wesley. All rights

More information

EE 382 Style Guide. March 2, 2018

EE 382 Style Guide. March 2, 2018 EE 382 Style Guide March 2, 2018 This is a short document describing the coding style for this class. All code written in this class is assumed to follow this coding style. 1 Indentation Indentations should

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

More information

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved. Chapter 4: Expressions Chapter 4 Expressions 1 Chapter 4: Expressions Operators Expressions are built from variables, constants, and operators. C has a rich collection of operators, including arithmetic

More information

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD CMSC 150 INTRODUCTION TO COMPUTING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH INTRODUCTION TO JAVA PROGRAMMING, LIANG (PEARSON 2014) LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE

More information

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5. Page 1 of 5 6.170 Laboratory in Software Engineering Java Style Guide Contents: Overview Descriptive names Consistent indentation and spacing Informative comments Commenting code TODO comments 6.170 Javadocs

More information

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with Project 1 and Java Intro Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The University of Texas at Arlington, Arlington, TX 76019 Email: sharma@cse.uta.edu

More information

Exam 2, Version 2. For the following code, mark True or False for statements 1.8 to 1.10.

Exam 2, Version 2. For the following code, mark True or False for statements 1.8 to 1.10. 1. True or False (clearly write True or False on each line). 1.1. It s possible for the body of a do-while loop to execute zero times F For the following code, mark True or False for statements 1.8 to

More information

CS 302: INTRODUCTION TO PROGRAMMING IN JAVA. Chapter 5: Methods. Lecture 10

CS 302: INTRODUCTION TO PROGRAMMING IN JAVA. Chapter 5: Methods. Lecture 10 CS 302: INTRODUCTION TO PROGRAMMING IN JAVA Chapter 5: Methods Lecture 10 1 PROBLEM What if I was using a lot of different arrays and often wanted to print out their contents? I would have to have that

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in: CS 215 Fundamentals of Programming II C++ Programming Style Guideline Most of a programmer's efforts are aimed at the development of correct and efficient programs. But the readability of programs is also

More information

CSE 142/143 Unofficial Style Guide

CSE 142/143 Unofficial Style Guide CSE 142/143 Unofficial Style Guide Below, things in GREEN are GOOD; things in RED are to be AVOIDED. Commenting Comment well. Follow the commenting rules for header, method, field, and inside-method comments

More information

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Course PJL. Arithmetic Operations

Course PJL. Arithmetic Operations Outline Oman College of Management and Technology Course 503200 PJL Handout 5 Arithmetic Operations CS/MIS Department 1 // Fig. 2.9: Addition.java 2 // Addition program that displays the sum of two numbers.

More information

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Lab # 2. For today s lab:

Lab # 2. For today s lab: 1 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot 1 For today s lab: Go the course webpage Follow the links to the lab notes for Lab 2. Save all the java programs you

More information

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.

More information

Section 2: Introduction to Java. Historical note

Section 2: Introduction to Java. Historical note The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence

More information

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010 IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

More information

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

Section 1. How to use Brackets to develop JavaScript applications

Section 1. How to use Brackets to develop JavaScript applications Section 1 How to use Brackets to develop JavaScript applications This document is a free download from Murach books. It is especially designed for people who are using Murach s JavaScript and jquery, because

More information

CIS133J. Working with Numbers in Java

CIS133J. Working with Numbers in Java CIS133J Working with Numbers in Java Contents: Using variables with integral numbers Using variables with floating point numbers How to declare integral variables How to declare floating point variables

More information

Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

More information

Technical Section. Lab 4 while loops and for loops. A. while Loops or for loops

Technical Section. Lab 4 while loops and for loops. A. while Loops or for loops Lab 4 while loops and for loops The purpose of this lab is to introduce you to the concept of a for loop, gain experience distinguishing between a while loop (which is a more general type of loop than

More information

Introduction to Programming (Java) 4/12

Introduction to Programming (Java) 4/12 Introduction to Programming (Java) 4/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information