Keyword

Result: 265 questions

The declaration of structure is also called as?

Quiz

What is the output of this program?

    #include <iostream>
    #include <string.h>
    using namespace std;
    int main()
    {
        struct student {
            int num;
            char name[25];
        };
        student stu;
        stu.num = 123;
        strcpy(stu.name, "John");
        cout << stu.num << endl;
        cout << stu.name << endl;
        return 0;
    }

 

Quiz

What is the output of this program?

    #include <iostream>
    using namespace std;
    struct Time {
        int hours;
        int minutes;
        int seconds;
    };
    int toSeconds(Time now);
    int main()
    {
        Time t;
        t.hours = 5;
        t.minutes = 30;
        t.seconds = 45;
        cout << "Total seconds: " << toSeconds(t) << endl;
        return 0;
    }
    int toSeconds(Time now)
    {
        return 3600 * now.hours + 60 * now.minutes + now.seconds;
    }

 

Quiz

What will be the output of this program?

    #include <iostream>
    using namespace std;
    int main()
    {
        struct ShoeType {
           string style;
           double price;
        };
         ShoeType shoe1, shoe2;
         shoe1.style = "Adidas";
         shoe1.price = 9.99;
         cout << shoe1.style << " $ "<< shoe1.price;
         shoe2 = shoe1;
         shoe2.price = shoe2.price / 9;
         cout << shoe2.style << " $ "<< shoe2.price;
         return 0;
    }

 

Quiz

What is the output of this program?

    #include <iostream>
    using namespace std;
    struct sec {
        int a;
        char b;
    };
    int main()
    {
        struct sec s ={25,50};
        struct sec *ps =(struct sec *)&s;
        cout << ps->a << ps->b;
        return 0;
    }

 

Quiz

Which of the following is a properly defined structure?

Quiz

Which of the following accesses a variable in structure *b?

Quiz

What output will be produced by the code below?

struct Spaceship {
    var name: String {
        willSet {
            print("I'm called \(newValue)!")
        }
    }
}

var serenity = Spaceship(name: "Serenity")
serenity.name = "TARDIS"
Quiz

What is a ContentProvider and what is it typically used for?

Answer:

ContentProvider manages access to a structured set of data. It encapsulates the data and provide mechanisms for defining data security. ContentProvider is the standard interface that connects data in one process with code running in another process.

More information about content providers can be found here in the Android Developer’s Guide.

View

What is the difference between a fragment and an activity? Explain the relationship between the two.

Answer:

An activity is typically a single, focused operation that a user can perform (such as dial a number, take a picture, send an email, view a map, etc.). Yet at the same time, there is nothing that precludes a developer from creating an activity that is arbitrarily complex.

Activity implementations can optionally make use of the Fragment class for purposes such as producing more modular code, building more sophisticated user interfaces for larger screens, helping scale applications between small and large screens, and so on. Multiple fragments can be combined within a single activity and, conversely, the same fragment can often be reused across multiple activities. This structure is largely intended to foster code reuse and facilitate economies of scale.

A fragment is essentially a modular section of an activity, with its own lifecycle and input events, and which can be added or removed at will. It is important to remember, though, that a fragment’s lifecycle is directly affected by its host activity’s lifecycle; i.e., when the activity is paused, so are all fragments in it, and when the activity is destroyed, so are all of its fragments.

More information is available here in the Android Developer’s Guide.

View

What is JVM ? Why is Java called the “Platform Independent Programming Language” ?

Answer:

A Java virtual machine (JVM) is a process virtual machine that can execute Java bytecode. Each Java source file is compiled into a bytecode file, which is executed by the JVM. Java was designed to allow application programs to be built that could be run on any platform, without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible, because it is aware of the specific instruction lengths and other particularities of the underlying hardware platform.

View

What is a Constructor, Constructor Overloading in Java and Copy-Constructor ? 

Answer:

A constructor gets invoked when a new object is created. Every class has a constructor. In case the programmer does not provide a constructor for a class, the Java compiler (Javac) creates a default constructor for that class. The constructor overloading is similar to method overloading in Java. Different constructors can be created for a single class. Each constructor must have its own unique parameter list. Finally, Java does support copy constructors like C++, but the difference lies in the fact that Java doesn’t create a default copy constructor if you don’t write your own.

View

What is difference between ArrayList and LinkedList ?

Answer:

Both the ArrayList and LinkedList classes implement the List interface, but they differ on the following features:

  • An ArrayList is an index based data structure backed by an Array. It provides random access to its elements with a performance equal to O(1). On the other hand, a LinkedList stores its data as list of elements and every element is linked to its previous and next element. In this case, the search operation for an element has execution time equal to O(n).
  • The Insertion, addition and removal operations of an element are faster in a LinkedList compared to an ArrayList, because there is no need of resizing an array or updating the index when an element is added in some arbitrary position inside the collection.
  • LinkedList consumes more memory than an ArrayList, because every node in a LinkedList stores two references, one for its previous element and one for its next element.

Check also our article ArrayList vs. LinkedList.

View

What do you know about the big-O notation and can you give some examples with respect to different data structures ?

Answer:

The Big-O notation simply describes how well an algorithm scales or performs in the worst case scenario as the number of elements in a data structure increases. The Big-O notation can also be used to describe other behavior such as memory consumption. Since the collection classes are actually data structures, we usually use the Big-O notation to chose the best implementation to use, based on time, memory and performance. Big-O notation can give a good indication about performance for large amounts of data.

View

What is the difference between HashSet and TreeSet ?

Answer:

The HashSet is Implemented using a hash table and thus, its elements are not ordered. The add, remove, and contains methods of a HashSet have constant time complexity O(1). On the other hand, a TreeSet is implemented using a tree structure. The elements in a TreeSet are sorted, and thus, the add, remove, and contains methods have time complexity of O(logn).

View

What is structure of Java Heap ? What is Perm Gen space in Heap ?

Answer:

The JVM has a heap that is the runtime data area from which memory for all class instances and arrays is allocated. It is created at the JVM start-up. Heap memory for objects is reclaimed by an automatic memory management system which is known as a garbage collector. Heap memory consists of live and dead objects. Live objects are accessible by the application and will not be a subject of garbage collection. Dead objects are those which will never be accessible by the application, but have not been collected by the garbage collector yet. Such objects occupy the heap memory space until they are eventually collected by the garbage collector.

View

What are the two types of Exceptions in Java ? Which are the differences between them ?

Answer:

Java has two types of exceptions: checked exceptions and unchecked exceptions. Unchecked exceptions do not need to be declared in a method or a constructor’s throws clause, if they can be thrown by the execution of the method or the constructor, and propagate outside the method or constructor boundary. On the other hand, checked exceptions must be declared in a method or a constructor’s throws clause. See here for tips on Java exception handling.

View

What is the applet class loader, and what does it provide ?

Answer:

When an applet is loaded over the internet, the applet is loaded by the applet classloader. The class loader enforces the Java name space hierarchy. Also, the class loader guarantees that a unique namespace exists for classes that come from the local file system, and that a unique namespace exists for each network source. When a browser loads an applet over the net, that applet’s classes are placed in a private namespace associated with the applet’s origin. Then, those classes loaded by the class loader are passed through the verifier.The verifier checks that the class file conforms to the Java language specification . Among other things, the verifier ensures that there are no stack overflows or underflows and that the parameters to all bytecode instructions are correct.

View

What is the role of Remote Interface in RMI ?

Answer:

The Remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. A class that implements a remote interface should declare the remote interfaces being implemented, define the constructor for each remote object and provide an implementation for each remote method in all remote interfaces.

View

What is the structure of the HTTP response ?

Answer:

The HTTP response consists of three parts:

  • Status Code: describes the status of the response. It can be used to check if the request has been successfully completed. In case the request failed, the status code can be used to find out the reason behind the failure. If your servlet does not return a status code, the success status code, HttpServletResponse.SC_OK, is returned by default.
  • HTTP Headers: they contain more information about the response. For example, the headers may specify the date/time after which the response is considered stale, or the form of encoding used to safely transfer the entity to the user. See how to retrieve headers in Servlet here.
  • Body: it contains the content of the response. The body may contain HTML code, an image, etc. The body consists of the data bytes transmitted in an HTTP transaction message immediately following the headers.
View

© 2017 QuizBucket.org