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

Learn Fundamentals of Java Programming “Constructors in Java Programming ” Lesson 19

Constructors A data member that is declared but not initialized before using, is assigned a default value by the compiler usually either zero or null. However, it is good programming practice to always initialize variables before using them. A special method member called the constructor method is used to initialize the data members of the class (or any other initialization is to be done at time of object creation). The constructor...
Continue reading »

Learn Fundamentals of Java Programming “Object Oriented Programming in Java Programming ” Lesson 17

Object Oriented Programming By now you know quite a bit of Java programming. Now we begin to look at Java’s most fundamental feature – Classes and Objects. Java is an Object Oriented Programming (OOP) language. In an OOP language, a program is collection of objects that interact with other objects to solve a problem. Each object is an instance of a class. Imagine you are creating a database application for a...
Continue reading »

Learn Fundamentals of Java Programming “User Defined Methods in Java Programming ” Lesson 16

User Defined Methods A method in Java is a block of statements grouped together to perform a specific task. A method has a name, a return type, an optional list of parameters, and a body. The structure of a Java method is as below: return_type method_name(list of parameters separated by commas) { statements return statement } The method name is a word followed by round brackets. The parameter list placed within...
Continue reading »

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 »