Found 33676 Articles for Programming

What is static import in Java?

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

725 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

979 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

309 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

How do we call a Java method recursively?

Lakshmi Srinivas
Updated on 18-Feb-2020 09:55:44

270 Views

Recursion is where which a method class itself.Examplepublic class RecursionExample {    private static long factorial(int n) {    if (n == 1)       return 1;    else       return n * factorial(n-1);    }    public static void main(String args[]) {       RecursionExample obj = new RecursionExample();       long result = obj.factorial(5);       System.out.println(result);    } }

How to find the real user home directory using Python?

Sarika Singh
Updated on 15-May-2025 18:21:27

17K+ Views

When working with the Python scripts, it is required to interact with user-specific files or directories and also it's essential to accurately determine the actual user's home directory. This is especially important if the script might be executed with elevated privileges like using sudo where default methods could mistakenly point to /root directory instead of the true user's home. Python offers multiple ways to retrieve the home directory and selecting the appropriate method which helps to ensure consistent and expected behavior across different environments and permission levels. In this articlE, we will go through the different methods to find the ... Read More

What is the difference between up-casting and down-casting in Java?

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

562 Views

Converting a subclass type to a superclass type is known as up-casting.Converting a superclass type to a subclass type is known as down-casting.

What are up-casting and down-casting in Java?

karthikeya Boyini
Updated on 18-Feb-2020 09:57:00

2K+ Views

Typecasting is converting one data type to another.Up-casting − Converting a subclass type to a superclass type is known as up casting.Exampleclass Super {    void Sample() {       System.out.println("method of super class");    } } public class Sub extends Super {    void Sample() {       System.out.println("method of sub class");    }        public static void main(String args[]) {       Super obj =(Super) new Sub(); obj.Sample();    } }Down-casting − Converting a superclass type to a subclass type is known as downcasting.Exampleclass Super {    void Sample() {     ... Read More

How to touch all the files recursively using Python?

Niharikaa Aitam
Updated on 01-Sep-2025 14:42:01

948 Views

In file system management, it's sometimes necessary to update the modification or access time of files which is commonly referred as "touching" files. This is useful in automation scripts, build systems or cache invalidation mechanisms. Python offers powerful modules such as os and pathlib to touch all files within a directory recursively. In this article, we'll explore different methods to recursively touch files using Python by ensuring each file's timestamp is refreshed as needed. Using os.walk() and os.utime() The os.walk() function generates the file names in a directory tree by walking the tree either top-down approach or bottom-up approach. It ... Read More

Why multiple inheritance is not supported by Java?

Sharon Christine
Updated on 16-Jun-2020 06:27:30

7K+ Views

Multiple inheritances lead to ambiguity.For example, if there is a class named Sub and there are two classes Super1 and Super2 and if both contains a method named sample(). And if the class sub inherits both classes Super1 and Super2 then there will be two copies of the sampling method one from each superclass and it is ambiguous to decide which method to be executed.

Advertisements