×
SET SOME GOALS. STAY QUIET ABOUT THEM. SMASH THE HELL OUT OF THEM. CLAP FOR YOUR DAMN SELF.
--Your friends at LectureNotes
Close

Core Java

by Trishaank Kumar
Type: PracticalCourse: B.Tech Specialization: Computer Science EngineeringViews: 18Uploaded: 7 months agoAdd to Favourite

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Trishaank Kumar
Trishaank Kumar
Durgasoftwaresolutions Mr.Ratan 3) Documentation Comments:- This comment is used to provide description about our program in more than one page. In general we are using document comment to prepare API kind of documents but it is not sujastable. Syntax: - /*…………….line-1 *……………..line-2 *………………line-3 */ Ex:-/*project name:-green project team size:6 team lead:- ratan */ class Test { //main method public static void main(String[] args) { //printing statement System.out.println("ratan"); } }; java Statements:Java statements Selection Statements Iteration statements if if-else switch 21 | P a g e while do-while for Transfer statement break continue return try
Durgasoftwaresolutions If syntax:if (condition) { if body; } The curly brasses are optional whenever we are taking single statements. The curly brasses are mandatory whenever we are taking multiple statements. Ex 1:class Test { public static void main(String[] args) { int a=10; if (a>5) { System.out.println("if body / true body"); } } } Ex 2:class Test { public static void main(String[] args) { if (true) { System.out.println("if body / true body"); } System.out.println("hi rattaiah"); } } Ex 3:class Test { public static void main(String[] args) { if (false) { System.out.println("if body / true body"); } System.out.println("hi rattaiah"); } } 22 | P a g e Mr.Ratan
Durgasoftwaresolutions Ex 4:-good in c-language but in java we are getting compilation error class Test { public static void main(String[] args) { if (0) { System.out.println("if body / true body"); } System.out.println("hi rattaiah"); } } If-else syntax:if (condition) { if body;(true body) } else { else body;(false body) } The curly brasses are optional whenever we are taking single statements. The curly brasses are mandatory whenever we are taking multiple statements. Ex:class Test { public static void main(String[] args) { int a=10; int b=20; if (a<b) { System.out.println("if body / true body"); } else { System.out.println("else body/false body "); } System.out.println("hi rattaiah"); } } 23 | P a g e Mr.Ratan
Durgasoftwaresolutions Mr.Ratan Switch statement:1) Switch statement is used to take multiple selections. 2) Curly brasses are mandatory if we are not taking we are getting compilation error. 3) Inside the switch It is possible to declare any number of cases but is possible to declare only one default. 4) Switch is taking the argument the allowed arguments are a. Byte b. Short c. Int d. Char e. String(allowed in 1.7 version) 5) Float and double and long is not allowed for a switch argument because these are having more number of possibilities (float and double is having infinity number of possibilities) hence inside the switch statement it is not possible to provide float and double and long as a argument. 6) If the case is matched particular case will be executed if there is no case is matched default case is executed. Syntax:switch(argument) { Case label1 : sop(“ “); break; Case label2 : sop(“ “); break; | | Default } 24 | P a g e | | : sop(“ “); break;

Lecture Notes