INPUT-OUTPUT OPERATIONS: ======================== INPUT OPERATIONS java.io ==> System.in System.out & System.err ==> Output operations System.out three built-in methods: 1) println() 2) print() 3) printf() Value of a = 123 String Datatype: ================ ==> group of characters which enclosed with double quotes. ex: "string" Syntax for string variable declaration is: String name-data = "value"; name-data.lowercase 1) println() ============ ==> an built-in method from "java.io" package. ==> a module "System.out" Syntax: System.out.println("text"); ==> to print/write/display anything on the screen/console println() can use. ==> println ==> print line Ex: printf("\n"); class outputOperations{ public static void main(String x[]) { int a = 123; byte b = 112; System.out.println(a); System.out.println(b); } } ==> that every definition of println() can reserve with new line by default. Ex: println("hi"); println("hello"); output: ====== hi hello Aspect-1: printing only the text. ========================= class outputOperations{ public static void main(String x[]) { // printing of text String s = "Hello"; System.out.println(s); System.out.println("Hi all."); System.out.println("Welcome To Ashok IT."); } } class outputOperations{ public static void main(String x[]) { // printing of multiple strings using single println() String s1 = "Hi all"; String s2 = "Welcome To Ashok IT"; System.out.println(s1 + " " + s2); } } Aspect-2: ========= the text along with result sample-op: Hi, my name is ravi. value of a = 123 and value of b = 112 String Concatenation: ==================== ==> Joining of two or more strings into one unit is called as "String concatenation". ==> Symbol: + Syntax: str1 + str2 Rules: ====== 1) String with number (Integral/float) number + string string + number string1 + number + string2 class outputOperations{ public static void main(String x[]) { // concatenation of string with number String name = "Raju"; int age = 23; System.out.println("Hi" + " " + "I am " + name + ".I am " + age + " years of old."); } } ====================================== 2) print() ========== which can use to write/print anything on the screen/console. ==> with multiple print() definitions, we can get the result with single line. Ex: print("Hi"); print("Ravi"); "HiRavi" ============================= Assignment: =========== WAP to take two integers as an input and print their sum along with inputs. Sample Output: ============== inputs: a = 12 b = 24 Output: Sum of 12 and 24 is = 36. ==================================================== 3) printf() =========== Syntax: System.out.printf() Format Specifiers: ================== int ==> %d/%i long ==> %ld string ==> %s char ==> %c class outputOperations{ public static void main(String x[]) { // text using printf() int n = 123; float f1 = 1.23f; float f2 = 1.223f; System.out.printf("%s","Hello\n"); System.out.printf("Hello"); System.out.printf("The Given Integer value is = %d\n",n); System.out.print("Hi all."+"\n"+"Welcome To Ashok IT."); System.out.print("f1 = "+f1+"\t" + "f2 = "+f2); } } ============================================ Identifiers: ============ Variable: datatype name-of-data = value; ==> a name which we can use to name any entity like: variables, methods, class, objects in the program. Rules for an Identifiers: ========================= 1) Should contains: alphabets : Upper case/Lower case/both 2) should contains: digits: 0 to 9 3) should include: special characters: underscore sign (_) dollar sign ($) ex: abc_12, abc ==> valid identifiers 4) never begin with digit, but it can be begin with: alphabet/_/$ ex: 97abc = 123 ==> Invalid 5) never include: other special characters like: space, .!@ ex: abc@we = 123; ==> Invalid 6) Never define with keywords. Ex: import = 122; ==> Invalid 7) Case Sensitive Ex: ravi (lower case) Ravi (mixed case) RAVI (upper case) 8) no limit in length of an identifier. class Identifiers{ public static void main(String x[]) { byte abc = 127; // short 97abc = 1223; Syntax Error short $_s = 1122; // int abc@we = 112233; // long private = 123l; long PRIVATE = 123l; boolean bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = true; System.out.println(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); } }