CSCE145 F2026 01 Basic Computing Part 01
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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Transcript excerpt
0:01 Hey everyone, how it goes? Welcome back to computer science 145. I'm Dr. JJ Shepard and today we're going to discuss basic computation. So as we are developing programs, we're first going to discuss procedural programming. As we know a computer consists of two major components, hardware and software. In hardware, we understand that the CPU runs a program statements one at a time. This starts from the entry point and reads it left to right, top to bottom. We also understand another piece of hardware is called the memory and this stores the information that can be accessed and modified by the CPU. Going into more detail, we are developing Java programs. These are
0:49 organized first by projects, then by classes, and then by methods. We're going to be using some terminology a lot, but whenever we refer to the body of something, it is whatever is in between the curly braces. So for example, this is the class and this would be the body of the class. Everything in between those curly braces. Methods in Java need to be written inside of classes and the body of the method is in between these curly braces. Now, more specifically, the main method is Java's entry point. This is where the CPU knows to start reading the information. So, a lot of our code is going to be written inside the main
1:35 method at first. Now, in order for us to do basic computation, we need to be able to store information. One way that we could do this is by utilizing variables. Variables store data such as a number or a character and you can consider it as basically being a container or a box. Storing information is implemented by using memory. The value is the name that we called the
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
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.