Skip to content

Update Java Fundamentals #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: Java-Fundamentals-Methods-and-Arrays
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions EN/00-Data-Types-and-Variables/00-Lesson-Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@

- What is a variable

**2. The Integer and the Double Data Types**
**2. Integer and Double Data Types**

- The difference between The Integer and Double data types
- The difference between **Integer** and **Double** data types

**3. Type Conversion (Casting)**

- Implicit vs explicit conversion
- **Implicit** vs **Explicit** conversion

**4. The Boolean Data Type**
**4. Boolean Data Type**

- What is a boolean value
- What is a **boolean** value

- An overview of the Boolean data type

**5. The Character and The String Data Types**
**5. Character and String Data Types**

- An overview of the Character data type
- An overview of the **Character** data type

- An overview of the String data type
- An overview of the **String** data type

[/slide]
57 changes: 30 additions & 27 deletions EN/00-Data-Types-and-Variables/01-Data-Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-3-4-How-computers-work-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

A computer is an **electronic machine** that processes information or, in other words, an **information processor**. It takes the raw information (or data) from one end, stores it until it is ready to process, when processed it returns the results on the other end.
A computer is an **electronic machine** that processes information. It takes the raw information (data) and stores it until it is ready to process. When processed it returns a results on the other end.

The processing stages **can be defined as follows**:
The **processing stages** are defined as follows:

Taking in information is done through the "input", information is then stored in "memory", performing computations on information is also known as "processing", the returned results are called "output".
* **input** - taking in information
* **memory** - storing information
* **processing** - performing computations on information
* **output** - returning result

[image assetsSrc="How-Does-Computing-Work.png" /]

Expand All @@ -21,13 +24,13 @@ Taking in information is done through the "input", information is then stored in

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-5-Variables-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

A variable is a location in computer memory, which can be addressed by its name.
A variable is a location in the computer's memory, which can be addressed by its name.

It is the basic storage unit in a program.

* The value stored inside a variable can be changed during the program's execution.

* A variable is only the name given to a memory location, every operation done on the variable affects the memory location.
* A variable is only the name given to a memory location. Every operation done on the variable affects the memory location.

* In Java all variables must be declared before usage.

Expand All @@ -38,11 +41,11 @@ int count = 5;
// 5 – variable value
```

A variable is defined bi its:
A variable is defined by its:

* **Data type**: The type of data that can be stored in this variable
* **Variable name**: The name given to the variable
* **Variable value**: The initial value stored in the variable
* **Data type**: the type of data that can be stored in this variable
* **Variable name**: the name given to the variable
* **Variable value**: the initial value stored in the variable

A variable can be declared without initialization and then initialized at a later time:

Expand All @@ -51,20 +54,20 @@ int count;
count = 5;
```

In the example above we declare an `int` variable named `count`, when we need that variable we can assign a value to it.
In the example above we declare an `int` variable named `count`. When needed that variable can have a value assigned to it.

The `count` variable holds the value of `5` after getting initialized.

## Real Life Example
You can think of variables as kitchen jars.

Imagine that in each jar you can only store one of the following: salt, sugar, or coffee.
Imagine that in each jar you can only store one of the following: salt, sugar or coffee.

[image assetsSrc="Variables-real-life-example.png" /]

In programming,

we use variables that act as containers for different data types like: numbers, text, symbols, and so on.
we use variables that act as containers for different data types - numbers, text, symbols and so on.

For example, if we have a variable meant to hold integers we will not be able to store text in it.

Expand All @@ -81,20 +84,20 @@ There are **two general data types** in Java:

**Primitive data types**

- Built-into the programming language
- Built-in the programming language

- The size and type of the variable values are stronly specified and they cannot be modified
- The size and type of the variable values are strongly specified and they cannot be modified

- Examples: `boolean`, `char`, `int`, `long`, `float`, and `double`
- Examples: `boolean`, `char`, `int`, `long`, `float` and `double`


**Non-primitive data types**

- Not defined by the programming language but by the programmer

- They are also called "reference types" since they hold an address in computer memory (RAM) where the data is stored
- They are also called "reference types" since they hold an address in the computer memory (RAM) where data is stored

- Some examples are `Strings`, `Arrays`, and `Classes`
- Some examples are `Strings`, `Arrays` and `Classes`

[/slide]

Expand Down Expand Up @@ -128,19 +131,19 @@ Non-primitive data types hold references to the location of a value in memory.

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-8-naming-our-variables-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

In programming, a naming convention is a set of **rules** to be observed when choosing names for variables and other code elements.
In programming, a naming convention is a set of **rules** to be observed when choosing a name for variables and other code elements.

Naming conventions make programs more understandable and easier to read.

In Java the naming convention called "**camelCase**" is applied.
The naming convention used in Java is called "**camelCase**".

"**camelCase**" follows these rules:

- Each word or abreviation (excluding the starting one) begins with a capital letter
- The first letter is always lower case

- A camelCase name contains no spaces
- Each word or abreviation following the first begins with a capital letter

- A camelCase name contains no punctuation
- A camelCase name contains no spaces or punctuation

```Java
String firstName = John; //correct
Expand All @@ -152,9 +155,9 @@ String last_name = Smith; //incorrect
int PersonAge = 41; //incorrect
int foo = 2; //incorrect
```
The variable name should explain its purpose.
The name should explain the variable's purpose.

When naming a variable, it should answer the question: **What does this variable contain?**
When naming a variable it should answer the question: **What does this variable contain?**
[/slide]

[slide hideTitle]
Expand All @@ -166,7 +169,7 @@ The **scope** of a variable is defined by the areas or sections of a program in

The **lifetime** of a variable refers to how long the variable is kept in memory.

Generally, the scope of a variable is limited to the code block, in which it is created.
Generally, the scope of a variable is limited to the code block in which it is created.

A block **begins** with an opening curly bracket `{` and **ends** with a closing curly bracket `}`.

Expand Down Expand Up @@ -194,9 +197,9 @@ public static void main(String[] args) {

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-10-variable-span-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

Variable **span** is a term representing how long before a variable is called after its declaration.
Variable **span** is a term representing how long before a variable is called after it is declared.

It is a good practice to create a variable as **late as possible** (shorter span), before it is needed.
It is good practice to create variables with **shorter span**, i.e. create them right before they will be needed.

```java
static void main(String[] args) {
Expand Down
28 changes: 14 additions & 14 deletions EN/00-Data-Types-and-Variables/02-Integer-Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

**Integer types** store whole numbers, positive or negative (such as 123 or -456).

**Byte**, **short**, **int**, and **long** are all different integer data types.
**Byte**, **short**, **int** and **long** are all different integer data types.

Choosing which one to use depends on the numeric value it will need to store.
Choosing which one to use depends on the numeric value it needs to store.

|Type| Default Value | Min Value | Max Value| Size |
|-----|------|-----|------|-----|
Expand All @@ -23,7 +23,7 @@ Choosing which one to use depends on the numeric value it will need to store.

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-14-examples-centuries-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

We should choose different integer types according to their value.
Choosing different integer types according to their value:

```java live
byte centuries = 20;
Expand All @@ -36,7 +36,7 @@ System.out.printf("%d centuries = %d years = %d days = %d hours.",
//20 centuries = 2000 years = 730484 days = 17531616 hours.
```

We can use different integer types depending on what we want to store in them.
Using different integer types depends on what information will be stored in them.

- The **byte** data type can be used to store whole numbers from -128 to 127

Expand All @@ -54,16 +54,16 @@ short myNum = 5000;
System.out.println(myNum);
```

- The **int** data type can store whole numbers ranging from -2147483648 to 2147483647
- The **int** data type can store whole numbers ranging from -2147483648 to 2147483647.

The **int** data type is the most commonly used data type when we create variables holding a numeric value.
The **int** data type is the most commonly used data type when variables holding a numeric value are created.

```java live
int myNum = 100000;
System.out.println(myNum);
```

- The **long** data type can store whole numbers from -9223372036854775808 to 9223372036854775807
- The **long** data type can store whole numbers from -9223372036854775808 to 9223372036854775807.

It is used when an int is not large enough to store the value.

Expand All @@ -80,9 +80,9 @@ System.out.println(myNum);

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-15-Integer-overflow-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

All integers have a range - a minimum and maximum value.
All integers have a range - **minimum** and **maximum** value.

This means that integers can overflow, producing incorrect values.
This means that integers can overflow which leads to producing incorrect values.

Example:

Expand All @@ -101,11 +101,11 @@ for (int i = 0; i < 130; i++) {
//-127
```

The `counter` starts from 0 and is incremented on each step of the for-loop.
The `counter` starts from 0 and is incremented on each step of the **for-loop**.

Eventually when it reaches the maximum value of a byte (127), it assumes its minimum value (-128).
Eventually when it reaches the maximum value of a byte (127) it assumes its minimum value (-128).

This is called **integer overflow** and it is precisely the reason why choosing your data type correctly is important.
This is called **integer overflow** and it is precisely the reason why choosing the correct data type is crucial.

[/slide]

Expand All @@ -116,9 +116,9 @@ This is called **integer overflow** and it is precisely the reason why choosing

Integer literals are numbers which do not have a floating point part.

**541** is a literal value, for example.
For example: **541** is a literal value.

They can be represented in a few different ways, which are not as intuitive:
They can be represented in a few different ways which are not as intuitive:

- **hexadecimal integer literals** - values using the hexdecimal numeral system; beginning with **0x** and **OX** - **0xFE**, **0xA8F1**, **0xFFFFFFFF**

Expand Down
8 changes: 4 additions & 4 deletions EN/00-Data-Types-and-Variables/03-Real-Number-Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ System.out.println("Float PI is: " + floatPI);
System.out.println("Double PI is: " + doublePI);
```

**NOTE**: The `f` suffix in the first statement signifies that it should be interpreted as a float
**NOTE**: The `f` suffix in the first statement signifies that it should be interpreted as a float.

- Real numbers are interpreted as **double** by default

Expand Down Expand Up @@ -193,7 +193,7 @@ System.out.println(exampleVariableThree);

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-24-floating-point-division-and-demo-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

There are two types of numeric division: integral and floating-point division
There are two types of numeric division: integral and floating-point division.

See the examples below:

Expand Down Expand Up @@ -243,7 +243,7 @@ System.out.println(num);

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-26-big-decimal-and-demo-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

Sometimes, floating-point numbers might also behave abnormally in calculations
Occasionally, floating-point numbers behave abnormally in calculations

You can read more about **IEEE 754** by looking it up in any search engine.

Expand Down Expand Up @@ -369,4 +369,4 @@ Create a program that accepts numbers, calculates and prints their **exact sum**
[/test]
[/tests]
[/code-task]
[/slide]
[/slide]
10 changes: 5 additions & 5 deletions EN/00-Data-Types-and-Variables/04-Type-Conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

[video src="https://videos.softuni.org/hls/Java/Java-Fundamentals-Methods-And-Arrays/01.Java-Fundamentals-Data-types-and-variables/EN/interactive-java-fundamentals-data-types-and-variables-30-31-type-conversion-and-demo-,1080p,720p,480p,360p,240p,.mp4/urlset/master.m3u8" poster="" /]

When you assign the value of one data type to another, the two types might not be compatible with each other.
When assigning the value of one data type to another the two types might not be compatible with each other.

If the data types are compatible, Java will perform the conversion automatically.
If the data types are compatible **Java** will perform the conversion automatically.

This is known as **Automatic Type Conversion**, and if they are not compatible, they need to be converted explicitly.
This is known as **Automatic Type Conversion**. If they are not compatible they need to be converted explicitly.

For example, assigning an **int** value to a **long** variable.

Expand All @@ -30,7 +30,7 @@ System.out.println(myDouble);

Here a lower data type \(having smaller size\) is converted into a larger data type \(having larger size\).

There is no loss in data, so this type of conversion happens automatically.
There is no loss in data, therefore, this type of conversion happens automatically.

- **Narrowing conversion** \(manual\) - converting a larger type into a smaller data type. Also known as **explicit conversion**

Expand Down Expand Up @@ -75,7 +75,7 @@ public class Main {

## Description

Create a program that accepts an **int** number of **centuries** and converts it to the respective amount of **years**, **days**, **hours**, and **minutes**.
Create a program that accepts an **int** number of **centuries** and converts it to the respective amount of **years**, **days**, **hours** and **minutes**.

The input will be of type **int**.

Expand Down
Loading