Java Basics Free Course Archives - SoftUni Global https://softuni.org/category/code-lessons/java-basics-free-course/ Learn Programming and Start a Developer Job Sun, 08 Jan 2023 22:09:08 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.3 https://softuni.org/wp-content/uploads/2022/04/cropped-SoftUni-Global-Logo-Square-notext-32x32.png Java Basics Free Course Archives - SoftUni Global https://softuni.org/category/code-lessons/java-basics-free-course/ 32 32 What are Nested Loops? – Java Basics Tutorial (Part 9) https://softuni.org/code-lessons/what-are-nested-loops-java-basics-part-9/ https://softuni.org/code-lessons/what-are-nested-loops-java-basics-part-9/#respond Mon, 25 Oct 2021 11:07:00 +0000 https://softuni.org/?p=10142 In this lesson, we’ll try to untangle the complexity of Nested Loops.

The post What are Nested Loops? – Java Basics Tutorial (Part 9) appeared first on SoftUni Global.

]]>

A nested loop is the placement of a loop inside another loop to execute the operations that need multiple loop traversals, such as printing star patterns. Although it helps to make our task easier, it also increases the complexity of the program thus must be used efficiently.

Now, onto the important part: if a loop exists inside the body of another loop, it is called a nested loop. It has no limitations that only similar types of loops can be nested.

We can nest any loop inside any other loop, such as while loop inside for loop, and all different combinations are accepted.

 

In the chart, first, when we enter the body of the program, a statement such as initialization gets executed. Once a loop is found, the program checks for the condition for the outer loop, and if it returns true, it enters the loop. Once it enters the outer loop and encounters the inner loop, variables are initialized if any are present. Then it checks the condition for the inner loop, and if it returns true, the program enters into the inner loop. This procedure is repeated several times, and then the program exits from the second loop, then the first loop, and move to statements present after the loop.

Lesson Topics

In this tutorial we cover the following topics:
  • Complex Loops
  • Nested Loops
  • Nested For-Loops
  • Nested While Loops
  • Nesting While and For Loops

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Description

Lesson Slides

The post What are Nested Loops? – Java Basics Tutorial (Part 9) appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/what-are-nested-loops-java-basics-part-9/feed/ 0
Java Basics Tutorial – Part 8 – While Loops https://softuni.org/code-lessons/java-basics-tutorial-part-8-while-loops/ https://softuni.org/code-lessons/java-basics-tutorial-part-8-while-loops/#respond Sun, 24 Oct 2021 11:06:00 +0000 https://softuni.org/?p=10086 In this part of the Java Bascics Tutorial, we take a look at While Loops.

The post Java Basics Tutorial – Part 8 – While Loops appeared first on SoftUni Global.

]]>

A While Loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The While Loop can be thought of as a repeating if statement.

In the expression, we have to test the condition. If the condition evaluates to true, then we will execute the body of the loop and go to update the expression. After executing the loop body, this expression increments/decrements the loop variable by some value. Otherwise, we will exit from the While Loop.

How does While Loop execute?

  1. Control falls into the While Loop.
  2. The flow jumps to the condition
  3. The condition is tested.
    1. If it is true, the flow goes into the body.
    2. If it is false, the flow goes outside the loop
  4. The statements inside the body of the loop get executed.
  5. The update takes place.
  6. Control flows back to Step 2.

One more thing, which we have already read in the previous article about advanced conditional statements, is the break statement. It ends the loop immediately when it is encountered. The break statement is usually used with a conditional statement inside the loop.

Both While and For Loops repeat a block of code. We use For Loops when we preliminary know the number of iterations. If we don’t know when the exit condition will be met, we use While Loops.

Lesson Topics

In this video we review the following topics:
  • While Loops
  • While or For Loop?
  • Operator Break
  • Infinite Loops

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 8 – While Loops appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-8-while-loops/feed/ 0
Java Basics Tutorial – Part 7 – For Loops https://softuni.org/code-lessons/java-basics-tutorial-part-7-for-loops/ https://softuni.org/code-lessons/java-basics-tutorial-part-7-for-loops/#respond Sat, 23 Oct 2021 11:06:00 +0000 https://softuni.org/?p=10039 In this lesson of the Java Basics Tutorial, we take a look at For Loops.

The post Java Basics Tutorial – Part 7 – For Loops appeared first on SoftUni Global.

]]>

In programming, a loop is used to repeat a block of code until a specified condition is met. The For Loop is best when you want to do something for a fixed number of times.

How does For Loop work?

  1. Control falls into the For Loop. Initialization is done.
  2. The flow jumps to the Condition.
  3. The Condition is tested.
    1. If it is true, the flow goes into the body.
    2. If it is false, the flow goes outside the loop.
  4. The statements inside the body of the loop get executed.
  5. The update takes place, and the flow goes to Step 3 again.
  6. The For Loop has ended, and the flow has gone outside.

This process goes on until the test expression is false. When the test expression is false, the loop terminates.

Say we want to loop over a range of numbers and print out each one along the way. We can do this best with a For Loop. We will start from the first number, print it out, move to the next number to do the same thing, and continue until we’ve printed each number. Let’s print the numbers zero through nine:

Let’s look at the first line of the For Loop and the three parts necessary to make it work. First, we have an initialization expression, then termination expression, and increment expression in the end.

The initialization expression initializes the loop and is only executed once when the loop starts. That is where you must declare and initialize a variable, usually of type int, to hold an initial number that will be used to loop until it reaches a specific value. That can be thought of as the start of the range to iterate over. In our case, we started at 0.

The For Loop will continue looping until the termination expression evaluates to false. The termination expression is evaluated before each iteration of the loop, and it must return a boolean to decide whether or not to continue looping. If the boolean returned is equal to true, we will run the body of our For Loop again. In our case, the loop terminates after it prints 9.

for-loopsThe increment expression is executed after each iteration of the loop. To increment the variable, we initialize it by using the ++ operator. That allows the termination expression to know how many times the loop loops. The initialization variable count, in our example, starts at 0, and it’s printed out. Then the incrementer increments it, and the next iteration of the loop runs to print the new value and continues that way until it prints 9.

In conclusion, you should use a For Loop when you know how many times the loop should run. There are other more advanced iteration structures that we will look at in the next article.

Lesson Topics

In this video we review the following topics:
  • Increment adn Decrement
  • For Loops
  • Loops with a Step
  • Iterating over Characters
  • Infinite Loops

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 7 – For Loops appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-7-for-loops/feed/ 0
Java Basics Tutorial – Part 6 – Advanced Conditional Statements https://softuni.org/code-lessons/java-basics-tutorial-part-6-advanced-conditional-statements/ https://softuni.org/code-lessons/java-basics-tutorial-part-6-advanced-conditional-statements/#respond Fri, 22 Oct 2021 11:06:00 +0000 https://softuni.org/?p=9984 In this part of the Java Basics Tutorial, we look at Advanced Conditional Statements.

The post Java Basics Tutorial – Part 6 – Advanced Conditional Statements appeared first on SoftUni Global.

]]>

There may be a situation when you want to check for another condition after a condition resolves to true. In such a situation, you can use nested conditional statements. In them, you can have a statement inside another statement and so on.

A Switch Statement is usually more efficient than a set of nested ifs. When we have to choose which one to use, it’s based on readability and the expression that the statement is testing. We use a switch statement to test the value of a variable against a list of case values, while we use an if-else statement for taking a decision.

switch-case-computer

If-else statement evaluates integer, character, pointer, floating-point type, or boolean type. On the other hand, the switch statement evaluates only character or an integer datatype. It’s known to be hard to edit if-else statements since it’s tedious to trace where the correction is required. Many people agree that it’s much simpler to correct switch statements since they’re easy to trace.

There can be any number of case statements within a switch statement. Each case is followed by the value to be compared to and after that a colon. When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached. If that happens, the switch terminates, and the flow of control jumps to the next line following the switch statement. Not every case needs to contain a break. If no break appears, the flow of control will fall through until a break is reached. all the case statements will get executed as soon as the compiler finds a comparison to be true.

Guy-It-Problem

A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used to perform a task when none of the cases are true. No break is needed in the default case. The  switch statement works much faster than an equivalent if-else statement. During execution, instead of checking which case is matching, it only decides which case has to execute. It’s more readable compared to if-else statements.

Lesson Topics

In this video we review the following topics:
  • Complex Control-Flow
  • Nested Conditions
  • Logical Operators
  • Switch-Case
  • Multi-Label Switch-Case

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 6 – Advanced Conditional Statements appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-6-advanced-conditional-statements/feed/ 0
Java Basics Tutorial – Part 5 – Conditional Statements https://softuni.org/code-lessons/java-basics-tutorial-part-5-conditional-statements/ https://softuni.org/code-lessons/java-basics-tutorial-part-5-conditional-statements/#respond Thu, 21 Oct 2021 11:06:00 +0000 https://softuni.org/?p=9921 In this lesson of the Java Bascics Tutorial, we take a look at Conditional Statements.

The post Java Basics Tutorial – Part 5 – Conditional Statements appeared first on SoftUni Global.

]]>

 

conditional-statement-picA conditional statement is a piece of code that checks the given condition, and when it is true, the code related to it is performed. It is used to make decisions based on the conditions. Conditional statements execute when there is no condition around the statements. If you put a condition for a block of statements, the execution flow may change based on the result evaluated by the condition. This process is called decision-making.

Conditional statements begin with the keyword if followed by parentheses. An expression is placed inside the parentheses, then evaluated when the conditional statement is reached. 

The parentheses are followed by a block, which is defined inside opening { and closing } curly brackets. The source code inside the block executes if the expression inside the parentheses evaluates to true. If the expression in the conditional statement evaluates to true, the execution of the program progresses to the block defined by the conditional statement.

On the other hand, if the expression evaluates to false, the execution moves on to the statement after the closing curly bracket of the current conditional statement. Using the else command, we create an alternative option for when the conditional expression evaluates to false. In the case of multiple conditions, we can use the else if  command. else if is like else, but with an additional condition. It follows the if-condition, and they may be multiple.switch-case-computer

To sum it up, conditional statements are something that you must learn if you want to continue developing as a programmer. They s are specified by a set of statements having boolean expressions which, are evaluated to a boolean value true or false. Conditional statements help us to make a decision based on certain conditions.

Lesson Topics

In this video we review the following topics:
  • Logical Expressions
  • Conditional Statements
  • Series of Checks
  • Variable Scope
  • Debugging

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 5 – Conditional Statements appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-5-conditional-statements/feed/ 0
Java Basics Tutorial – Part 4 – Data and Calculations https://softuni.org/code-lessons/java-basics-tutorial-part-4-data-and-calculations/ https://softuni.org/code-lessons/java-basics-tutorial-part-4-data-and-calculations/#respond Wed, 20 Oct 2021 11:06:00 +0000 https://softuni.org/?p=9877 In this part of the Java Bascics Tutorial, we take a look at Data and Calculations.

The post Java Basics Tutorial – Part 4 – Data and Calculations appeared first on SoftUni Global.

]]>

data-type-exampleData types specify the different sizes and values stored in a variable. There are two types of data in Java:

  • Primitive data types
  • Non-primitive data types

To start, we will be using these data types only:

  • int –  holds a wide range of non-fractional number values.
  • double – only takes up to 8 bits of memory
  • boolean – can contain only two values: true or false.
  • char – is a symbol representing a Unicode-encoded character.
  • String – is a sequence of characters

Besides printing them on the console, we can use them for various arithmetic operations. The table on the right shows different types of arithmetic operations. All of them are the same as the arithmetic operations you have learned in school.

These may seem like simple operators, but when correctly, used they can be of help on more complex projects.

Lesson Topics

In this video we review the following topics:
  • Variables
  • Data Types
  • Statements
  • Arithmetic Operators
  • Expressions

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 4 – Data and Calculations appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-4-data-and-calculations/feed/ 0
Java Basics Tutorial – Part 3 – Console-Based Input and Output https://softuni.org/code-lessons/java-basics-tutorial-part-3-input-and-output/ https://softuni.org/code-lessons/java-basics-tutorial-part-3-input-and-output/#respond Tue, 19 Oct 2021 11:06:22 +0000 https://softuni.org/?p=8017 Learn how to process console input and output in Java, how to read text and numbers and how to print formatted text and integers and floating-point values on the console.

The post Java Basics Tutorial – Part 3 – Console-Based Input and Output appeared first on SoftUni Global.

]]>

In this lesson, Svetlin Nakov teaches how to read and work with console-based input and output. Learn how to read strings and numbers from the standard input and how to format and print text, numbers and other data to the standard output.

Svetlin Nakov demonstrates several ways to use a console for user input and output in Java. Learn how to use the console API in Java: java.util.Scanner, System.in, System.out and System.out.print(), System.out.print() and System.out.printf() with placeholders.

As you know, our free code lessons are not just video tutorials. They combine videos with many live examples and practical hands-on exercises, where you write code after each lesson. So, you learn Java coding through practice: by writing Java code. And you send your code to our online judge system, and you get an instant automated grading.

Remember that coding is a skill, which should be practiced. To learn to code, you should write code, every day, for a long time. Watching tutorials is not enough. You should code! Now it’s your turn. Do your exercises!

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 3 – Console-Based Input and Output appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-3-input-and-output/feed/ 0
Java Basics Tutorial – Part 2 – IntelliJ IDEA https://softuni.org/code-lessons/java-basics-tutorial-part-2-intellij-idea/ https://softuni.org/code-lessons/java-basics-tutorial-part-2-intellij-idea/#respond Tue, 12 Oct 2021 13:39:00 +0000 https://softuni.org/?p=6741 Learn about development environments (IDE) and JDK and how to install and use IntelliJ IDEA to create Java projects, write Java code, and compile, run and debug Java projects.

The post Java Basics Tutorial – Part 2 – IntelliJ IDEA appeared first on SoftUni Global.

]]>

In this lesson, Svetlin Nakov talks about development environments (IDEs), which are used by developers to write, compile, run and debug code. He will teach you how to use IntelliJ IDEA, the most popular IDE for Java developers. He will show you how to install JDK (Java development kit), how to install and run IntelliJ IDEA, how to create a console-based app, how to write code, how to use the auto-complete to speed up coding, how to run your programs and even how to debug your code.

What is IDE: “integrated development environment“, or just coding environment? How it helps writing code, compiling and running the code, and debugging (which means to step through the code line by line). Learn from the video lesson.

In the video Nakov will show you how to create new Java project, choose the project type, give a name for the project, create a class with a “main” method, write some code in it, and finally, run the project.

As you know, our free code lessons are not just video tutorials. They combine  videos with many live examples and practical hands-on exercises, where you write code after each lesson. So, you learn Java coding through practice: by writing Java code. And you send your code to our online judge system, and you get an automated grading.

Remember that coding is a skill, which should be practiced. To learn coding, you should write code, every day, for a long time. Watching tutorials is not enough. You should code! Now it’s your turn. Do your exercises!

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 2 – IntelliJ IDEA appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-2-intellij-idea/feed/ 0
Java Basics Tutorial – Part 1 – Getting Started with Java https://softuni.org/code-lessons/java-basics-tutorial-part-1-getting-started-with-java/ https://softuni.org/code-lessons/java-basics-tutorial-part-1-getting-started-with-java/#comments Wed, 06 Oct 2021 13:16:25 +0000 https://softuni.org/?p=6724 This code lesson teaches the first steps in coding with Java: writing code commands, running the code, writing Java programs. It comes with practical exercises with automated grading.

The post Java Basics Tutorial – Part 1 – Getting Started with Java appeared first on SoftUni Global.

]]>

Welcome to Nakov’s free code lessons at the SoftUni Global Community.

Today we shall start with a simple tutorial for Java programming for absolute beginners. This will be the first lesson, but it is just a start. In the next few weeks, we will publish a series of free Java lessons, which follow logically one after another, so if you want to learn Java coding, just follow the lessons in the correct order.

In this lesson, Svetlin Nakov explains what is coding, what are commands and what is their syntax in Java. He teaches how to write simple Java commands and Java programs, and how to execute a Java commands and programs.

The lesson includes practical coding exercises, which you should try yourself, because learning to code is only possible through coding.

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Еxercises: Problem Descriptions

Lesson Slides

The post Java Basics Tutorial – Part 1 – Getting Started with Java appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/java-basics-tutorial-part-1-getting-started-with-java/feed/ 2