<h1 style='border: none'><center>Programming I Lab 1</center></h1>
<h2 style='border: none'><center>Intorduction to Programming</center></h2>
<h5><center>The Islamic University of Gaza<br>Engineering Faculty<br>Department of Computer Engineering</center></h5>
<h6>Author: Mohammed Nafiz ALMadhoun<span style="float:right">2021/09/17</span></h6>
---
In this lab, we are going to have an introduction about computers, programs, and programming, after that lab you should be able to:
## Lab Objectives
- Understand the basic concepts of computer memory.
- Understand how programs run.
- Be able to use Windows Powershell (or cmd).
- Be able to write a Java program.
- Be able to compile Java programs.
- Be able to fix syntax errors.
- Be able to run and test Java Programs.
## Introduction
### What is a Program
You have programmed some programs in your previous course `Introduction to Computers`, but how do these programs work?
First of all, we write instructions to the computer to execute, as you know the computer won't understand the regular English Text, so we write a text that is between English and Maths, this code also is very hard for the computer to execute.
But there's a magic program (Compilers, Interpreters) that converts your source code to machine code, the machine code is just a binary that your CPU could understand and execute easily.
<center>

Figure 1: From Problem to Machine.
</center>
<div style="page-break-after: always;"></div>
### Command Line Interface
The command-line interface (CLI) is just a way to control your computer and run programmes, we usually do that using Graphical User Interface (GUI).
The GUI is easier for regular computer users, but for a programmer, it is easier and faster to use the CLI, as you will have more options, and the tools run faster.
If you are using windows, you can use PowerShell, or Command Prompt.
<center>

Figure 2: PowerShell Example
</center>
In the CLI, we have something called Current Working Directory, which is the folder we are currently in (1), after the `>` we could write a command, I used the command `cd` (2) with one argument (3), the `cd` command will change the current working directory to the argument.
Then I executed the command (program) `cat`, with one argument `test.txt`, which is the file name that `cat` program will get its content.
As you can see the program prints its output to the CLI (4)
`Note: It's very important to know your current working directory.`
<div style="page-break-after: always;"></div>
## Introduction to Java Programming
### How Java Programs Work
In Java, we write a java source code file (*.java), which is a text file (You can use notepad to write code).
Then this code will be compiled using Java Compiler to an intermediate code (Bytecode) (*.class).
This intermediate code will be executed using a program called Java Runtime Environment, the JRE will translate the code to machine code (Not really).
<center>

Figure 2: How Java Programs Work
</center>
### What do I need to Staring Programming in Java
To compile your Java source code, you should Install [JDK](https://www.oracle.com/java/technologies/downloads/#java8), please Install `Java SE Development Kit 8`, the JDK comes with the JRE, which is important to run Java Programs.
Now after installing JDK, you should add it your `Environment Variables`, so we could run the Java Compiler directly from the CLI, to do that follow these steps:
1. Open `MyComputer` Properties
<center>

</center>
<div style="page-break-after: always;"></div>
2. Click `Advanced System Settings`
<center>

</center>
3. Click `Enviroment Varialbes`
<center>

</center>
4. Choose `Path` variable from the top menu (to configure it for your user only), or the bottom menu (to configure it for all users), then click `Edit`.
<center>

</center>
5. Click `New` and paste the path of the `bin` folder in the JDK installation folder.
e.g. `C:\Program Files\Java\jdk1.8.0_221\bin`
6. Click `OK` in every window.
<div style="page-break-after: always;"></div>
### Comple Your First Java Source Code!
1. Open a notepad, and paste the following code:
```java=
public class MyProgram {
public static void main(String[] args) {
System.out.println("Hi This is my first program!");
}
}
```
2. Save the file as `MyProgram.java`.
3. Open Powershell and go to the folder where you saved the file.
4. Write `javac MyProgram.java`.
5. Write `java MyProgram`.
<center>

</center>
You might notice that the line `System.out.println`, will print the text between the quotations.
Note: You can use [Notepad++](https://notepad-plus-plus.org/downloads/).
## LAB Tasks
### Task 1: Compile and fix the following code.
```java=
import java.util.Scanner;
public class Task1 {
public static void main(String[] args){
System.out.print("Enter your birthyear: );
Scanner input = new Scanner (System.in);
int year = input.nextInt();
int age = 2021 - year
System.out.println("You are " + age " years old");
}
}
```
`Note: Remember to name your file as your class name (Taks1)`
<div style="page-break-after: always;"></div>
### Task 2: Write your first program.
You should write a program that solves the following equation and prints it, your class name should be `Task2`.
equation $\frac{5*4+4}{10+2}$
<center>

</center>
Note that you should calculate the result in code (Don't print number 2!).
###### tags: `Programming` `Java` `IUG`
<center>End Of Lab 1</center>