Sie sind auf Seite 1von 6

Q) What are the basic features of java ?

Sol)

Platform Independence o The Write-Once-Run-Anywhere ideal has not been achieved (tuning for different platforms usually required), but closer than with other languages.

Object Oriented o Object oriented throughout - no coding outside of class definitions, including main(). o An extensive class library available in the core language packages. Compiler/Interpreter Combo o Code is compiled to bytecodes that are interpreted by a Java virtual machines (JVM) . o This provides portability to any machine for which a virtual machine has been written. o The two steps of compilation and interpretation allow for extensive code checking and improved security. Robust
o

Exception handling built-in, strong type checking (that is, all data must be declared an explicit type), local variables must be initialized.

Several dangerous features of C & C++ eliminated: o No memory pointers o No preprocessor o Array index limit checking

Automatic Memory Management o Automatic garbage collection - memory management handled by JVM. Security o No memory pointers o Programs runs inside the virtual machine sandbox. o Array index limit checking o Code pathologies reduced by bytecode verifier - checks classes after loading class loader - confines objects to unique namespaces. Prevents loading a hacked "java.lang.SecurityManager" class, for example. security manager - determines what resources a class can access such as reading and writing to the local disk. Dynamic Binding o The linking of data and methods to where they are located, is done at run-time.

o o

New classes can be loaded while a program is running. Linking is done on the fly. Even if libraries are recompiled, there is no need to recompile code that uses classes in those libraries. This differs from C++, which uses static binding. This can result in fragile classes for cases where linked code is changed and memory pointers then point to the wrong addresses.

Good Performance o Interpretation of bytecodes slowed performance in early versions, but advanced virtual machines with adaptive and just-in-time compilation and other techniques now typically provide performance up to 50% to 100% the speed of C++ programs. Threading o Lightweight processes, called threads, can easily be spun off to perform multiprocessing. o Can take advantage of multiprocessors where available o Great for multimedia displays. Built-in Networking o Java was designed with networking in mind and comes with many classes to develop sophisticated Internet communications.

Q2) Difference between C,C++ and Java ? Sol) 1)c is a procedure oriented language & c++ is extended object oriented language & java is true ool.c++ is works like a bridge to ool & pol. 2). C is a structured or procedural oriented language. It mainly depends upon the function which is written in structural manner. It does not support in the web application and also C is very difficult to learn compared to C++ and java. 3). C++ is a object oriented language (shortly called as OOPS). In which is mainly depends upon the object(Runtime entity). Compared to C, it is easy to learn. 4). Java is a combination of C and C++. But most of C++ features are added in the Java. The main advantage of java is it supports Web Application. It is robust, distributing and secured language in which C & C++ does not support. And even Java support in Networking where as it is not possible in C or C++. 5) Java doesn't support global variables. C and c++ support global variables. 6) In c++ & c, goto statement is used.But in java it is not possible.

7) C is top to bottom programing langauge,c++ is bottom to top and java is self dependent progreaming language. 8) All C and C++ compilers implement a stage of compilation known as the

preprocessor. Java does not have a preprocessor. Constant data members are used in place of the #define directive and class definitions are used in lieu of the #typedef directive, however there is no substitute for macros. 9) In C and C++, any memory that is allocated on the heap must be explicitly freed by the programmer, Java provides garbage collection, meaning that memory is freed automatically when it is no longer reachable by any references. 10)In C,C++ pointers causes the majority of bugs in C and C++ programs and Have an ability to acess memory does not belong to it. The Java language does not support pointers. Instead, it provides similar functionality by making heavy use of references. Q3)What are advantages of OOP paradigm and Explain its advantages ? Sol). a. OOP provides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface. b. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. c. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.

Q4)What are Objects And Classes ? Sol) A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviors. Java class objects exhibit the properties and behaviors defined by its class. Methods are nothing but members of a class that provide a service for an object or perform some business logic. An object is an instance of a class created using a new operator. The new operator returns a reference to a new instance of a class. This reference can be assigned to a reference variable of the class. The process ofcreating objects from a class is called instantiation. An object encapsulates state and behavior. An object reference provides a handle to an object that is created and stored in memory. In Java, objects can only be manipulated via references, which can be stored in variables.

Q5) Data Abstraction ? Sol) hiding unnecessary data from user details is called abstraction. Example: TV Remote. Buttons are visible. Circuit is not visible.(Hidden). Abstraction is only giving essential details w/o any background information. This is achieved in java by 1) Abstract Class and Interface //We don't know the function implementation of code until unless at run time or we have a information about the class which implementing this Interface or Extends this Abstract Class If we click on this method it directly take us to Interface method not to Class which actually implementing this method. 2) Hiding information by access modifier only give access to required 3) Object - Nothing can be access by Object ref.

Q6)Encapsulation ? Sol) Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding. The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.
public class Computer{ private String sProcessor; public String getProcessor(){ return sProcessor; } public void setProcessor(String sProcessor){ this.sProcessor=sProcessor; } }

Q7)Inheritence , Single, Multiple? Sol) an object is able to inherit characteristics from another object. In more concrete terms, an object is able to pass on its state and behaviors to its children. For inheritance to work the objects need to have characteristics in common with each other. In the relationship between two objects a superclass is

the name given to the class that is being inherited from. In the relationship between two objects a subclass is the name given to the class that is inheriting from the superclass. Inheritance allows programmers to re-use code they've already written. To derive a class in java the keyword extends is used.

Simple Inheritance When a subclass is derived simply from it's parent class then this mechanism is known as simple inheritance. In case of simple inheritance there is only a sub class and it's parent class. It is also called single inheritance
class A { int x; int y; int get(int p, int q){ x=p; y=q; return(0); } void Show(){ System.out.println(x); } } class B extends A{ public static void main(String args[]){ A a = new A(); a.get(5,6); a.Show(); } void display(){ System.out.println("B"); } }

Multilevel Inheritance It is the enhancement of the concept of inheritance. When a subclass is derived from a derived class then this mechanism is known as the multilevel inheritance. The derived class is called the subclass or child class for it's parent class and this parent class works as the child class for it's just above ( parent ) class.
class A { int x; int y; int get(int p, int q){ x=p; y=q; return(0); } void Show(){ System.out.println(x); } } class B extends A{ void Showb(){ System.out.println("B"); } }

class C extends B{ void display(){ System.out.println("C"); } public static void main(String args[]){ A a = new A(); a.get(5,6); a.Show(); } }

Multiple Inheritance The mechanism of inheriting the features of more than one base class into a single class is known as multiple inheritance. Java does not support multiple inheritance but the multiple inheritance can be achieved by using the interface. Q8) Super Keyword ? Sol) The super is java keyword. As the name suggest super is used to access the members of the super class.It is used for two purposes in java. The first use of keyword super is to access the hidden data variables of the super class hidden by the sub class.
<super.member;>

The second use of the keyword super in java is to call super class constructor in the subclass. This functionality can be achieved just by using the following command.
super(param-list);

Das könnte Ihnen auch gefallen