An Introduction to Linux COS 151 An Introduction to Linux
Lesson Outcome An overview of Linux OS Concept of Boolean Expressions (…If/else statement) Concept of … Flow diagram Introduction to Algorithm (Next week lectures)
Content What is Linux Linux Kernel Map Examples Operating System Linux versus Microsoft Windows Linux Kernel Map Examples While loop If and else statements
What is Linux? It’s an Operating System Linux vs. Microsoft Windows Operating systems graphic source: http://en.wikipedia.org/wiki/Operating_system https://www.youtube.com/watch?v=zA3vmx0GaO8
Linux Kernel Map The kernel is the central nervous system of Linux, include OS code which runs the whole computer. It provides resources to all other programs that you run under Linux, and manages all other programs as they run. The kernel includes the code that performs certain specialized tasks, including TCP/IP networking. The kernel design is modular, so that the actual OS code is very small to be able to load when it needs, and then free the memory afterwards, thus the kernel remains small and fast and highly extensible
Examples If and else statements While loop
Questions?
If and else statement
Boolean Expressions More complex Boolean expressions are also possible Operator Meaning == equal to != not equal to < less than <= less than or equal to > greater than >= greater than or equal to More complex Boolean expressions are also possible
Then if Statement The Java if statement has the following syntax: if (boolean-condition) statement; If the Boolean condition is true, the statement is executed; if it is false, the statement is skipped This provides basic decision making capabilities
If statement flow diagram
If .. Else Statement An else clause can be added to an if statement to make it an if-else statement: if (condition) statement1; else statement2; If the condition is true, statement1 is executed; if the condition is false, statement2 is executed
If/else flow diagram
Lets work on this example together An algorithm for inter-library lending of materials Input: The unique code of the user (userID) Output: Message on whether the material was successfully loaned or not Algorithm: 1. Set numMaterialsLoaned to 0 2. For each material (materialID) loaned to user userID: 2.1 Check availability of materialID 2.2 If not available then 2.2.1 Print message “loan unsuccessful – material is not available” 2.3 Else 2.3.1 If materialID is reserved by another user then 2.3.1.1 Print message “loan unsuccessful – material is reserved” 2.3.2 Else 2.3.2.1 Print message “loan successful – material is loaned” 2.3.2.2 Update arrival date in database (today’s date + 15 days) 2.3.2.3 Add 1 to numMaterialsLoaned 3. Print message: “Number of materials loaned:” numMaterialsLoaned 4. Quit
While statement
The while statement A while statement has the following syntax: while (condition) statement; If the condition is true, the statement is executed; then the condition is evaluated again The statement is executed over and over until the condition becomes false If the condition of a while statement is false initially, the statement is never executed Therefore, we say that a while statement executes zero or more times The while statement
While statement flow diagram
Questions?