0% found this document useful (0 votes)
20 views4 pages

core java most ask

most ask core java question

Uploaded by

Jivan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
20 views4 pages

core java most ask

most ask core java question

Uploaded by

Jivan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

Can class have private and protected as access modifier?

No, class does not have private and protected as access modifier, class can be default and public.

What is the difference between Abstraction and Encapsulation?

Abstraction is the method of hiding the unwanted information. Whereas encapsulation is a method to hide the data in a single entity
or unit along with a method to protect information from outside.In abstraction, implementation complexities are hidden using
abstract classes and interfaces. While in encapsulation, the data is hidden using methods of getters and setters.

Why final and abstract cannot be used at a time?

If we declare class as abstract it must be extended by another class but if we declare final class it cannot be extended by other class.

What is Object Cloning?

Object cloning means exact copy of Object by using Cloneable interface must be implemented by class and if you not implemented it
throws cloneNotSupportedException

Define Wrapper Classes in Java?

Wrapper class is a mechanism which contains primitive data types of class and it converts to primitive data type to object and object
to primitive data type by using Autoboxing and unboxing technique.For example Primitive data type ‘char’ and wrapper class is
‘Character’

Can you implement pointers in a Java Program?No, Pointers are not available in java so, we cannot implement pointers

How to access class data members and methods in Java?


Class data members and methods into another class by using object in java but we have Instance data members and static data members and
similar to methods
Can we declare a static variable inside a method?
No we cannot declare a static variable inside a method and only final method is allowed.

What is the difference between a static and a non-static inner class?

Nested or inner static class doesn’t need a reference of Outer class but a non static nested class or Inner class requires Outer class
reference.

What is the difference between a constructor and a method?


Constructor does not have return type and it is used to initialize the object.
Default constructor is available
Method
Method has return type if you declare void it does not return any value and we access by using
object.We don’t have default method

What is the difference between java.util.Date and java.sql.Date?

Both dates are storing date and time information but java.sql.Date is used to communication of java applications with the database
but java.util.Date get time and date from the system.Sometimes we need to convert sql date into util date and vice versa based on
date formate

What are the inner class?

We have two types of inner classes one is static inner class and non static inner classInner class is defined as class provides another
class inside that class or group of classes in one place it is more reliable to maintain.
What is the anonymous class?Anonymous class is nothing but without a class name of inner class which is only create
single object and a anonymous class must be defined inside another classAnonymous class may have to create in two ways like class
and interface.

What is the difference between thread and process?


process takes more time to create or terminate when compared to thread because thread communication is more efficient and thread have segment
of processWe have multi programs holds multiple process but each process ave multiple threads.Process involved in system calls but thread is
created by API’s

What is the lifecycle of Thread?We have various stages in lifecycle of Thread.

New/ Start ,Runnable,Running,Blocked,Waiting,Terminated

difference between Runnable and Callable interface?


Callable interface is checked exception so it returns value otherwise it throws exception but Runnable interface is unchecked exception so it does
not return any value.Callable interface is call() method but Runnable interface have run() method

How can we handle deadlock?

There are four ways to Handling the deadlock situation


1. Prevention
2. Avoidance
3. Detection and Recovery
4. Ignorance

What is the purpose of join() method?


In java join() method found in java.lang.Thread class which permits one thread to wait until the other thread to finish its execution. If more than
one thread invoking the join() method, then it leads to overloading on the join() method that permits the developer or programmer to mention
thewaiting period.
There are three overloaded join() methods
Join() : current thread stops and goes into wait state
Syntax:
public final void join() throws InterruptedException
Join(long mls) : this method is used to current thread is goes to wait state upto specified time that is in milliseconds.
Syntax:
public final synchronized void join(long mls) throws InterruptedException, where mls is in milliseconds
Join(long mls, int nanos) : this method is used to current thread is goes to wait state upto specified time that is in milliseconds plus nano seconds.
Syntax:
public final synchronized void join(long mls, int nanos) throws InterruptedException, where mls is in milliseconds.

What is Thread Scheduler?


Thread Scheduler means the JVM thread using preemptive and priority based scheduling algorithm.All Java Threads have a priority and the thread
with the height priority is scheduled to run by JVM.In case of two threads have the same priority it follows FIFO order

super keyword?The super keyword is used for refers to superclass (parent) objects and It is used to call superclass methods,
and to access the superclass constructor.

Can Static method be overridden?


NO, static method is not overridden in java because static method of parent class is hidden in child class but static overloaded
methods are possible but different parameters

difference between Exception and error in java?


Error is a result from system resources but all errors are comes at run time and unchecked so we cannot handle errors. Exceptions are
checked or unchecked exception but we handle Exception at compile time or runtime.

What is Custom exception? Custom Exception is nothing but user defined exceptions or own exception derived from
exception class

You might also like