1.History of JAVA? Many java versions have been released till now. The current stable release of Java is Java SE 10.
JDK Alpha and Beta (1995)
JDK 1.0 (23rd Jan 1996) JDK 1.1 (19th Feb 1997) J2SE 1.2 (8th Dec 1998) J2SE 1.3 (8th May 2000) J2SE 1.4 (6th Feb 2002) J2SE 5.0 (30th Sep 2004) Java SE 6 (11th Dec 2006) Java SE 7 (28th July 2011) Java SE 8 (18th March 2014) Java SE 9 (21st Sep 2017) Java SE 10 (20th March 2018) Codenamed Oak and released on January 23, 1996 JDK Version 1.0 JDK Version 1.1 Features in JDK 1.1 JDBC (Java Database Connectivity) Inner Classes Java Beans RMI (Remote Method Invocation) Reflection (introspection only) 2. J2SE Version 1.2 Code named Playground and released on December 8, 1998 Features in J2SE 1.2 Collections framework. Java String memory map for constants. Just In Time (JIT) compiler. Jar Signer for signing Java ARchive (JAR) files. Policy Tool for granting access to system resources. Java Foundation Classes (JFC) which consists of Swing 1.0, Drag and Drop, and Java 2D class libraries. Java Plug-in Scrollable result sets, BLOB, CLOB, batch update, user-defined types in JDBC. Audio support in Applets. 3. J2SE Version 1.3 Code named Kestrel and released on May 8, 2000. Features in J2SE 1.3 Java Sound Jar Indexing A huge list of enhancements in almost all the java area. 4.J2SE Version 1.4 Code named Merlin and released on February 6, 2002 (first release under JCP). Features in J2SE 1.4 XML Processing Java Print Service Logging API Java Web Start JDBC 3.0 API Assertions Preferences API Chained Exception IPv6 Support Regular Expressions Image I/O API J2SE Version 5.0 Code named Tiger and released on September 30, 2004. Features in J2SE 5.0 Generics Enhanced for Loop Autoboxing/Unboxing Typesafe Enums Varargs Static Import Metadata (Annotations) Instrumentation Java Version SE 6 Code named Mustang and released on December 11, 2006. Features in Java SE 6 Scripting Language Support JDBC 4.0 API Java Compiler API Pluggable Annotations Native PKI, Java GSS, Kerberos and LDAP support. Integrated Web Services. Lot more enhancements. Java Version SE 7 Code named Dolphin and released on July 28, 2011. Features in Java SE 7 Strings in switch Statement Type Inference for Generic Instance Creation Multiple Exception Handling Support for Dynamic Languages Try with Resources Java nio Package Binary Literals, underscore in literals Diamond Syntax Automatic null Handling Java SE 8 Java 8 was released on 18 March 2014. The code name culture is dropped with Java 8 and so no official code name going forward from Java 8. Features in Java SE 8 Lambda Expressions Pipelines and Streams Date and Time API Default Methods Type Annotations Nashhorn JavaScript Engine Concurrent Accumulators Parallel operations PermGen Error Removed TLS SNI 2.Difference between JDK, JRE, JVM, JIT? Java Virtual Machine (JVM) is an abstract computing machine. Java Runtime Environment (JRE) is an implementation of the JVM. Java Development Kit (JDK) contains JRE along with various development tools like Java libraries, Java source compilers, Java debuggers, bundling and deployment tools. Just in Time compiler (JIT) is runs after the program has started executing, on the fly. It has access to runtime information and makes optimizations of the code for better performance. 3.What is the role of JIT in JVM? The JIT compiler helps improve the performance of Java programs by compiling bytecodes into native machine code at run time. The JIT compiler is enabled by default. When a method has been compiled, the JVM calls the compiled code of that method directly instead of interpreting it. 4.What is program Arguments? Command Line Argument is information passed to the program when you run the program. The passed information is stored as a string array in the main method Command Line Arguments can be used to specify configuration information while launching your application. There is no restriction on the number of java command line arguments. You can specify any number of arguments Information is passed as Strings. They are captured into the String args of your main method Arguments class CommandLineExample{ public static void main (String args[]){ System.out.println("Your first argument is: "+args[0]); } }
5.What is Copy Constructor?
There is no copy constructor in Java. However, we can copy the values from one object to another like copy constructor in C++. There are many ways to copy the values of one object into another in Java. They are: By constructor By assigning the values of one object into another By clone () method of Object class 6.Explain about Constructor Overloading? Constructor overloading in Java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types. 7.Is possible static constructor in Java? Java does not permit to declare a constructor as static. Following are the reasons. Static means for the same class. For example, static methods cannot be inherited. With static, "this" reference (keyword) cannot be used. "this" is always linked to an object. A constructor always belongs to some object. If a constructor is static, an object of subclass cannot access. If static is allowed with constructor, it is accessible within the class but not by subclass. 8.Difference between Abstract class and Interface? Abstract class Interface Abstract class can have abstract and non- Interface can have only abstract methods. abstract methods. Since Java 8, it can have default and static methods also. Abstract class doesn't support multiple Interface supports multiple inheritance. inheritance. Abstract class can have final, non-final, static Interface has only static and final variables. and non-static variables. Abstract class can provide the implementation Interface can't provide the implementation of of interface. abstract class. The abstract keyword is used to declare The interface keyword is used to declare abstract class. interface. An abstract class can extend another Java An interface can extend another Java interface class and implement multiple Java interfaces. only. An abstract class can be extended using An interface can be implemented using keyword "extends". keyword "implements". A Java abstract class can have class members Members of a Java interface are public by like private, protected, etc. default.
9.Explain about Diamond Problems?
This leads to the ambiguity as the compiler doesn't know which superclass method to execute. Because of the diamond-shaped class diagram, it's referred to as Diamond Problem in java. The diamond problem in Java is the main reason java doesn't support multiple inheritances in classes.
10.Can we define a constructor in abstract class?
Yes, an abstract class can have a constructor. When we define a class to be an Abstract Class it cannot be instantiated but that does not mean an Abstract class cannot have a constructor. Each abstract class must have a concrete subclass which will implement the abstract methods of that abstract class. Hence, we can have a constructor in abstract classes. 11.Explore about Static Block? Static block is used for initializing the static variables. This block gets executed when the class is loaded in the memory. A class can have multiple Static blocks, which will execute in the same sequence in which they have been written into the program. Single static block Multiple Static blocks
12.Difference between Overloading and Overriding?
Method Overloading Method Overriding Method overloading is used to increase the Method overriding is used to provide the readability of the program. specific implementation of the method that is already provided by its super class. Method overloading is performed within Method overriding occurs in two classes that class. have IS-A (inheritance) relationship. In case of method overloading, parameter In case of method overriding, parameter must must be different. be same. Method overloading is the example of Method overriding is the example of run time compile time polymorphism. polymorphism. In java, method overloading can't be Return type must be same or covariant in performed by changing return type of the method overriding. method only. Return type can be same or different in method overloading. But you must have to change the parameter. 13.How to implement overloading and overriding in Java? Method Overloading: Same as constructors, Conditions for method overloading are: 1. Methods to be overloaded must have the same name. 2. All methods must have different arguments (either different number of parameters or different type of parameters). Method Overriding: Conditions for Method Overriding Methods of both parent and child class must have the same name. Methods must have the same argument list and return type. A method declared static cannot be overridden. If a method cannot be inherited, it cannot be overridden. 14.Types of class in Java? Java supports three types of classes. Concrete classes Abstract classes Concrete classes: A concrete class is a class that has an implementation for all of its methods. They cannot have any unimplemented methods. It can also extend an abstract class or implement an interface as long as it implements all their methods. Abstract classes: Abstract class in Java is similar to interface except that it can contain default method implementation. An abstract class can have an abstract method without body, and it can have methods with implementation also. abstract keyword is used to create a abstract class and method. 15.How to stop the inheritance features of class? Use final. Use private constructors. Use a comment: // do not inherit. Use a javadoc comment. Make every method final, so people can't override them. Use a runtime check in the class constructor: if (this. getClass() != MyClass. class) {throw new RuntimeException("Subclasses not allowed"); } 16.How to stop the overriding of the function? We can prevent method overriding in java in 3 ways By making method final in Base class By making method static in Base class By making method private in Base class 17.Is Constructor Overloading is possible? Yes, we can overload constructors in java.Constructor is just like a method but without return type. It can also be overloaded like Java methods. Constructor overloading in Java is a technique of having more than one constructor with different parameter lists. They are arranged in a way that each constructor performs a different task. They are differentiated by the compiler by the number of parameters in the list and their types. 18.Properties in Java? The properties object contains key and value pair both as a string. The java.util.Properties class is the subclass of Hashtable. It can be used to get property value based on the property key. The Properties class provides methods to get data from the properties file and store data into the properties file. Moreover, it can be used to get the properties of a system. 19.How to make property as read only? To make a file read only in java, you can use one of below methods. 3rd method using Runtime.getRuntime().exec () is platform specific because of command you pass to it as parameter. Rest two methods will work fine in most cases. 1) Use java.io.File.setReadOnly() method 2) Use java.io.File.setWritable(false) method 3) Execute a native command (platform dependent)
20.Log Files in Java?
Logging helps a programmer in the debugging process of a program. Java provides logging facility in the java.util.logging package. The package consists of a set of classes and interfaces which are used in logging. The System uses a Logger object to log messages The need for Log Files: Recording unusual circumstances or errors that may be happening in the program Getting the info about what’s going in the application