Core Java Interview Questions- Part 5

120+ Core Java Interview Questions and Answers part5

[fusion_builder_container type=”flex” hundred_percent=”no” hundred_percent_height=”no” min_height=”” hundred_percent_height_scroll=”no” align_content=”stretch” flex_align_items=”flex-start” flex_justify_content=”flex-start” flex_column_spacing=”” hundred_percent_height_center_content=”yes” equal_height_columns=”no” container_tag=”div” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” publish_date=”” class=”” id=”” margin_top_medium=”” margin_bottom_medium=”” margin_top_small=”” margin_bottom_small=”” margin_top=”0px” margin_bottom=”” padding_top_medium=”” padding_right_medium=”” padding_bottom_medium=”” padding_left_medium=”” padding_top_small=”” padding_right_small=”” padding_bottom_small=”” padding_left_small=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” link_color=”” link_hover_color=”” border_sizes_top=”” border_sizes_right=”” border_sizes_bottom=”” border_sizes_left=”” border_color=”” border_style=”solid” box_shadow=”no” box_shadow_vertical=”” box_shadow_horizontal=”” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” z_index=”” overflow=”” gradient_start_color=”” gradient_end_color=”” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ background_blend_mode=”none” video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” video_preview_image=”” render_logics=”” absolute=”off” absolute_devices=”small,medium,large” sticky=”off” sticky_devices=”small-visibility,medium-visibility,large-visibility” sticky_background_color=”” sticky_height=”” sticky_offset=”” sticky_transition_offset=”0″ scroll_offset=”0″ animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ align_self=”auto” content_layout=”column” align_content=”flex-start” valign_content=”flex-start” content_wrap=”wrap” spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” type_medium=”” type_small=”” order_medium=”0″ order_small=”0″ dimension_spacing_medium=”” dimension_spacing_small=”” dimension_spacing=”” dimension_margin_medium=”” dimension_margin_small=”” margin_top=”” margin_bottom=”” padding_medium=”” padding_small=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” hover_type=”none” border_sizes=”” border_color=”” border_style=”solid” border_radius=”” box_shadow=”no” dimension_box_shadow=”” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” background_type=”single” gradient_start_color=”” gradient_end_color=”” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” background_blend_mode=”none” render_logics=”” filter_type=”regular” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” last=”true” border_position=”all” first=”true”][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” font_size=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” line_height=”” letter_spacing=”” text_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””]

Core Java Interview Questions- Part 5
During programming interviews, employers want to know how proficient you are in Core Java concepts like object-oriented principles, memory management, exception handling, multithreading, etc. So, to help you out, we have created this Java interview questions page.
The page has about 200 questions, covering all the Core Java topics so that when you go to interviews, you are well-prepared for the questions, which are commonly asked by the interviewers.
You can go through the essential concepts by reading the questions and answers. This interview questions guide is useful for gaining knowledge, identifying weak areas, and improving your responses. Let’s start practicing and move one step closer to your dream Java job.

[/fusion_text][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container][fusion_builder_container type=”flex” hundred_percent=”no” hundred_percent_height=”no” min_height=”” hundred_percent_height_scroll=”no” align_content=”stretch” flex_align_items=”flex-start” flex_justify_content=”flex-start” flex_column_spacing=”” hundred_percent_height_center_content=”yes” equal_height_columns=”no” container_tag=”div” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” publish_date=”” class=”” id=”” margin_top_medium=”” margin_bottom_medium=”” margin_top_small=”” margin_bottom_small=”” margin_top=”” margin_bottom=”” padding_top_medium=”” padding_right_medium=”” padding_bottom_medium=”” padding_left_medium=”” padding_top_small=”” padding_right_small=”” padding_bottom_small=”” padding_left_small=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” link_color=”” link_hover_color=”” border_sizes_top=”10px” border_sizes_right=”10px” border_sizes_bottom=”10px” border_sizes_left=”10px” border_color=”#007dc6″ border_style=”solid” box_shadow=”yes” box_shadow_vertical=”4″ box_shadow_horizontal=”4″ box_shadow_blur=”30″ box_shadow_spread=”0″ box_shadow_color=”rgba(0,0,0,0.32)” box_shadow_style=”” z_index=”” overflow=”” gradient_start_color=”” gradient_end_color=”” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ background_blend_mode=”none” video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” video_preview_image=”” render_logics=”” absolute=”off” absolute_devices=”small,medium,large” sticky=”off” sticky_devices=”small-visibility,medium-visibility,large-visibility” sticky_background_color=”” sticky_height=”” sticky_offset=”” sticky_transition_offset=”0″ scroll_offset=”0″ animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ align_self=”auto” content_layout=”column” align_content=”flex-start” valign_content=”flex-start” content_wrap=”wrap” spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” background_image_id=”” type_medium=”” type_small=”” order_medium=”0″ order_small=”0″ spacing_left_medium=”” spacing_right_medium=”” spacing_left_small=”” spacing_right_small=”” spacing_left=”” spacing_right=”” margin_top_medium=”” margin_bottom_medium=”” margin_top_small=”” margin_bottom_small=”” margin_top=”” margin_bottom=”” padding_top_medium=”” padding_right_medium=”” padding_bottom_medium=”” padding_left_medium=”” padding_top_small=”” padding_right_small=”” padding_bottom_small=”” padding_left_small=”” padding_top=”20px” padding_right=”20px” padding_bottom=”20px” padding_left=”20px” hover_type=”none” border_sizes_top=”” border_sizes_right=”” border_sizes_bottom=”” border_sizes_left=”” border_color=”” border_style=”solid” border_radius_top_left=”” border_radius_top_right=”” border_radius_bottom_right=”” border_radius_bottom_left=”” box_shadow=”no” box_shadow_vertical=”” box_shadow_horizontal=”” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” background_type=”single” gradient_start_color=”” gradient_end_color=”” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_position=”left top” background_repeat=”no-repeat” background_blend_mode=”none” render_logics=”” filter_type=”regular” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” last=”true” border_position=”all” first=”true”][fusion_accordion type=”accordions” boxed_mode=”” border_size=”1″ border_color=”” background_color=”” hover_color=”” divider_line=”” title_font_size=”” icon_size=”” icon_color=”” icon_boxed_mode=”” icon_box_color=”#4f4f4f” icon_alignment=”right” toggle_hover_accent_color=”#3ed9df” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”interview_list” id=””][fusion_toggle title=”Question 81: Compare race condition & deadlock in Java?” open=”no” class=”” id=””]

Answer:

A deadlock occurs when multiple threads are blocking each other. It is in regards to the threads trying to acquire the shared resources. A race condition occurs when multiple threads interact negatively depending on the exact order that their execution takes place.

[/fusion_toggle][fusion_toggle title=”Question 82: Why does Java not support multiple inheritances?” open=”no” class=”” id=””]

Answer:

Java does not support multiple inheritance using class because whenever a sub or child class wants to access the property of two or more parent or super class that have same method, java compiler can’t decide which class method it should be inherit.

[/fusion_toggle][fusion_toggle title=”Question 83: What do you mean by overloading & overriding in Java?” open=”no” class=”” id=””]

Answer:

When we have more than one method in a class with the same name but different arguments, it is called overloading. Overriding occurs when we have two methods with the same signature from which one in the child class & the other is in the parent class.

[/fusion_toggle][fusion_toggle title=”Question 84: Can you have multiple public classes in a Java source file?” open=”no” class=”” id=””]

Answer:

No, while defining two or more classes in a single Java file, we need to ensure that only one class amongst them is public. If we have multiple public classes in a single file, it generates a compile-time error.

[/fusion_toggle][fusion_toggle title=”Question 85: Define Java Package? Which package is imported by default?” open=”no” class=”” id=””]

Answer:

Java package is a mechanism that organizes classes by grouping them. The grouping logic can be based on modules or functionality. A java class fully classified name contains package and class name. Java compiler imports java.lang package by default & it doesn’t need to be imported explicitly.

[/fusion_toggle][fusion_toggle title=”Question 86: Explain finally and finalize method in Java?” open=”no” class=”” id=””]

Answer:

Finally block is used to execute clean-up codes such as closing files, closing connections, or freeing up threads since it excites irrespective of an exception. Whereas, Finalize is a method in the Object class that can be overridden in our classes. It is generally overridden to release system resources whenever the object is garbage collected.

[/fusion_toggle][fusion_toggle title=”Question 87: Can interface extend or implement another interface?” open=”no” class=”” id=””]

Answer:

An interface can extend many interfaces. Still, it cannot implement another interface because if an interface is implemented, its methods need to be defined & the interface never has a definition of any method.

[/fusion_toggle][fusion_toggle title=”Question 88: What do you mean by Java Annotation?” open=”no” class=”” id=””]

Answer:

Annotation is metadata about the program embedded in itself. It can be parsed by the compiler or annotation parsing tool. One can specify annotation availability till runtime or to compile-time only.

[/fusion_toggle][fusion_toggle title=”Question 89: What is an anonymous inner class in Java?” open=”no” class=”” id=””]

Answer:

An anonymous inner class refers to a local inner class with no name. It is defined & instantiated into a single statement. Anonymous inner class always implements an interface or extends a class. It is only accessible at the point where it is defined.

[/fusion_toggle][fusion_toggle title=”Question 90: Is Java pass by value or reference?” open=”no” class=”” id=””]

Answer:

As object references are passed by value, so Java also pass by value, not by reference.

[/fusion_toggle][fusion_toggle title=”Question 91: Can we initialize the final blank variable?” open=”no” class=”” id=””]

Answer:

Yes, the final blank variable can be initialized in the constructor if it is not static. In case it is a static blank final variable, then it can be initialized in the static block only.

[/fusion_toggle][fusion_toggle title=”Question 92: What is the use of ‘this’ keyword in a class?” open=”no” class=”” id=””]

Answer:

‘this’ keyword refers to the current object in a method or constructor. It is most commonly used to eliminate the confusion between class attributes & parameters with the same name.

[/fusion_toggle][fusion_toggle title=”Question 93: Mention a class that is considered as a superclass of all the classes?” open=”no” class=”” id=””]

Answer:

In Java, the Object class is considered to be the superclass of all other classes.

[/fusion_toggle][fusion_toggle title=”Question 94: What is wrong with using HashMap in the multithreaded environment?” open=”no” class=”” id=””]

Answer:

There is nothing wrong with using HashMap; it all depends on how you use it. For instance, if you initialize the HashMap using one thread & all the other threads are just reading from it, it does not create any problem. However, the main issue arises when at least one thread is updating HashMap, i.e., changing, removing, or adding any key-value pair.

[/fusion_toggle][fusion_toggle title=”Question 95: Does all property of Immutable Object need to be final in Java?” open=”no” class=”” id=””]

Answer:

No, it is not essential to have all properties final. In immutable objects, you must not allow the users to modify the class’s variables. To do that, you can make variables private and not provide setter methods to change them.

[/fusion_toggle][fusion_toggle title=”Question 96: How do you handle error conditions while accessing stored procedures or writing stored procedures from Java?” open=”no” class=”” id=””]

Answer:

When we call a stored procedure, it executes in the database server, so if an exception occurs, that can be handled in the EXCEPTION block in the stored procedure. If the stored procedure fails, it throws an SQLException, which can be handled by a try or catch block.

[/fusion_toggle][fusion_toggle title=”Question 97: When to override hashCode() & equals() method?” open=”no” class=”” id=””]

Answer:

It is particularly overridden when you want to check equality based on business logic instead of object equality. It is also essential to override both methods if you want to use them as a key in HashMap.

[/fusion_toggle][fusion_toggle title=”Question 98: Which two methods you need to implement a key Object in HashMap?” open=”no” class=”” id=””]

Answer:

If you want to use any object as a key in HashMap, then it must implement the hashcode & equals method.

[/fusion_toggle][fusion_toggle title=”Question 99: What do you mean by wrapper class in Java?” open=”no” class=”” id=””]

Answer:

A wrapper class converts the primitive data types into objects or reference types. Each primitive data type has a class dedicated to it, known as wrapper class, as it wraps the primitive data type into that class object.

[/fusion_toggle][fusion_toggle title=”Question 100: What is Enumeration in Java?” open=”no” class=”” id=””]

Answer:

Enumeration means a list of named constant that defines a class type in Java. An Enumeration can have methods, constructors, & instance variables. It is created using the enum keyword. Each Enumeration constant is static, final, & public by default. Enumeration variables are used & declared in the same way as primitive variables.

[/fusion_toggle][/fusion_accordion][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

Share the Post:

Related Posts

Contact Us