Intro to CS – Honors I Documentation and Coding Style GEORGIOS PORTOKALIDIS

Slides:



Advertisements
Similar presentations
Basic Java Constructs and Data Types – Nuts and Bolts
Advertisements

1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
Your First Java Program: HelloWorld.java
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
Java Overview CS2336: Computer Science II1. First Program public class HelloWorld { public static void main(String args[]) { System.out.println("Hello.
Computer Programming Lab(4).
CS0007: Introduction to Computer Programming Scope, Comments, Code Style, Keyboard Input.
Computer Programming Lab(5).
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
CSC204 – Programming I Lecture 4 August 28, 2002.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
CMSC 150 CONDITIONAL EXECUTION CS 150: Mon 16 Jan 2012.
Assignment statements using the same variable in LHS and RHS.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
Java basics. Task  Display the supposed forecast I think there is a world market for maybe five computers. Thomas Watson, IBM, 1943.
Chapter 2 Introduction to C++ Department of Computer Science Missouri State University.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Lecture 4 – Scanner & Style. Console Output The console that starts a Java application is typically known as the standard output device. The standard.
Documentation and Style. Documentation and Comments  Programs should be self-documenting.  Use meaningful variable names.  Use indentation and white.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Formatted Output (printf) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC INTRO TO COMPUTING - PROGRAMMING If Statement.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Java basics – part 2. Where are we Last week –Java basics Simple output program Started programs as calculators –Codelab –Lab procedures This week –Types,
Computer Programming with Java Chapter 2 Primitive Types, Assignment, and Expressions.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING String and Scanner Objects.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
Formatted Output (printf) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to programming in java
Lecture 4 – Scanner & Style
Computer Programming Your First Java Program: HelloWorld.java.
User Input ICS2O.
Chapter 2 Clarifications
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
CS0007: Introduction to Computer Programming
Chapter 1 Introduction to Computers, Programs, and Java
COMPUTER 2430 Object Oriented Programming and Data Structures I
Data types, Expressions and assignment, Input from User
Comp Sci 200 Programming I Jim Williams, PhD.
Something about Java Introduction to Problem Solving and Programming 1.
Scope, Comments, Code Style, Keyboard Input
Program Style Console Input and Output
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Java Intro.
Announcements Lab 7 due Wednesday Assignment 4 due Friday.
class PrintOnetoTen { public static void main(String args[]) {
Documentation and Style
Anatomy of a Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

Intro to CS – Honors I Documentation and Coding Style GEORGIOS PORTOKALIDIS

Picking Good Names NOT HELPFUL double r; double a; a = * r * r; SELF-DOCUMENTING double radius; double area; public static final PI = ; Area = PI * radius * radius;

Comments // comment text ◦Everything after “//” is ignored by the compiler /* comment text */ ◦Everything between “/*” and “*/” is ignored by the compiler ◦Appropriate for multi-line comments /** comment text*/ ◦Same as above, but also understood by Javadoc Use comments to explain details

More Comments  More Readable POOR COMMENT double radius; //the radius of a circle USEFUL COMMENT double radius;//in inches double area;//in square inches Useful for people that use the metric system.

Comment Your Code import java.util.Scanner; /** Program to compute area of a circle. Author: Jane Q. Programmer. Address: Programming Assignment 2. Last Changed: October 7, */ public class CircleCalculation { public static void main(String[] args) { double radius; //in inches You can also place this block above imports

Indentation public class CircleCalculation { public static void main(String[] args) { double radius; //in inches Scanner keyboard = new Scanner(System.in); System.out.println("Enter the radius of a circle in inches:"); radius = keyboard.nextDouble(); area = * radius * radius; System.out.println("A circle of radius " + radius + " inches"); System.out.println("has an area of " + area + " square inches."); } Program structure elements

Indentation public class CircleCalculation {public static void main(String[] args) { double radius; //in inches Scanner keyboard = new Scanner(System.in); System.out.println("Enter the radius of a circle in inches:"); radius = keyboard.nextDouble(); area = * radius * radius; System.out.println("A circle of radius " + radius + " inches"); System.out.println("has an area of " + area + " square inches."); } } Without proper indentation things can get ugly quickly.

Indentation public class CircleCalculation { public static void main(String[] args) { double radius; //in inches Scanner keyboard = new Scanner(System.in); System.out.println("Enter the radius of a circle in inches:"); radius = keyboard.nextDouble(); area = * radius * radius; System.out.println("A circle of radius " + radius + " inches"); System.out.println("has an area of " + area + " square inches."); } Indent every new block of code

Indentation public class CircleCalculation { public static void main(String[] args) { double radius; //in inches Scanner keyboard = new Scanner(System.in); System.out.println("Enter the radius of a circle in inches:"); radius = keyboard.nextDouble(); area = * radius * radius; System.out.println("A circle of radius " + radius + " inches"); System.out.println("has an area of " + area + " square inches."); } Quite a few “schools” of coding styles Example: spaces vs tabs Use one or the other! When using spaces use an indentation of 4 or 8 spaces Tab can be configured to leave these many spaces.

Using Named Constants public class CircleCalculation2 { public static final double PI = ; public static void main(String[] args) { double radius; //in inches double area; //in square inches Scanner keyboard = new Scanner(System.in); System.out.println("Enter the radius of a circle in inches:"); radius = keyboard.nextDouble(); area = PI * radius * radius; System.out.println("A circle of radius " + radius + " inches"); System.out.println("has an area of " + area + " square inches."); } Can be also placed here. What would be the problem with that?

Javadoc