ELK Education Consultants Fresher Interview Questions with Answers – Part 2

 

ELK Education Consultants Fresher Interview Questions with Answers – Part 2

This blog explains about ELK Education Consultants Fresher Interview Questions with Answers – Part 2 and is given below :

1. Explain about Final Keyword In Java

  1. Final variable
  2. Final method
  3. Final class
  4. Is final method inherited ?
  5. Blank final variable
  6. Static blank final variable
  7. Final parameter
  8. Can you declare a final constructor

The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be:

  1. variable
  2. method
  3. class

The final keyword can be applied with the variables, a final variable that have no value it is called blank final variable or uninitialized final variable. It can be initialized in the constructor only. The blank final variable can be static also which will be initialized in the static block only. We will have detailed learning of these. Let’s first learn the basics of final keyword.

1) Java final variable

If you make any variable as final, you cannot change the value of final variable(It will be constant).

Example of final variable

There is a final variable speedlimit, we are going to change the value of this variable, but It can’t be changed because final variable once assigned a value can never be changed.

  1. classBike9{  
  2. finalint speedlimit=90;//final variable  
  3. voidrun(){  
  4. speedlimit=400;  
  5. }  
  6. publicstatic void main(String args[]){  
  7. Bike9 obj=newBike9();  
  8. run();  
  9. }  
  10. }//end of class 

2. Explain about Super Keyword in Java

The super keyword in Java is a reference variable which is used to refer immediate parent class object.

Whenever you create the instance of subclass, an instance of parent class is created implicitly which is referred by super reference variable.

Usage of Java super Keyword

  1. super can be used to refer immediate parent class instance variable.
  2. super can be used to invoke immediate parent class method.
  3. super() can be used to invoke immediate parent class constructor.

1) super is used to refer immediate parent class instance variable.

We can use super keyword to access the data member or field of parent class. It is used if parent class and child class have same fields.

  1. classAnimal{  
  2. String color=”white”;  
  3. }  
  4. classDog extendsAnimal{  
  5. String color=”black”;  
  6. voidprintColor(){  
  7. out.println(color);//prints color of Dog class
  8. out.println(super.color);//prints color of Animal class
  9. }  
  10. }  
  11. classTestSuper1{  
  12. publicstatic void main(String args[]){  
  13. Dog d=newDog();  
  14. printColor();  
  15. }}  

Output:

 black white

3. What is Hadoop

Hadoop is an open source framework from Apache and is used to store process and analyze data which are very huge in volume. Hadoop is written in Java and is not OLAP (online analytical processing). It is used for batch/offline processing.It is being used by Facebook, Yahoo, Google, Twitter, LinkedIn and many more. Moreover it can be scaled up just by adding nodes in the cluster.

Modules of Hadoop

  1. HDFS:Hadoop Distributed File System. Google published its paper GFS and on the basis of that HDFS was developed. It states that the files will be broken into blocks and stored in nodes over the distributed architecture.
  2. Yarn:Yet another Resource Negotiator is used for job scheduling and manage the cluster.
  3. Map Reduce:This is a framework which helps Java programs to do the parallel computation on data using key value pair. The Map task takes input data and converts it into a data set which can be computed in Key value pair. The output of Map task is consumed by reduce task and then the out of reducer gives the desired result.
  4. Hadoop Common:These Java libraries are used to start Hadoop and are used by other Hadoop modules.

Advantages of Hadoop

  • Fast: In HDFS the data distributed over the cluster and are mapped which helps in faster retrieval. Even the tools to process the data are often on the same servers, thus reducing the processing time. It is able to process terabytes of data in minutes and Peta bytes in hours.
  • Scalable: Hadoop cluster can be extended by just adding nodes in the cluster.
  • Cost Effective: Hadoop is open source and uses commodity hardware to store data so it really cost effective as compared to traditional relational database management system.
  • Resilient to failure: HDFS has the property with which it can replicate data over the network, so if one node is down or some other network failure happens, then Hadoop takes the other copy of data and use it. Normally, data are replicated thrice but the replication factor is configurable.

4. Write a java code to display the price based on the product  

Discount Java Code

  1. Java program to calculate Discount ( Using standard values )

By using standard values consider this program is universal code.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

class Discount

{

          public static void main(String args[])

          {

 

          double  dis,amount,markedprice,s;

              

          markedprice=1000;

 

        dis=25;  // 25 mean 25%                            

         

          System.out.println(“markedprice= “+markedprice);

 

          System.out.println(“discount rate=”+dis);

        

        s=100-dis;

 

          amount= (s*markedprice)/100;

 

          System.out.println(“amount after discount=”+amount);

 

          }

}

output:

1

2

3

markedprice = 1000.0

discount rate=25.0

amount after discount=750.0

2. Taking inputs through scanner classs

Taking inputs through scanner class, with sample output.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

java.util.Scanner;

 

class Discount

{

          public static void main(String args[])

          {

 

          double  dis,amount,markedprice,s;

         

          Scanner sc=new Scanner(System.in);

         

          System.out.println(“enter markedprice “);      

              

          markedprice=sc.nextDouble();

 

        System.out.println(“enter discount percentage “);      

              

          dis=sc.nextDouble();                        

         

        s=100-dis;

 

          amount= (s*markedprice)/100;

 

          System.out.println(“amount after discount=”+amount);

 

          }

}

output:

1

2

3

4

5

enter marked price

2000

enter discount percentage

30

amount after discount=1400.0

 

 REFERENCES : 

https://payilagam.com/blogs/elk-education-consultants-fresher-interview-questions-with-answers/

https://www.javatpoint.com/final-keyword

https://www.javatpoint.com/super-keyword

https://www.javatpoint.com/what-is-hadoop

https://javatutoring.com/java-program-to-calculate-discount/