CSCE145 F2026 01 Basic Computing Part 01
Watch on YouTube →
Overview
Dr. JJ Shepard introduces procedural programming in Java, explaining how programs run through a main method and how variables, primitive types, identifiers, assignments, and constants represent data in memory. He demonstrates arithmetic and console input/output, then builds a Java program that converts a decimal height in feet into total inches and whole feet plus remaining inches.
Key takeaways
- Java programs begin execution in the main method, which is written inside a class; curly braces identify the bodies of both classes and methods.
- Java primitive types determine what values a variable can hold: int represents whole numbers, double represents decimals, char represents one character, and boolean represents true or false.
- Assignment with = stores the right-hand expression in the variable on the left, while narrowing a double to an int with a cast truncates its fractional part.
- Integer division can produce surprising results: 1 / 3 is 0 when both operands are integers, whereas floating-point arithmetic can represent an approximate decimal result.
- Use named constants such as INCHES_PER_FOOT = 12.0 instead of unexplained numeric literals to make conversion logic clearer.
- The feet-to-inches example combines Scanner input, a conversion constant, multiplication, integer casting, and modulo to turn 5.5 feet into 66 inches, or 5 feet 6 inches.
Chapters
0:00
Java Program Structure, the Main Method, and Variables
- A computer’s CPU executes program statements sequentially, while memory stores information the CPU can access and modify.
- Java code is organized into projects, classes, and methods; curly braces mark each body.
- The main method is Java’s entry point, and variables act as named containers for data stored in memory.
3:00
Java Primitive Types, Memory Sizes, and Identifier Rules
- Java is strongly typed; common primitive types include int for whole numbers, double for decimals, char for one character, and boolean for true or false.
- The lecture gives int as 4 bytes, double as 8 bytes, and char as 2 bytes; character literals use single quotes and strings use double quotes.
- Identifiers cannot contain spaces or begin with digits, are case-sensitive, and cannot use reserved words such as class.
- Java naming conventions use lowercase camelCase for variables and uppercase letters for class names.
9:30
Variable Declarations, Assignments, and Type Casting
- A declaration specifies a variable’s type and identifier; assignment uses = to store the right-hand value in the variable.
- Initialize variables when declaring them, and omit the type when assigning a new value to an already declared variable.
- A double cannot be assigned directly to an int without a cast such as (int) value; casting discards the fractional part rather than rounding.
- Constants are declared with final and must receive a value; uppercase names with underscores help distinguish them from variables.
15:30
Java Arithmetic, Compound Operators, and Numeric Precision
- Java arithmetic includes +, -, *, /, and %; the modulo operator returns the remainder, so 15 % 2 equals 1.
- Compound assignments such as +=, -=, *=, /=, and %= combine an operation with storing its result; ++ and -- change a value by one.
- Floating-point values such as 1.0 / 3.0 are approximations because finite memory cannot store infinitely repeating decimals.
- Integer division discards the fractional part, so 1 / 3 evaluates to 0 when both operands are integers.
21:00
Console Output and Keyboard Input with Java Scanner
- System.out.println prints its argument and moves to a new line, while System.out.print leaves the cursor on the same line.
- Keyboard input uses java.util.Scanner and an instance connected to System.in, such as Scanner keyboard = new Scanner(System.in).
- Scanner methods include nextLine for text and nextInt or nextDouble for numeric input; the example reads a name, 64, and 3.14.
- After nextInt or nextDouble, the lecture recommends consuming the remaining newline with nextLine to avoid input-reading problems.
25:00
Building a Java Feet-to-Inches Converter
- The example program imports Scanner, prompts for a decimal number of feet, and reads it with keyboard.nextDouble().
- A public static final double constant stores 12.0 inches per foot, avoiding an unexplained magic number in the conversion.
- The program calculates total inches as feet × 12, then casts total inches divided by 12 to int for whole feet.
- The remainder operator finds leftover inches; entering 5.5 feet produces 66 total inches, or 5 feet and 6 inches.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, UofSC_CSCE145_CSCE146.