Initialization;
while (test expression)
{
body of the loop
}
where the test expression is the conditional state which executes the body of the loop if it returns the true value and terminates once the value returned for the test condition is false. It acts as an entry controlled loop and the given test expression is evaluated at every execution of the body of the loop.
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
Do While Statement of JAVA
This format of the WHILE statement is an exit controlled iteration statement. In this the condition which is to be checked lies at the end of the execution statement/statements and is hence executed at least once no matter the conditon is met or not. It has the following format :
do
{
body of the loop
}
while (test expression);
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
FOR LOOP IN JAVA
This acts as an automatic looping statement with all the control elements/conditions placed in one place. It is equivalent to the FOR/NEXT of BASIC high-level language.
It has the following format :
for (initialization expression;testexpression;update expression)
{
loop body
}
It starts with the keyword for, followed by parentheses that contains three expressions separated by semicolons. eg. for (s=1;j<11;j++) The above segment assigns the loop variable s by 1, the test condition is j<11 and the increment expression is j++. The loop executes for 10 times, with the value of s ranging from 1 to 10.
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
VISIBILITY LABELS/ ACCESS
MODIFIERS
The visibility labels are of two major types viz. public and private. The method or a variable with modifier public is accessible wherever the program has access to an object. Any instance variable or method declared with class private is accessible only to methods of the class.The instance variable private are accessible to methods of the class. The instance variables are normally declared private and the methods are declared as public.
attention@computerscienceexpertise.com PDF created with pdfFactory Pro trial version www.pdffactory.com
CONSTRUCTORS
A class is a combination of member variables and methods. The member variables are initialized by a constructor. All Java classes have special methods called constructors that are used to initialize a new object of that type.
A constructor is a method with the same name as a class. It is invoked automatically each time an object of that class is initiated. It does not return any value.
Java supports method name overloading, so that a class can have any number of constructors, all of which have the same name. Like other overloaded methods, constructors are differentiated from one another by the number or type of their arguments.
Java Learning Made Easy
Magsimula sa umpisa
