Language features
Is Java a fully object oriented language?
A: Java is an object oriented language, but there is no standard that defines a "fully" object oriented language, it is a matter of definition and opinion
What are Java types are available?
A: There are two main divisions of data types in Java: object and primitive types. Object types are declared according to their class.
Object object = new Object();
Objects can also be cast to a more general superclass or interface type. This is known as polymorphism, which means the object behaves like, and can be treated as, an instance of the more general type.
// Type cast
Object object = new StringBuffer("Example");
// Interface
Comparable object = new File("c:\Example.txt");
What's the difference between the Java versions?
A: The major release versions of the Sun Java Software Development Kit (SDK, also known as the JDK) include significant API changes that provide extra programming features built upon the core Java software platform. That means that the basic features of the Java language do not change from one release to the next, so most existing programs will run successfully when compiled with the new SDK.
Some core packages may gain additional features in new Java releases, but it is very rare for established API features to be removed, which would break backwards compatibility. Superseded or problematic API methods are usually marked deprecated before they are removed altogether, to give programmers the chance to upgrade their code to the new standard. Deprecated classes and methods can still be used to develop and run Java programs, but the compiler will issue warnings.
What is the return type in Java?
A: All Java methods must declare a return type, which may be an object reference, primitive value or void. The void return declaration means that no value is returned, control is simply returned to the calling class. Methods with non-void return types must ensure that the appropriate object reference or primitive value is returned when the method completes. The method return value is like a message and often represents a property of the object, the product of a calculation or algorithm or a text output for instance.
What's the difference between checked and un-checked exceptions?
A: A Java checked exception represents a problematic case that can be anticipated when one instantiates an object or calls a method. A typical example is when you attempt to create a file or open a URL connection, which may fail for many reasons. Checked exceptions must be declared in the throws statement of a method header, and any class that calls the method must ensure that it handles all checked exceptions that may occur.
What is dynamic method dispatch?
A: Dynamic method dispatch is the process the Java runtime system uses to determine which method implementation to call in an inheritance hierarchy. For example, the Object class has a toString() method that all subclasses inherit, but the String class overrides this method to return its string content. If a String or other object type is assigned to an Object reference using application logic, the Java compiler cannot know in advance where a call to the toString() method will be resolved, it must be determined dynamically at runtime.
No comments:
Post a Comment