Be Perfect, Do Perfect, Live Perfect 1 1. What is the meaning of public static void main(string args[])? public keyword is an access modifier which represents visibility, it means it is visible to all. static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create object to invoke the main method. So it saves memory. void is the return type of the method, it means it doesn't return any value. main represents startup of the program. String[] args is used for command line argument. 2. What is a Stream? List different types of streams in Java. A Stream is linked to a physical layer by java I/O system to make input and output operation in java. A stream can be defined as a sequence of data. Java a stream is composed of bytes. It's called a stream because it's like a stream of water that continues to flow Java encapsulates Stream under java.io package. Java defines two types of streams. They are, Byte Stream: It provides a convenient means for handling input and output of byte. Character Stream : It provides a convenient means for handling input and output of characters. Byte Stream Classes Byte stream is defined by using two abstract class at the top of hierarchy, they are InputStream and OutputStream. OutputStream Java application uses an output stream to write data to a destination, it may be a file,an array,peripheral device or socket. InputStream Java application uses an input stream to read data from a source, it may be a file,an array,peripheral device or socket.
Be Perfect, Do Perfect, Live Perfect 2 3. Explain predefine streams in Java? Standard Input This is used to feed the data to user's program and usually a keyboard is used as standard input stream and represented as System.in. Standard Output This is used to output the data produced by the user's program and usually a computer screen is used for standard output stream and represented as System.out. Standard Error This is used to output the error data produced by the user's program and usually a computer screen is used for standard error stream and represented as System.err. 4. Differentiate byte and character streams. Byte streams can read or write the files containing ASCII characters that range from 0 to 255. That is, byte streams can copy the files containing English letters only but not of other languages. Character streams operate on Unicode characters. That is, character streams can read, write and copy the files containing other than English characters. Characters streams can do with English characters also as ASCII code is a subset of Unicode. 5. What is infinite loop in Java? The loop that never terminates is called as infinite loops. Syntax: for(;;)
Be Perfect, Do Perfect, Live Perfect 3 6. What is type conversion? Explain its types. Assigning a value of one type to a variable of another type is known as Type Casting. Automatic type conversion Automatic Type casting take place by JVM automatically. Example : public class Test public static void main(string[] args) int i = 100; long l = i; //no explicit type casting required float f = l; //no explicit type casting required System.out.println("Int value "+i); System.out.println("Long value "+l); System.out.println("Float value "+f); Output : Int value 100 Long value 100 Float value 100.0 Explicit type conversion When you are assigning a larger type value to a variable of smaller type, then you need to perform explicit type casting. public class Test public static void main(string[] args) double d = 100.04; long l = (long)d; //explicit type casting required int i = (int)l; //explicit type casting required
Be Perfect, Do Perfect, Live Perfect 4 System.out.println("Double value "+d); System.out.println("Long value "+l); System.out.println("Int value "+i); Output : Double value 100.04 Long value 100 Int value 100 7. Difference between C++ and Java? Platformindependent Mainly used for C++ is platformdependent. C++ is mainly used for system programming. Java is platform-independent. Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications. Goto C++ supports goto statement. Java doesn't support goto statement. Multiple inheritance Operator Overloading Pointers Compiler and Interpreter C++ supports multiple inheritance. C++ supports operator overloading. C++ supports pointers. You can write pointer program in C++. C++ uses compiler only. Java doesn't support multiple inheritance through class. It can be achieved by interfaces in java. Java doesn't support operator overloading. Java supports pointer internally. But you can't write the pointer program in java. It means java has restricted pointer support in java. Java uses compiler and interpreter both.
Be Perfect, Do Perfect, Live Perfect 5 Call by Value and Call by reference Structure and Union Thread Support Documentation comment Virtual Keyword unsigned right shift >>> Inheritance Tree C++ supports both call by value and call by reference. C++ supports structures and unions. C++ doesn't have built-in support for threads. It relies on third-party libraries for thread support. C++ doesn't support documentation comment. C++ supports virtual keyword so that we can decide whether or not override a function. C++ doesn't support >>> operator. C++ creates a new inheritance tree always. Java supports call by value only. There is no call by reference in java. Java doesn't support structures and unions. Java has built-in thread support. Java supports documentation comment (/**... */) to create documentation for java source code. Java has no virtual keyword. We can override all non-static methods by default. In other words, non-static methods are virtual by default. Java supports unsigned right shift >>> operator that fills zero at the top for the negative numbers. For positive numbers, it works same like >> operator. Java uses single inheritance tree always because all classes are the child of Object class in java. Object class is the root of inheritance tree in java. Note: Kindly read the given first unit notes and refer the previous year question bank.