23-12-24 ---------- Q)What is meant by defining a variable? =>Within a single statement if variable delcaration and initialization happens, it is known as defining a variable. For eg. int a=10;//defining a variable. Q)What is the output of the following Java application? class Output{ public static void main(String args[]){ int a; System.out.println(a); } } Ans:- The above application causes compilation error. => "a" is a local variable. =>A variable created within a method is known as a local variable. =>Using a local variable without initializing it, is a syntactical error in Java. Q)What is a comment in a Java application? =>Textual description written within the source code of the application that is ignored by the Java compiler is nothing but a comment. =>There are two types of comments in Java. 1)implementation comments 2)documentation comments (used for API creation) =>There are two types of implementation comments. 1)single line comments 2)multi line comments =>Single line comment starts with "//" and ends with the physical line. =>Multi-line comment starts with "/*" and ends with "*/". We can write any number of lines of textual description here. Q)What is a data type? =>data type is the one that specifies the kind of data that can be stored in Computer's memory. =>data type specifies a set of values and a set of operations that can be performed on those values. Q)How are data types classified in Java? 1)Primitive data types(pre-defined/system-defined/fundamental/basic data types) 2)User defined data types. Q)What are the primitive data types in Java? =>To represent numbers, 6 primitive data types are given in Java. 1)byte 2)short 3)int 4)long 5)float 6)double =>To represent integral numbers(without fractioal part) there are 4 primitive data types. 1)byte 2)short 3)int 4)long. =>To represent decimal data (with fractional part) we have 2 data types in Java. 1)float 2)double =>To represent character data, "char" data type is given. =>to represent true/false values "boolean" data type is given. Q)What is the output of the following application? class Output{ public static void main(String args[]){ float s=10.5; System.out.println(s); } } Ans:- The above application cuases compilation error. Reason:- 10.5 is decimal literal. When a decimal literal is used in the source code, Java compiler treats it by default as "double data type". But here, "s" of float type. =>We can fix it as follows. double s=10.5; OR float s=10.5F; OR float s=10.5f;