Summary

These notes cover fundamental concepts in computer science, including units of data like bytes and bits, and an introduction to Java programming. The material explains programming concepts such as objects, methods, and classes.

Full Transcript

CS2 - Unit 1 Notes Bytes & Bits 1 B Byte = 8 bits 1 KB KiloByte = 1 thousand bytes 1 MB MegaByte = 1 million bytes 1 GB GigaByte = 1 bil...

CS2 - Unit 1 Notes Bytes & Bits 1 B Byte = 8 bits 1 KB KiloByte = 1 thousand bytes 1 MB MegaByte = 1 million bytes 1 GB GigaByte = 1 billion bytes 1 TB TeraByte = 1 trillion bytes Java Programming Generalities Safe Portable Platform-independent Has a vast set of library packages Designed for the internet Object-oriented programming therefore follows a specific syntax System.out. Println (“hello world”); Case-sensitive so uppercase text is considered different than lowercase text Source Code Set of instructions written by a programmer in a programming language that tells a computer how to perform tasks. It’s a fundamental component of a computer program and is often written in the form of functions, definitions, descriptions, calls, methods, and other operational statements. Designed to be human-readable and formatted in a way that developers and other users can understand Types of Editors Text editor (Notepad ++) - more basic and focused on editing code Integrated Development Environment aka IDE (Visual Studio Code) - more feature-rich and can help you test and preview code projects Some top IDEs in 2024 are IntelliJ, Eclipse, and VS Code Compiler A program that translates source code (instructions) into machine-code so it can be read and executed by a computer. Class Files A file containing bytecode and having.class extension that can be used by JVM (Java Virtual Machine) JVM acts as the run-time engine to run Java apps It’s the one that actually calls the main method present in the Java code Main Method Every Java application contains a class with a main method When the application starts, the instructions in the main method are executed Declaring a main method Public static void main (String [ ] args) {... } The main method is automatically called when the program is executed Classes The fundamental building blocks of Java The blueprint or a template that defines the properties and behavior of objects The keyword “class” must be used to declare the class and whether it is public or private, etc. Initial letter is capitalized by convention Class body is surrounded by { } The name of the public class must match the name of the file containing the class ○ Class HelloPrinter must be contained in a file named HelloPrinter.java A java program can contain any number of classes, and at most, one of them can be declared as a public class Methods Set of instructions (action) which we use to do operations on the data. They DO something Start with a lowercase letter Objects The actual component of programs while the class specifies how instances are created and how they behave. They just REPRESENT some class. Object Method Call An object to call the method (System.out) The name of the method (println) Any arguments the method needs to carry out its task enclosed in parentheses (“Hello World) Semi-colon at the end System.out.println (“Hello World”); Variable Stores a value that you want to use later When declaring a variable you usually specify an initial value When declaring a variable, you also specify the type of its value Use a meaningful variable name that describes its purpose Starts with a lowercase letter Types String - text, surrounded by double quotes “ “ int - integers float - decimals char - single char, surrounded by single quotes ‘ ‘ boolean - true or false Can be combined by arithmetic operators such as +, -, * Identifiers The names given to a package, class, interface, method, or variable Must start with a letter, underscore, or $ After beginning character, remaining characters must be letters, numbers, or underscores Cannot use other symbols such as ?, %, or space Use camelcase Are case sensitive Cannot use reserved words such as class Example of Class vs Method vs Objects Class acts like a skeleton that contains data and methods. You have to use that skeleton to do data manipulation So you give the skeleton different names called object. Through that object you access different types of skeletons. For example, a skeleton can be named male or female. Both have different characteristics (data) under the same attributes. Methods are a set of instructions, which we use Male Object to do a work called writing, then the methods write ( ) will have the instructions such as take pen, take paper, write “something”. The write ( ) methods can be accessed by both male and female object. To access it with male we use male.write ( ) and to access it with female we use female.write ( ).

Use Quizgecko on...
Browser
Browser