Found 4338 Articles for Java 8

What is a Locale class in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

123 Views

The java.util.Locale class object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to form information for the user. The locale is a mechanism for identifying objects, not a container for the objects themselves.

What is the purpose of System class in Java?

Lakshmi Srinivas
Updated on 30-Jul-2019 22:30:20

1K+ Views

System class belongs to the package java.lang. It cannot be instantiated. A System class provides − standard output. error output streams. standard input and access to externally defined properties and environment variables. A utility method for quickly copying a portion of an array. a means of loading files and libraries. Following are the fields for java.lang.System class − static PrintStream err − This is the "standard" error output stream. static InputStream in − This is the "standard" input stream. static PrintStream out − This is the "standard" output stream.

What is Callable interface in Java?

Sharon Christine
Updated on 30-Jul-2019 22:30:20

585 Views

The Callable interface is found in the package java.util.concurrent. The Callable object can return the computed result done by a thread in contrast to a runnable interface which can only run the thread. The Callable object returns a Future object which provides methods to monitor the progress of a task being executed by a thread. The future object can be used to check the status of a Callable and then retrieve the result from the Callable once the thread is done. It also provides timeout functionality.

What is Runnable interface in Java?

Swarali Sree
Updated on 30-Jul-2019 22:30:20

447 Views

If your class is intended to be executed as a thread, then you can achieve this by implementing a Runnable interface. This belongs to the java.lang package.

Can private methods of a class be accessed from outside of a class in Java?

Samual Sam
Updated on 18-Feb-2020 09:45:41

14K+ Views

You can access the private methods of a class using java reflection package.Step1 − Instantiate the Method class of the java.lang.reflect package by passing the method name of the method which is declared private.Step2 − Set the method accessible by passing value true to the setAccessible() method.Step3 − Finally, invoke the method using the invoke() method.Exampleimport java.lang.reflect.Method; public class DemoTest {    private void sampleMethod() {       System.out.println("hello");    } } public class SampleTest {    public static void main(String args[]) throws Exception {       Class c = Class.forName("DemoTest");       Object obj ... Read More

Where and how is import statement used in Java programs?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

229 Views

Wan import statement in Java is used to − Import user defined classes/Interfaces Whenever you need to access a class which is not in the current package of the program you need to import that particular class using the import statement. Example In the following example we are using the Math class to find the square root of a number therefore, first of all w should import this class using the import statement. Live Demo import java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(Math.sqrt(169)); ... Read More

What is static import in Java?

Krantik Chavan
Updated on 30-Jul-2019 22:30:21

509 Views

As import statement allows to use a class without its package qualification, static import allows to access the static members of a class without class qualifications. For Example, to access the static methods you need to call the using class name − Math.sqrt(169); But, using static import you can access the static methods directly. Example Live Demo import static java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(sqrt(169)); } } Output 13.0

Do I need to import the Java.lang package anytime during running a program?

Monica Mona
Updated on 30-Jul-2019 22:30:20

3K+ Views

No, java.lang package is a default package in Java therefore, there is no need to import it explicitly. i.e. without importing you can access the classes of this package. If you observe the following example here we haven’t imported the lang package explicitly but, still we are able to calculate the square root of a number using the sqrt() method of the java.lang.Math class. Example Live Demo public class LangTest { public static void main(String args[]){ int num = 100; double result = ... Read More

What is the difference between abstraction and encapsulation in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:20

685 Views

As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of e-mail, complex details such as what happens as soon as you send an e-mail, the protocol your e-mail server uses are hidden from the user. Therefore, to send an e-mail you just need to type the content, mention the address of the receiver, and click send. Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what ... Read More

How do we pass parameters by value in a Java method?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

185 Views

Passing Parameters by Value means calling a method with a parameter. Through this, the argument value is passed to the parameter. Example public class SwappingExample { public static void swapFunction(int a, int b) { int c = a+b; System.out.println("Sum of the given numbers is ::"+c); } public static void main(String[] args) { int a = 30; int b = 45; swapFunction(a, b); } } Output Sum of the given numbers is ::75

Advertisements