Thursday, December 12, 2024

Getting started with Java

Getting started in Java can seem daunting, but with a bit of time and elbow grease, you can easily start your programming journey!

Installing Java

You can install Java from Oracle's website page Java Downloads. Select the newest JDK (Java Development Kit) and your system's OS. I chose the Windows x64 Installer. Follow the normal installation process on your PC.

Installation and IDE

To begin your first Java program, you can use the Notepad application on your PC, or install an IDE (Integrated Development Environment). Using an IDE over a simple text editor like notepad has many advantages as they contain many helpful tools for developers like error checking and debugging, and some will automatically compile code and provide you a console to test your code within the program.

For more information on installing Java and an IDE, I recommend Coding With John’s video on YouTube “Create Your First Java Program from Scratch in Minutes”. In his video, he recommends the IDE Eclipse.

 

Now that you have Java and your IDE installed, start your journey by creating your first program, “Hello World”

Java Basics

Java is an object-oriented programming (OOP) language where the code is centered around objects. An Object combines properties (attributes) and methods (behaviors), typically representing a real-world entity. A Class is a blueprint or template for creating objects, defining the properties and behaviors that can be done to an object, while an object is an instance of a class that inherits these properties and methods. For example, the class may be Animals, while an object could be created for different types of Animals, like Mammals. You can extend classes to create subclasses, so instead of an object being created for Mammals, you can create a new subclass for Mammals that extends from the Animals class and create an object from the Mammals class for Cats.

The Four Major Principles of Java

There are 4 major principles to learn for Java.

Encapsulation: Hiding the complex implementation details around data by bundling the data within a class. For example, a user may be able to call data on a cat’s diet using a public accessor (a way to fetch information) without seeing how the Diet object was created (inherited from the Animal class). You may also be able to edit data using a public Mutator without seeing the complex details of how the diet is updated.

Abstraction: Abstraction is the development of classes, objects, and types that only focus on exposing the essential functionalities of a class, object, or type.

Inheritance: Subclasses can inherit properties and methods from existing classes. In our example above, the Animals class may have the attributes “Number of Legs” and “Diet.” Classes extended from it will also have these attributes, so the Mammals and Cats class will inherit these attributes and any methods unless overridden.

Polymorphism: Allows you to use the same method to have different behaviors by overriding. In our animal class example, if we have a method makenoise = ‘Growl’ we can use polymorphism on the subclass reptile to define behavior to output ‘Ssssssss’ instead of ‘Growl’.


Recommended Resources


Sunday, December 8, 2024

Operating System Theory

     A computer operating system has three primary purposes: allocating resources between hardware and programs, providing a platform for application programs to execute on, and operating as the control program supervising I/O devices. The objectives are achieved through an operating system's core functions: Process Management, Memory Management, File management, I/O Device Management, security, and protection. At the top of the OS hierarchy is the User Interface, where the user interacts with the computer. From there, user applications and system programs, programs that run in the background and do not require user interaction, make system calls that interact with the services provided by the OS.



    Computer systems consist of many processes, including user processes and operating-system processes. Processes are programs in execution, each one a list of instructions. Processes are represented as Process Control Blocks (PCB), which contain important information like the program code, the program counter, which tracks the next instructions, and the process state. The process state indicates where the process is in execution, between New, Waiting, Ready, Running, and Terminated. Threads are within processes, which are instructions for execution within a process. With the introduction of multi-processing and multi-threading, process management has become more important than ever to ensure processes are protected from one another during execution. The OS manages kernel threads, which handle resource allocation, and kernel threads are mapped to user threads in various models, including Many-To-One, where many user threads are mapped to a single kernel, One-To-One where one user thread is mapped to one kernel, and Many-to-Many where many user threads are mapped to less than or equal amounts of kernel threads. 



Within the computer system, the hardware lives the memory, split into four types that interact together. The registers in the CPU core are the fastest and smallest memory, storing limited data that is frequently used like operands. The cache memory lives in the processor, is also fast but limited, and typically acts as a buffer between the cache and Main Memory. The main memory (RAM) typically stores active processes, and because it is volatile, any data is lost when turned off. Finally, secondary storage, such as HDD and SDD, is non-volatile, so information can be stored with no power and acts as long-term storage. 

    Because processes must move between all different memory types, memory management is important for improving CPU utilization and computer response time amongst the multiple active processes. Memory management algorithms vary, but the most important determinant of the method is the hardware provided. The CPU can only access the main memory and registers onboard the processor, so process instructions must be in one of the direct access storage devices. When a process is ready for execution, its code and data are moved into the main memory from the secondary storage. Those processes waiting to be brought into the memory make the input queue, from which a single-tasking procedure selects one and loads the process into the memory. Each process in the main memory must have its own defined memory space to protect it from other processes and ensure processes can run concurrently. To do so, we use two registers: the base register and the limit register. The base register contains the smallest physical memory address of the processes allocated memory, while the limit register defines the range size from that base. Thus, when the CPU goes to check if the address generated in user mode if the program attempts to access operating-system memory or other process-defined memory, it results in a trap. When a program is executed, the binary executable file must be brought into the memory and placed in a process. Virtual memory is when the main memory is expanded into the secondary storage to simulate a larger main memory for more or larger processes.



    The next important function of an operating system is file management. In the file system, some files contain related data and file directories with information on the files within the system. Different operations can be performed on files, including creating, writing, reading, deleting, truncating, and repositioning within files. File management functions include access control for users and programs, access methods to obtain information, sharing files between users and other systems, and file protection by defining access types, user access control, passwords, and enhancing reliability through backup copies. File directories are crucial in maintaining file systems by organizing and providing information on all files. Directory operations include creating, deleting, renaming, and searching for files, listing directories and contents, and traversing the file system. There are many types of directory schemes that dictate how files and sub-directories are laid out and interact with each other.



    Input and Output devices vary widely, from storage devices, transmission devices, and human-interfaced devices to other specialized devices. The CPU moves data between the I/O devices and memory by sending read and write bit patterns to the controller’s data and control signal registers. Device drivers help the OS communicate with these devices by translating commands between the OS and the I/O devices and acting as an in-between between the software layer and physical hardware.



    Finally, the last important function of an operating system is to provide protection and security for the computer system. Protection is controlling access to resources in the computer system for programs, processes, and users. It is necessary to prevent internal access violations from ill intent and ensure active programs only use necessary resources. Access Control can be determined in different ways, each to secure resources and limit access to only what is necessary. Security is focused on external threats and computer system security. Working to prevent security threats reduces the need to react to threats. These threats can be targeted or unintentional. Protection methods like access control help protect and secure from unauthorized access, destruction, or alteration of resources. User authentication methods like passwords or two-factor authentication can additionally help protect systems. Encrypting data for secure transfer helps secure networks and programs. While not covered in the book, one of the biggest vulnerabilities to a computer system is the user, making user training in security best practices a large contributor to protecting programs, systems, and networks.



With the world becoming increasingly computer-dependent and advanced, understanding the concepts of operating system theory will help in every field. From writing code with memory management in mind to running faster, more efficient processes, understanding and managing access for users and programs with a more fine-tuned approach, or even just interacting with your personal computer more efficiently and securely. OS theory concepts help enable you to better interact with computer systems in any field of work. As an Information Technology student, OS theory concepts are the building blocks to fundamental knowledge you can build upon in future classes.

CPT304 Operating Systems Theory & Design Concept Map-OS Theory Concept Map.drawio.png