Skip to main content

Posts

Showing posts from August, 2021

Quiz based on Digital Principles and Computer Organization

1) Base of hexadecimal number system? Answer : 16 2) Universal gate in digital logic? Answer : NAND 3) Memory type that is non-volatile? Answer : ROM 4) Basic building block of digital circuits? Answer : Gate 5) Device used for data storage in sequential circuits? Answer : Flip-flop 6) Architecture with shared memory for instructions and data? Answer : von Neumann 7) The smallest unit of data in computing? Answer : Bit 8) Unit that performs arithmetic operations in a CPU? Answer : ALU 9) Memory faster than main memory but smaller in size? Answer : Cache 10) System cycle that includes fetch, decode, and execute? Answer : Instruction 11) Type of circuit where output depends on present input only? Answer : Combinational 12) The binary equivalent of decimal 10? Answer : 1010 13) Memory used for high-speed temporary storage in a CPU? Answer : Register 14) Method of representing negative numbers in binary? Answer : Two's complement 15) Gate that inverts its input signal? Answer : NOT 16)...

Java important question - 13

What are the ways to initialize a final variable ?           We must initialize a final variable, otherwise compiler will throw compile time error. A final variable can only be initialize once, either via an initializer or an assignment statement. There are three ways to initialize a final variable, 1) You can initialize a final variable when it is declared. This approach is most common. A final variable is called blank final variable, if it is not initialized while declaration. Below are the two ways to initialize a blank final variable. 2) A blank final variable can be initialized inside constructor. If you have more than one constructor in your class then it must be initialized in all of them, otherwise compile time error will be thrown. 3) A blank final static variable can be initialized inside static block. What is the difference between transient and volatile variable in Java ? Transient:           In Java, it is used to specify th...

Java important question - 12

What is the use of final keyword in java ?           final keyword is used in different contexts. First of all, final is a non-access modifier applicable only to a variable, method or a class. Following are different contexts where final is used, a) Final variable -  To create constant variable. When a variable is declared with final keyword, it's value can't be modified, essentially a constant. This also means that you must initialize a final variable. If the final variable is reference this means that the variable cannot be rebound to reference another object, but the internal state of the object pointed by that reference variable can be changed. i.e. you can add or remove elements from final array or final collection. It is good practice to represent final variables in all uppercase, using underscore to separate words. Java interface variables are by default final and static. b) Final methods - Prevent method overridding. We can use the final keyword wit...

Java important question - 11

What is the difference between creating String as new() and literal ?           When we create String with new() operator, it's created in heap and not added into string pool. When String created using literal are created in String pool itself which exist in permgem area of heap.  String s = new String("Test");           This does not put the object in string pool, we need to call String.intern() method which is used to put them into String pool explicitly. When you create String object as String literal. Eg : String s = "Test" java automatically put that into String pool. Define a StringJoiner and write sample code ?           StringJoiner is a utility method to construct a string with the desired delimiter. StringJoiner strJoiner = new StringJoiner                                              ...

Java important question - 10

Can we use String with switch case ?           One of the java7 features was improvement of switch case to allow strings. So if you are using java 7 or higher version, you can use String in switch case statement. private   static void printColorUsingSwitch                                                (String color) { switch(color) { case "blue":      System.out.println("Blue");      break; case "red":      System.out.println("Red");      break; default :      System.out.println("Invalid color                                                code"); } Q) Difference between String, StringBuilder and StringBuffer in java String :       ...

Java important Question - 9

Q) Can we declare a class as static ?           We can't declare a top-level class as static however an inner class can be declared as static. If inner class is declared as static,it's called  static nested class. The static nested class is same as any other top-level class and is nested for only packaging convenience. Also when we declare a class as 'static' then it can be referenced without the use of an object. Q) What is static import ?           static import is a feature introduced in java version 5.0 that allows members defined in a class as public static to be used in Java code without specifying the class in which the field is defined. If we have to use any static variable or method from other class, usually we import the class and then use the method/variable with class name. We can do the same thing by importing the static method or variable only and then use it in the class as if it belong to it. import static java.lang....

Java important question - 8

Q) What is composition in Java ?           Composition is the design technique to implement has a relationship in classes. We can use object composition for code reuse.           Java composition is achieved by using instance variables that refer to other objects. The benefit of using composition is that we can control the visibility of other objects to client classes and reuse only what we need. Q) What is the benefits of composition over inheritance ?           Prefer composition over inheritance is a one of the popular object oriented design principles, some of the possible reasons are 1) Inheritance is tightly coupled whereas composition is loosely coupled. 2) Any change in superclass might affect subclass even though we might not be using the superclass methods. For example, if we have a method test() in the subclass and suddenly somebody introduces a method test() in the superclass, we may get compilation e...

Java important question - 7

Q) What is Inheritance ?           Inheritance is one of the key features of object oriented programming. It is the mechanism in java in which one class inherits the properties (methods and fields) of another class.           The class which inherits the properties of other is known as subclass and the class whose properties are inherited is known as superclass.           extends is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword. Syntax: class Super { .......... .......... } class Sub extends Super { .......... .......... } Q) Can an interface implement or extend another interface ?          Interface can't implement  another interface, since interfaces can't have method implementations. An interface can extend another interface. Q) What is Marker interface ?         A Marker interface is an empty interface withou...

Java important question - 6

Q) What is the difference between abstract class and interface ? Answer : 1) The abstract keyword is used to declare  abstract class.  The interface keyword is used to declare interface. 2) Abstract class have all the features of a normal java class except that we can't instantiate it. We can use abstract keyword to make a class abstract but interfaces are a completely different type and can have only public static final constants and method declarations. 3) Abstract class can have abstract and non abstract methods. Interface can have only abstract methods. 4) Abstract class can have final, non-final, static and non-static variables. Interface has only static and final variables. 5) A java abstract class can have class members like private, protected,etc. Members of a java interface are public by default. 6) Abstract classes can have constructors but interface can't have constructors. 7) A subclass can extend only one abstract class but it can implement multiple interfaces. 8)...

Java important Question - 5

Q) What are wrapper classes? Why do we need wrapper classes ? Answer :           Wrapper class provides the mechanism to convert primitive into object and object into primitive. In the java.lang package java provides a separate class for each of the primitive data types namely Boolean, Byte, Short, Integer, Float, Long, Double & Character. These are known as wrapper classes because they wrap the primitive data type into an object of the class. Need of wrapper classes : * They convert primitive data types into objects. Objects are needed if we wish to modify the arguments passed into a method. * The classes in java.util package handles only objects and hence wrapper classes help in this case also. * Data structures in the collection framework, such as ArrayList and vector, store only objects and not primitive types. * An object is needed to support synchronization in multithreading. Q) What is an interface ? Answer :           An inte...