Home »
Archive by category "Online Computer Education" (Page 4)
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 »
February 29, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Class Design We are now ready to create a class in Java. A class in Java begins with the keyword class followed by the name of the class. The body of the class is enclosed within curly braces. The body contains the definitions of the data and method members of the class. The data members are defined by specifying their type. The method members of the class are defined just like...
Continue reading »
February 29, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
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 »
February 29, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
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 »
February 29, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
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 »
February 29, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
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 »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
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 »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
The while statement The while statement evaluates the test before executing the body of a loop. The structure of the Java while statement is as below: while (expression) { statements } Let us write a program to print the squares of numbers from 1 to 5. The following steps need to be performed. 1. Initialize number = 1 2. Test if the number <= 5 3. If yes, print the square...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Page 4 of 13« Prev
1
2
3
4
5
6
7
…
13
Next »