Home » Posts tagged "Learn Fundamentals of Java" (Page 3)

Learn Fundamentals of Java Programming “Arrays in Java Programming ” Lesson 15

Arrays Previously you learned about variables that are place holders for a single value. Arrays are variables that can hold more than one value, they can hold a list of values of the same type. For example, to store the marks of a student, we used a variable: double marks_obtained = 346; To store the marks of another student, we changed the variable marks_obtained. marks_obtained = 144; By changing marks_obtained, we...
Continue reading »

Learn Fundamentals of Java Programming “The for statement in Java Programming ” Lesson 14

The for statement The for loop is the most widely used Java loop construct. The structure of the Java for statement is as below: for (counter = initial_value ; test_condition ; increment/decrement counter) { statements } Semicolons separate the three parts of a for loop: 1. The initial_value initializes the value of the loop counter. 2. The test_condition tests whether the loop should be executed again. The loop is exited when...
Continue reading »

Learn Fundamentals of Java Programming “The do while statement in Java Programming ” Lesson 13

The do while statement The do while statement evaluates the test after executing the body of a loop. The structure of the Java do-while statement is as below: do { statements } while (expression); Let us write the same program to print the squares of numbers from 1 to 5. This time we will use a do-while loop. The following steps need to be performed. 1. Initialize number = 1 2....
Continue reading »

Learn Fundamentals of Java Programming “Repetition Structures in Java Programming ” Lesson 11

Repetition Structures In real life you often do something repeatedly, for example, consider a task such as reading a book, first you open the book, and then repeatedly – read a page; flip the page – until you get to the end of the book, then close the book. Similarly, when writing programs, you might need to perform the same sequence of statements repeatedly until some condition is met. The ability...
Continue reading »

Learn Fundamentals of Java Programming “The switch Statement in Java Programming ” Lesson 10

The switch Statement The switch statement is used to execute a block of code matching one value out of many possible values. The structure of the Java switch statement is as below: switch (expression) { case constant_1 : statements; break; case constant_2 : statements; break; … … default : statements; break; } Within the switch statement, as you can see, there can be many case statements. The expression is compared with...
Continue reading »

Learn Fundamentals of Java Programming “The if else Statement in Java Programming ” Lesson 9

The if else Statement The if statement in Java lets us execute a block of code depending upon whether an expression evaluates to true or false. The structure of the Java if statement is as below: if (expression) { statements } The expression given in the round brackets after the if keyword, is a condition – an expression constructed using relational and logical operators. If the condition evaluates to true, the...
Continue reading »

Learn Fundamentals of Java Programming “Selection Structures in Java Programming ” Lesson 8

Selection Structures In real life, you often select your actions based on whether a condition is true or not. For example, if it is raining outside, you carry an umbrella, otherwise not. Similarly in a program, you may want to execute a part of the program based on the value of an expression. Java provides two statements – the if else statement and the switch statement for executing a block of...
Continue reading »