Home » Archive by category "Online Computer Education" (Page 5)

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 »

Learn Fundamentals of Java Programming “Control Flow in Java Programming ” Lesson 7

Control Flow Recall, that a program is nothing but a sequence of instructions. Java executes the instructions in sequential order, that is, one after the other. However, sometimes you might want to execute an instruction only if a condition holds true. Or you may want to execute a set of instructions repeatedly until a condition is met. Java provides selection structures for the former and repetition structures for the latter.
Continue reading »

Learn Fundamentals of Java Programming “Operators in Java Programming ” Lesson 6

Operators Operators are special symbols in a programming language and perform certain specific operations. You have already seen two operator * and /. Table 2 lists the Java Arithmetic operators, Table 3 lists the Relational operators, Table 4 lists the Assignment operators, and Table 5 lists the Logical operators available in Java. Java also provides Bitwise operators which are beyond the scope of this text.
Continue reading »

Learn Fundamentals of Java Programming “String Variables in Java Programming ” Lesson 5

String Variables In the Percentage Calculator program of the previous section, we used variables to store numeric data. Quite often we want variables to store textual data, for example, the name of a student. A variable of the primitive data type char can be used to store a single character. To assign a value to a char variable we enclose the character between single quotes. char middle_name = ‘M’; To store...
Continue reading »

Learn Fundamentals of Java Programming “Primitive Data Types in Java Programming ” Lesson 4

Primitive Data Types Besides the two Java data types (int, double) that you have seen in the percentage calculator program, we can use six more data types. In all, Java supports eight primitive data types as in Table 1. STYLE TIP – Variable Names 1. Variable names can begin with either an alphabetic character, an underscore (_), or a dollar sign ($). However, convention is to begin a variable name with...
Continue reading »