Posts

Showing posts from May, 2014

Concept of access specifiers,Simple programs in java

Access specifiers in java: What are access specifiers:They are keywords that restricts the access of the instance variable(data) and methods within a package,inherited classes or within the class There are basically 4 access specifiers in java: public:Gives access is in the package,other classes,within the class but cannot be accesses in another package.Free access to the variable in the whole project to be summed. private:Most restrictive,can access variable within the class only.Used for saving critical data. protected:Data and methods are access within the classes that are inherited to the current class only and within class access. default:Data and methods are accessible withing your package/project Simple programs in java Program to find the largest between two numbers: Code: class A { public static void main(String args[]) { int a=5; int b=10;           if(a>b)             {            System.out.println("a is greatest");             }    

Control Statements in java

Image
Control Statements in java There are three control statements in java: Selection  statements Iteration statements or looping statements Jump statements Break statement 1.Selection statements: if-else statements switch case statements Which path to choose:your choice 1.if-else statements: With if only: Syntax:if(condition) { statement1; statement2; statement3; statement4; .......... } With if-else statements: Syntax: if(condition) { statement1; statement2; statement3; statement4; .......... } else { statement1; statement2; .......... }  Here condition is a conditional statement containing the condition operators only such as <,>,>=,<=,==,!=. Example:if(age>=18) {//if the age is greater than 18 then print this System.out.println("You are allowed to vote"); } else { System.out.println("Grow up!!wait for some years.."); } Take care of the curly brackets that