Содержание
- 2. Topics Covered Data Types Operators Control Statements Variables & Arrays String Handling The String Constructors String
- 3. Data Types Data types specify the different sizes and values that can be stored in the
- 5. Operators in Java Operator in Java is a symbol that is used to perform operations. Java
- 6. Arithmetic Operator Arithmetic operators are used to perform common mathematical operations.
- 7. Comparison operators comparison operators are used to compare two values
- 8. Assignment operators Assignment operators are used to assign values to variables For example, we use the
- 9. Logical operators Logical operators are used to determine the logic between variables or values
- 10. Conditional operators Consider this example Int a=30; Int b=40; In x=(a>b)?a:b;
- 11. Control Statements There are three types of control flow statements. Conditional statements: based on particular condition
- 12. Control Statement Conditional statements If Statement To take only one option Syntax of if statement is
- 13. Example of “if” statement Program 1 class Student { public static void main(String[] args) { int
- 14. Control Statement Decision-Making statements “if-else” statement Two option available. The if-else statement is an extension to
- 15. Example of “if else” statement Program 2 class Student { public static void main(String[] args) {
- 16. Control Statement Decision-Making statements “if-else-if” statement The if-else-if statement contains the if-statement followed by multiple else-if
- 17. Example of “if else if” statement Program 3 class Positive { public static void main(String[] args)
- 18. Example of “if else if” statement Program 3 class Sleep { public static void main(String[] args)
- 19. Control Statement Decision-Making statements switch statement The Java switch statement executes one statement from multiple conditions.
- 20. The syntax to use the switch switch(argument){ case value1: Statements; break; //optional case value2: Statements; break;
- 21. Example of “Switch” statement Program 5 EX: class SwitchExample { public static void main(String[] args) {
- 22. Loop Statements Loop statements: The same code will be Repeated multiple times for while do-while
- 23. Loop Statements for In Java, for loop is similar to C and C++ It enables us
- 24. Example of “for loop” Program 5 class Test { public static void main(String[] args) { for(int
- 25. Loop Statements While The while loop is also used to iterate over the number of statements
- 26. Example of “while” Program 6 class Test { public static void main(String[] args) { // for
- 27. Loop Statements do While If you want execute the body first without condition check then use
- 28. Loop Statements do While Ex: class Test { public static void main(String[] args) { do {
- 29. Jump Statement Jump statements are used to transfer the control of the program to the specific
- 30. Jump Statement
- 31. Variables in JAVA A variables are used to store the values by using that value we
- 32. Variables in JAVA 1) Local Variable A variable declared inside the method is called local variable.
- 33. 2) Instance Variable A variable declared inside the class but outside the method. Accessing done through
- 34. 3) Static variable A variable that is declared as static is called a static variable. Memory
- 35. Example of “Variables” Program 9 EX: class variable { int a=10;//instance variable static int b=10;//static variable
- 36. ARRAY in JAVA Arrays are used to store the group of elements and these elements are
- 37. EX: class Test { int[] a={10,20,30,40}; public static void main(String args[]) { System.out.println(a[0]); System.out.println(b[1]); System.out.println(c[2]); System.out.println(d[3]);
- 38. Advantages Code Optimization: It makes the code optimized, we can retrieve or sort the data efficiently.
- 39. String in JAVA Generally, String is a sequence of characters. But in Java, string is an
- 40. Example of “String” Program 10 public class StringExample{ public static void main(String args[]){ String s1="java";//creating string
- 41. String Handling The Java String class length() method finds the length of a string. The length
- 42. Special String Operations There are 4 types of special string Operations String Literals String Concatenation String
- 43. You can concatenate strings with other types of data. For example int age = 9; String
- 44. String Handling Character Extraction String is treated as an object in Java so we can’t directly
- 45. Example of “Character Extraction” Program 11 class temp { public static void main(String...s) { String str="Hello";
- 46. String Comparison We can compare String in Java on the basis of content a It is
- 47. Example of “String Comparision” Program 12 class Teststringcomparison1{ public static void main(String args[]){ String s1="Sachin"; String
- 48. Modifying a String Methods for modifying a String objects. substring() susubstring(int beginIndex) bstring(int beginIndex, int endIndex)
- 49. StringBuffer A string buffer is like a String, but can be modified append() insert() replace() delete()
- 50. Example of “String Buffer” Program 13 StringBuffer Class append() Method class StringBufferExample1{ public static void main(String
- 51. StringBuffer insert() Method class StringBufferExample2{ public static void main(String args[]){ StringBuffer sb=new StringBuffer("Hello "); sb.insert(1,"Java");//now original
- 52. StringBuffer replace() Method class StringBufferExample3{ public static void main(String args[]){ StringBuffer sb=new StringBuffer("Hello"); sb.replace(1,3,"Java"); System.out.println(sb);//prints HJavalo
- 53. StringBuffer delete() Method class StringBufferExample4{ public static void main(String args[]){ StringBuffer sb=new StringBuffer("Hello"); sb.delete(1,3); System.out.println(sb);//prints Hlo
- 54. StringBuffer capacity() Method class StringBufferExample5{ public static void main(String args[]){ StringBuffer sb=new StringBuffer(); System.out.println(sb.capacity());//default 16 sb.append("Hello");
- 55. StringBuffer reverse() Method class StringBufferExample6{ public static void main(String args[]){ StringBuffer sb=new StringBuffer("Hello"); sb.reverse(); System.out.println(sb);//prints olleH
- 57. Скачать презентацию