+ Reply to Thread
Results 1 to 9 of 9

Thread: Practice Question in JAVA

  1. #1
    Moderator
    Join Date
    Feb 2006
    Posts
    1,411
    Rep Power
    24
    hello



    answer the following questions which wd be helpfull for java
    beginers /freshers.. Initially lets start with knowing simple fundas ..
    then we will also give practise examples later.





    1 What is the difference between procedural and
    object-oriented programs?
    -


    2 What is the difference between C++ and JAVA?


    3
    what is Object Oriented Programming Language Whats are its major
    benifits when compared to other languages like c, c++, .net? What are
    its disadvantages or limitations too?


    4 What is object and how do u allocate memory to it?


    5 What is the difference between METHODS and CONSTRUCTORS?




    Regards



    Suresh Kumar Team




    http://livetolead.blogspot.com/
    all the best
    Arise Awake N Stop Not Until Ur Goal Is Reached!

  2. #2
    Moderator
    Join Date
    Feb 2006
    Posts
    1,411
    Rep Power
    24
    hello

    1 What is the difference between procedural and
    object-oriented programs?
    -



    a) In procedural program,
    programming logic follows certain procedures and the instructions are executed
    one after another. In OOP program, unit of program is object, which is nothing
    but combination of data and code.

    b) In procedural program, data is exposed to
    the whole program whereas in OOPs program, it is accessible with in the object
    and which in turn assures the security of the code.




    http://livetolead.blogspot.com/
    all the best
    Arise Awake N Stop Not Until Ur Goal Is Reached!

  3. #3
    Moderator
    Join Date
    Feb 2006
    Posts
    1,411
    Rep Power
    24
    hello



    Procedural Programming

    Procedural programming
    separates the data of the program from the operations that manipulate
    the data. For example, if you want to send information across a
    network, only the relevant data is sent (see Figure 1), with the
    expectation that the program at the other end of the network pipe knows
    what to do with it. In other words, some sort of handshaking agreement
    must be in place between the client and server to transmit the data. In
    this model, no code is actually sent over the wire.



    OOP

    The fundamental
    advantage of OO programming is that the data and the operations that
    manipulate the data (the code) are both encapsulated in the object. For
    example, when an object is transported across a network, the entire
    object, including the data and behavior, goes with it.



    bye






    http://livetolead.blogspot.com/
    all the best
    Arise Awake N Stop Not Until Ur Goal Is Reached!

  4. #4
    Moderator
    Join Date
    Feb 2006
    Posts
    1,411
    Rep Power
    24
    hello



    What is object and how do u allocate memory to it?



    Object is the instance of class .. u allocate memory thru new operator






    http://livetolead.blogspot.com/
    all the best
    Arise Awake N Stop Not Until Ur Goal Is Reached!

  5. #5
    Moderator
    Join Date
    Feb 2006
    Posts
    1,411
    Rep Power
    24
    hello



    5 What is the difference between METHODS and CONSTRUCTORS?



    A
    constructor is a member function of a class
    that is used to create objects of that class.
    It has the same name as the class itself,
    has no return type, and is invoked using
    the new operator.

    A method is an ordinary member function
    of a class. It has its own name, a return
    type (which may be void), and is invoked
    using the dot operator.


    http://livetolead.blogspot.com/
    all the best
    Arise Awake N Stop Not Until Ur Goal Is Reached!

  6. #6
    Moderator
    Join Date
    Feb 2006
    Posts
    1,411
    Rep Power
    24
    HELLO



    Similarities and Differences C++ AND JAVA





    This list of similarities and differences is based heavily on The Java Language Environment, A White Paper by James Gosling and Henry McGilton http://java.sun.com/doc/language_environment/ and the soon-to-be published book, Thinking in Java
    by Bruce Eckel, http://www.EckelObjects.com/. At least these were the
    correct URLs at one point in time. Be aware, however, that the web is a
    dynamic environment and the URLs may change in the future.



    Java does not support typedefs, defines, or a preprocessor. Without a preprocessor, there are no provisions for including header files.



    Since Java does not have a preprocessor there is no concept of #define macros or manifest constants. However, the declaration of named constants is supported in Java through use of the final keyword.



    Java does not support enums but, as mentioned above, does support named constants.



    Java supports classes, but does not support structures or unions.



    All stand-alone C++ programs require a function named main and can have numerous other functions, including both stand-alone functions and functions, which are members of a class. There are no stand-alone functions in Java. Instead, there are only functions that are members of a class, usually called methods. Global functions and global data are not allowed in Java.



    All classes in Java ultimately inherit from the Object class.
    This is significantly different from C++ where it is possible to create
    inheritance trees that are completely unrelated to one another.



    All function or method definitions in Java are contained within the class definition. To a C++ programmer, they may look like inline function definitions, but they aren't. Java doesn't allow the programmer to request that a function be made inline, at least not directly.



    Both C++ and Java support class (static) methods or functions that can be called without the requirement to instantiate an object of the class.



    The interface keyword in Java is used to create the
    equivalence of an abstract base class containing only method
    declarations and constants. No variable data members or method
    definitions are allowed. (True abstract base classes can also be
    created in Java.) The interface concept is not supported by C++.



    Java does not support multiple inheritance. To some extent, the interface feature provides the desirable features of multiple inheritance to a Java program without some of the underlying problems.



    While Java does not support multiple inheritance, single inheritance
    in Java is similar to C++, but the manner in which you implement
    inheritance differs significantly, especially with respect to the use
    of constructors in the inheritance chain.



    In addition to the access specifiers applied to individual members
    of a class, C++ allows you to provide an additional access specifier
    when inheriting from a class. This latter concept is not supported by
    Java.



    Java does not support the goto statement (but goto is a reserved word). However, it does support labeled break and continue statements, a feature not supported by C++. In certain restricted situations, labeled break and continue statements can be used where a goto statement might otherwise be used.



    Java does not support operator overloading.



    Java does not support automatic type conversions (except where guaranteed safe).



    Unlike C++, Java has a String type, and objects of this type are immutable (cannot be modified). Quoted strings are automatically converted into String objects. Java also has a StringBuffer type. Objects of this type can be modified, and a variety of string manipulation methods are provided.



    Unlike C++, Java provides true arrays as first-class objects. There is a length
    member, which tells you how big the array is. An exception is thrown if
    you attempt to access an array out of bounds. All arrays are
    instantiated in dynamic memory and assignment of one array to another
    is allowed. However, when you make such an assignment, you simply have
    two references to the same array. Changing the value of an element in
    the array using one of the references changes the value insofar as both
    references are concerned.



    Unlike C++, having two "pointers" or references to the same object
    in dynamic memory is not necessarily a problem (but it can result in
    somewhat confusing results). In Java, dynamic memory is reclaimed
    automatically, but is not reclaimed until all references to that memory
    become NULL or cease to exist. Therefore, unlike in C++, the allocated
    dynamic memory cannot become invalid for as long as it is being
    referenced by any reference variable.



    Java does not support pointers (at least it does not allow
    you to modify the address contained in a pointer or to perform pointer
    arithmetic). Much of the need for pointers was eliminated by providing
    types for arrays and strings. For example, the oft-used C++ declaration
    char* ptr needed to point to the first character in a
    C++ null-terminated "string" is not required in Java, because a string
    is a true object in Java.



    A class definition in Java looks similar to a class definition in C++, but there is no closing semicolon. Also forward reference declarations that are sometimes required in C++ are not required in Java.



    The scope resolution operator (::) required in C++ is not
    used in Java. The dot is used to construct all fully-qualified
    references. Also, since there are no pointers, the pointer operator (->) used in C++ is not required in Java.



    In C++, static data members and functions are called using
    the name of the class and the name of the static member connected by
    the scope resolution operator. In Java, the dot is used for this
    purpose.



    Like C++, Java has primitive types such as int, float, etc.
    Unlike C++, the size of each primitive type is the same regardless of
    the platform. There is no unsigned integer type in Java. Type checking
    and type requirements are much tighter in Java than in C++.



    Unlike C++, Java provides a true boolean type.



    Conditional expressions in Java must evaluate to boolean rather than to integer, as is the case in C++. Statements such as if(x+y)... are not allowed in Java because the conditional expression doesn't evaluate to a boolean.



    The char type in C++ is an 8-bit type that maps to the ASCII (or extended ASCII) character set. The char
    type in Java is a 16-bit type and uses the Unicode character set (the
    Unicode values from 0 through 127 match the ASCII character set). For
    information on the Unicode character set see
    http://www.stonehand.com/unicode.html.



    Unlike C++, the >> operator in Java is a "signed" right bit
    shift, inserting the sign bit into the vacated bit position. Java adds
    an operator that inserts zeros into the vacated bit positions.



    C++ allows the instantiation of variables or objects of all types
    either at compile time in static memory or at run time using dynamic
    memory. However, Java requires all variables of primitive types to be
    instantiated at compile time, and requires all objects to be
    instantiated in dynamic memory at runtime. Wrapper classes are provided
    for all primitive types except byte and short to allow them to be instantiated as objects in dynamic memory at runtime if needed.



    C++ requires that classes and functions be declared before they are used. This is not necessary in Java.



    The "namespace" issues prevalent in C++ are handled in Java by including everything in a class, and collecting classes into packages.



    C++ requires that you re-declare static data members outside the class. This is not required in Java.



    In C++, unless you specifically initialize variables of primitive
    types, they will contain garbage. Although local variables of primitive
    types can be initialized in the declaration, primitive data members of
    a class cannot be initialized in the class definition in C++.



    In Java, you can initialize primitive data members in the class
    definition. You can also initialize them in the constructor. If you
    fail to initialize them, they will be initialized to zero (or
    equivalent) automatically.



    Like C++, Java supports constructors that may be overloaded. As in
    C++, if you fail to provide a constructor, a default constructor will
    be provided for you. If you provide a constructor, the default
    constructor is not provided automatically.



    All objects in Java are passed by reference, eliminating the need for the copy constructor used in C++.




    (In reality, all parameters are passed by value in Java.
    However, passing a copy of a reference variable makes it possible for code
    in the receiving method to access the object referred to by the variable,
    and possibly to modify the contents of that object. However, code in
    the receiving method cannot cause the original reference variable to refer
    to a different object.)





    There are no destructors in Java. Unused memory is returned to the operating system by way of a garbage collector,
    which runs in a different thread from the main program. This leads to a
    whole host of subtle and extremely important differences between Java
    and C++.



    Like C++, Java allows you to overload functions. However, default arguments are not supported by Java.



    Unlike C++, Java does not support templates. Thus, there are no generic functions or classes.



    Unlike C++, several "data structure" classes are contained in
    the "standard" version of Java. More specifically, they are contained
    in the standard class library that is distributed with the Java
    Development Kit (JDK). For example, the standard version of Java
    provides the containers Vector and Hashtable that can be used to contain any object through recognition that any object isan object of type Object. However, to use these containers, you must perform the appropriate upcasting and downcasting, which may lead to efficiency problems.



    Multithreading is a standard feature of the Java language.



    Although Java uses the same keywords as C++ for access control: private, public, and protected, the interpretation of these keywords is significantly different between Java and C++.



    There is no virtual keyword in Java. All non-static methods always use dynamic binding, so the virtual keyword isn't needed for the same purpose that it is used in C++.



    Java provides the final keyword that can be used to specify that a method cannot be overridden and that it can be statically bound. (The compiler may elect to make it inline in this case.)



    The detailed implementation of the exception handling system in Java is significantly different from that in C++.



    Unlike C++, Java does not support operator overloading. However, the (+) and (+=) operators are automatically overloaded to concatenate strings, and to convert other types to string in the process.



    As in C++, Java applications can call functions written in another language. This is commonly referred to as native methods. However, applets cannot call native methods.



    Unlike C++, Java has built-in support for program documentation.
    Specially written comments can be automatically stripped out using a
    separate program named javadoc to produce program documentation.



    Generally Java is more robust than C++ due to the following:


      [*]Object handles (references) are automatically initialized to null.[*]Handles are checked before accessing, and exceptions are thrown in the event of problems.[*]You cannot access an array out of bounds.[*]Memory leaks are prevented by automatic garbage collection.[/list]


    http://livetolead.blogspot.com/
    all the best
    Arise Awake N Stop Not Until Ur Goal Is Reached!

  7. #7
    Moderator
    Join Date
    Feb 2006
    Posts
    1,411
    Rep Power
    24
    hello



    this can also be the explanation



    ava can be used to create two types of programs: applications and
    applets. The output of a Java compiler is not executable code. Rather
    it is bytecode. Java run-time system is an interpreter for bytecode. It
    is simply a highly efficient means of encoding a program for
    interpretation. It is much easier to allow Java programs to run in a
    wide variety of environments. Once the run-time package exists for a
    given system, the bytecode version of any Java program can run on it.
    Therefore, using bytecode to represent programs is the easiest way to
    create truly portable programs.


    There are two surface
    similarities between Java and C++. First, Java uses a syntax similar to
    C++, such as the general forms of the for, while, and do loops. Second,
    Java supports object-oriented programming, same way as C++.


    There
    are also significant differences from C++, which fundamentally makes
    Java distinct from C++. Perhaps the single biggest difference between
    Java and C++ is that Java does not support pointers. Pointers are
    inherently insecure and troublesome. Since pointers do not exist in
    Java, neither does the -> operator. Some other C++ features are not
    found in Java.


     Java does not include structures or unions because the class encompasses these other forms. It is redundant to include them.
     Java does not support operator overloading.
     Java does not include a preprocessor or support the preprocessor directives.
     Java does not perform any automatic type conversions that result in a loss of precision.

    All the code in a Java program is encapsulated within one or more
    classes. Therefore, Java does not have global variables or global
    functions.
     Java does not support multiple inheritance.
     Java does not support destructors, but rather, add the finalize() function.
     Java does not have the delete operator.
     The << and >> are not overloaded for I/O operations.
     Java does not support templates.


    Java
    shares many similarities with C++ as it relates to classes, but there
    are also several differences. By default, members of a class are
    accessible by other members of their class, derived classes, and by
    other members of their package. Therefore, class members are “more
    public” than they are in C++, however, the private access specifier
    applies only to the variable or method that it immediately precedes.
    All class objects are instantiated in Java using the new operator.
    Therefore, all class objects are dynamically allocated. When there are
    no references to an object, then the object is considered inactive.


    Java
    includes two class-management features that help make using and
    organizing classes easier. The first is called a package, which defines
    a scope. Therefore, names declared inside a package are private to that
    package. Java uses file directories to store packages. Therefore, each
    package must be stored in a directory that has the same name as the
    package—including capitalization.


    Java, like C++, supports
    hierarchies of classes. However, the way that inheritance is
    implemented in Java differs substantially from the way that it is
    implemented in C++. Since multiple inheritance is not allowed in Java,
    then Java class hierarchies are linear. In Java, inheritance is
    referred to as subclassing. A base class in C++ is referred to as
    superclass in Java.





    http://livetolead.blogspot.com/
    all the best
    Arise Awake N Stop Not Until Ur Goal Is Reached!

  8. #8
    tapeshj@gmail
    Unregistered

    Cool Re: Practice Question in JAVA

    Quote Originally Posted by sowmya571 View Post
    hello



    this can also be the explanation



    ava can be used to create two types of programs: applications and
    applets. The output of a Java compiler is not executable code. Rather
    it is bytecode. Java run-time system is an interpreter for bytecode. It
    is simply a highly efficient means of encoding a program for
    interpretation. It is much easier to allow Java programs to run in a
    wide variety of environments. Once the run-time package exists for a
    given system, the bytecode version of any Java program can run on it.
    Therefore, using bytecode to represent programs is the easiest way to
    create truly portable programs.


    There are two surface
    similarities between Java and C++. First, Java uses a syntax similar to
    C++, such as the general forms of the for, while, and do loops. Second,
    Java supports object-oriented programming, same way as C++.


    There
    are also significant differences from C++, which fundamentally makes
    Java distinct from C++. Perhaps the single biggest difference between
    Java and C++ is that Java does not support pointers. Pointers are
    inherently insecure and troublesome. Since pointers do not exist in
    Java, neither does the -> operator. Some other C++ features are not
    found in Java.


     Java does not include structures or unions because the class encompasses these other forms. It is redundant to include them.
     Java does not support operator overloading.
     Java does not include a preprocessor or support the preprocessor directives.
     Java does not perform any automatic type conversions that result in a loss of precision.

    All the code in a Java program is encapsulated within one or more
    classes. Therefore, Java does not have global variables or global
    functions.
     Java does not support multiple inheritance.
     Java does not support destructors, but rather, add the finalize() function.
     Java does not have the delete operator.
     The << and >> are not overloaded for I/O operations.
     Java does not support templates.


    Java
    shares many similarities with C++ as it relates to classes, but there
    are also several differences. By default, members of a class are
    accessible by other members of their class, derived classes, and by
    other members of their package. Therefore, class members are “more
    public” than they are in C++, however, the private access specifier
    applies only to the variable or method that it immediately precedes.
    All class objects are instantiated in Java using the new operator.
    Therefore, all class objects are dynamically allocated. When there are
    no references to an object, then the object is considered inactive.


    Java
    includes two class-management features that help make using and
    organizing classes easier. The first is called a package, which defines
    a scope. Therefore, names declared inside a package are private to that
    package. Java uses file directories to store packages. Therefore, each
    package must be stored in a directory that has the same name as the
    package—including capitalization.


    Java, like C++, supports
    hierarchies of classes. However, the way that inheritance is
    implemented in Java differs substantially from the way that it is
    implemented in C++. Since multiple inheritance is not allowed in Java,
    then Java class hierarchies are linear. In Java, inheritance is
    referred to as subclassing. A base class in C++ is referred to as
    superclass in Java.

  9. #9
    Unregistered
    Unregistered

    Smile Re: Practice Question in JAVA

    Quote Originally Posted by sowmya571 View Post
    hello



    5 What is the difference between METHODS and CONSTRUCTORS?



    A
    constructor is a member function of a class
    that is used to create objects of that class.
    It has the same name as the class itself,
    has no return type, and is invoked using
    the new operator.
    consturctors are used to initialize the instances of a class.

    A method is an ordinary member function
    of a class. It has its own name, a return
    type (which may be void), and is invoked
    using the dot operator.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Content Relevant URLs by vBSEO 3.5.1 PL1