Core Java Interview Questions- Part 10

Core Java Interview Questions- Part 10

[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 10Getting ready for a Java interview? This page is made to help you with that. Here, you’ll find a list of the most common Java interview questions. These questions test your understanding of Java basics like classes and objects, as well as advanced ideas like multithreading, exception handling, and collections.
Each question is explained in simple terms so you can learn faster. Whether you’re new to Java or already have some experience, this guide can help you improve your skills and feel ready for your interview.
Use this time to review key concepts and write your own answers. Practice makes perfect, and going over these questions will help you stay calm and confident in your interview. With effort and the right preparation, you’ll be ready to impress any employer.

[/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 181: What are assertions in Java, and what is their use?” open=”no” class=”” id=””]

Answer:

The principal use of Assertions is to check logically impossible situations like checking the state a code expects before running & its state after it finishes running. Unlike other errors or exceptional handling, Assertions are usually disabled during runtime.

[/fusion_toggle][fusion_toggle title=”Question 182: Why threads are needed in Java?” open=”no” class=”” id=””]

Answer:

Thread are needed in Java to start a Java program. It is a lightweight process that works independently to improve the utilization of the CPU. Threads accelerate the speed of Java applications by doing multiple things simultaneously. It helps us to achieve parallelism in a Java program.

[/fusion_toggle][fusion_toggle title=”Question 183: What is the difference between the Runnable interface & Thread class in Java?” open=”no” class=”” id=””]

Answer:

Following are the key differences between Runnable interface and thread class in Java:

  • Thread is a class. It is used to create a thread. While, Runnable is a functional interface which is used to create a thread.
  • Thread has multiple methods including start() and run(). Whereas, Runnable has only abstract method run().
  • Thread requires more memory. In contrast, Runnable interface requires less memory.

[/fusion_toggle][fusion_toggle title=”Question 184: What is Time Slicing?” open=”no” class=”” id=””]

Answer:

Time slicing refers to a scheduling process that divides the available CPU time amongst various runnable threads. The allocation of CPU time depends on the priority of a thread. In the time-slicing process, a task executes for a particular time & re-enters the pool of ready tasks. The thread scheduler decides which task should be executed next, based on priority & other factors.

[/fusion_toggle][fusion_toggle title=”Question 185: Can you make an array volatile?” open=”no” class=”” id=””]

Answer:

Yes, it is possible to make an array volatile in Java. However, we can only make the reference pointing to an array & not the whole array. If a thread changes the reference variable & points to another array, that will guarantee the array volatility. In case multiple threads make changes in the array elements, they cannot change before a volatile modifier renders the guarantee.

[/fusion_toggle][fusion_toggle title=”Question 186: When does a class get garbage collected in Java?” open=”no” class=”” id=””]

Answer:

A class becomes garbage-collected when nothing references it. There are several ways of making a class reachable & prevent it from being eligible for garbage collection:

  • When the objects of the class are still reachable;
  • The class object represents that class is still reachable;
  • The ClassLoader that has loaded the class is still reachable;
  • And when other classes loaded by the ClassLoader are still reachable.

[/fusion_toggle][fusion_toggle title=”Question 187: Mention the differences between the factory pattern & abstract factory pattern?” open=”no” class=”” id=””]

Answer:

The following are the differences between the factory pattern & abstract factory pattern:

  • A factory pattern is a single method, while an abstract factory is an object.
  • The level of abstraction for an abstract factory pattern is one step higher than the factory pattern.
  • The factory method pattern returns the common parent class, but the abstract factory pattern returns one of several factories.

[/fusion_toggle][fusion_toggle title=”Question 188: How is the Observable class used?” open=”no” class=”” id=””]

Answer:

An Observable class is used to create subclasses that other parts of a program can observe. When the object of such a subclass undergoes any change, then the observing classes get notified. Thereon, the update( ) method is called whenever an object is notified of any change.

[/fusion_toggle][fusion_toggle title=”Question 189: Explain the purpose of the Comparator interface in Java?” open=”no” class=”” id=””]

Answer:

The Comparator interface in Java controls the order of a certain collection of objects & data structures. It is present in java.util.Comparator. The Comparator interface is capable of comparing two objects & two classes. We can perform sorting by implicitly using data structures & explicitly implementing sort methods.

[/fusion_toggle][fusion_toggle title=”Question 190: What is the impact of a private constructor?” open=”no” class=”” id=””]

Answer:

A private constructor helps to prevent external instantiation of subclasses & classes. Objects can be created, but the creation can be done internally.

[/fusion_toggle][fusion_toggle title=”Question 191: What are the advantages of Java Sockets?” open=”no” class=”” id=””]

Answer:

The following are the advantages of Java Sockets:

  • Java Sockets are flexible for general communication & easy to implement.
  • Java Sockets causes low network traffic, unlike CGI scripts HTML forms that can generate the whole web page for each new request.

[/fusion_toggle][fusion_toggle title=”Question 192: Can an application with multiple classes have the main method?” open=”no” class=”” id=””]

Answer:

Yes, an application with multiple classes can have the main method. Java Virtual Method will look for the main() method in that class whose name we mentioned.

[/fusion_toggle][fusion_toggle title=”Question 193: Difference between HashMap & HashTable?” open=”no” class=”” id=””]

Answer:

The key differences between HashMap & HashTable are as follows:

  • HashMap is non-synchronized, but HashTable is synchronized and slower in performance.
  • HashMap uses an iterator to traverse, while the HashTable uses an enumerator to traverse.
  • The iterator in HashMap is fail-fast, but an enumerator in HashTable isn’t fail-fast.
  • HashMap permits only one null key & null values, while Hashtable doesn’t allow any key or value as null.

[/fusion_toggle][fusion_toggle title=”Question 194: What is a Priority Queue in Java?” open=”no” class=”” id=””]

Answer:

A priority queue refers to an abstract data type that has a priority associated with each element. In the priority queue, elements with higher priority get served before the elements with lower priority. The order of elements is either natural or as per the comparator.

[/fusion_toggle][fusion_toggle title=”Question 195: If a class has no modifiers, wherever could the class be accessed?” open=”no” class=”” id=””]

Answer:

A class with no access modifiers is visible through its package access. It means that the class can only be accessed by other interfaces & classes defined inside the same package.

[/fusion_toggle][fusion_toggle title=”Question 196: Explain the restrictions placed on the values of each case of a switch statement?” open=”no” class=”” id=””]

Answer:

The restrictions are placed during compilation in a switch statement, wherein each case’s values must evaluate to the value that can be promoted to an int value.

[/fusion_toggle][fusion_toggle title=”Question 197: Can an anonymous class declare as implementing an interface & extending a superclass?” open=”no” class=”” id=””]

Answer:

An anonymous class may extend a superclass or implement an interface but cannot be declared to do both at a time.

[/fusion_toggle][fusion_toggle title=”Question 198: What is an alternative to inheritance?” open=”no” class=”” id=””]

Answer:

The principal use of Assertions is to check logically impossible situations like checking the state a code expects before running & its state after it finishes running. Unlike other errors or exceptional handling, Assertions are usually disabled during runtime.

[/fusion_toggle][fusion_toggle title=”Question 199: What is the use of Void class in Java?” open=”no” class=”” id=””]

Answer:

The Void class means an uninstantiable placeholder class that references the Class Object, representing the primitive Java type void.

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

Answer:

A Locale class object in Java represents a cultural, political, or geographical region. It is a mechanism for identifying the objects, not a container for an object. A Locale comprises the fields like script, languages, variant, country, & extensions.

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

Share the Post:

Related Posts

Contact Us