/
CS 1: Java Programs CS 1: Java Programs

CS 1: Java Programs - PowerPoint Presentation

danika-pritchard
danika-pritchard . @danika-pritchard
Follow
344 views
Uploaded On 2020-01-28

CS 1: Java Programs - PPT Presentation

CS 1 Java Programs Colorado State University Department of Computer Science Announcements Learning Objectives To understand the components of a Java program Due Date Reminders zyBooks Chapter 1 Today ID: 774036

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "CS 1: Java Programs" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

CS 1: Java Programs Colorado State University Department of Computer Science

Announcements Learning Objectives To understand the components of a Java program Due Date Reminders zyBooks Chapter 1 – Today Program 1 - Monday

Think-Pair-Share: Application Essentials On a piece of paper, write: 2-4 components you think are essential to a computer application Pair with a partner Discuss the ideas you wrote down Share the answers with others Share the answer with another group next to you (or same table)

Imports: lets your program use other code. For example: import java.util.Scanner;Class name: the name of the organizational unit in Java. Must start with uppercase letter. Entry point: where the program starts. In Java: main() Statements: the base unit of code. Represents a single, simple action. Ends with a semicolon. ';'Reserved words: have special meaning and can’t be used for anything else. "class", "public"... Blocks: organize your program and help the computer read it. Defined by braces: { }Comments: help people reading the code! Can be line: // a single-line comment, or block: /* can span many lines! */ Anatomy of a Java Program

Whitespace means any part of some text that isn’t a symbol. Think spaces, tabs, etc.In Java, whitespace doesn’t change the way the program works.It’s a good idea to use good indentation and spacing to make your code easier to understand . public class Avatar { public static void main(String[] args) { String favoriteElement = "water"; System.out.println("My cabbages!"); } } Whitespace in code Indentation Spacing Pro Tip: Auto-Indent Many IDE’s support auto-indentation! In Eclipse, it’s Ctrl + I

In programming, there are many conventions around style choices.Brace positioning, variable names, etc…It’s usually good to choose a convention. Be consistent ! Don’t mix and match. public static int answerToTheUniverse() { // brace-up style int variable_with_underscores = 42; } String getSomeText() { // brace-down styleString camelCaseVariable = "<3"; } Convention

Let’s practice! Write declarations for variables to store some pieces of information. Pick a style and be consistent.Example: A student’s name => String studentName; Try these: The radius of the Earth in miles The character at the end of a sentence Your favorite ice cream flavor Then, think about the two brace placement styles (brace-up and brace-down). Which do you prefer? Why? Compare your variables and brace reasoning with a friend. Try it yourself

Compile Error: a problem with the actual text of the codeDetected by the compiler. Code will not runExamples: mismatched braces, missing semicolons Runtime Error: the code runs, but crashes/aborts Encountered at runtime Examples: divide by zero, index out of boundsLogic Error: the code will run and doesn’t crash, but gets the wrong answer Could be caused by a typo, or a misunderstanding of the logic Examples: adding instead of subtracting, off-by-one Types of programming errors

Think-Pair-Share: Organizing functionality On a piece of paper, try to come up with examples of: A syntax error A runtime error A logic error Pair with a partner Talk about the error examples you came up with Share the answers with others Share the answer with another group next to you (or same table)