Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why some java methods in core libraries end with numbers?

Tags:

It's common in a lot of classes in JDK, just a few examples:

  1. java.util.Properties
    • load0
    • store0
  2. java.lang.Thread
    • start0
    • stop0
    • setPriority0

Usually they are private native methods (like in Thread class), but sometimes they are just private (Properties class)

I'm just curious if anybody know if there is any history behind that.

like image 902
Petro Semeniuk Avatar asked Apr 04 '12 06:04

Petro Semeniuk


People also ask

What are the core Java libraries?

1 Java Core Libraries The core libraries consist of classes which are used by many portions of the JDK. They include functionality which is close to the VM and is not explicitly included in other areas, such as security. Here you will find current information that will help you use some of the core libraries.

How do methods work in Java?

A method in Java is a block of code that, when called, performs specific actions mentioned in it. For instance, if you have written instructions to draw a circle in the method, it will do that task. You can insert values or parameters into methods, and they will only be executed when called.

What are library methods in Java?

The standard library methods are built-in methods in Java that are readily available for use. These standard libraries come along with the Java Class Library (JCL) in a Java archive (*. jar) file with JVM and JRE.

Can Java methods have numbers?

The most basic data type of any computer language is number. Generally while working with numbers in Java, we use primitive data types which are byte, short, int, long, float and double.


2 Answers

I believe they are named like that because equivalent functions with same names exist in the code and just to distinguish between native helper functions and public functions they decided to suffix them with 0.

in java.util.Properties both load, store and load0, store0 exist.

like image 133
Mayank Avatar answered Oct 21 '22 06:10

Mayank


The 0 after the method name is done so to distinguish between public and private methods having same name .

Start function will call the start0 function. Those functions which ends with 0 is private method. And those which are not ending with number is public. You can check in any of the library.

like image 24
vikiiii Avatar answered Oct 21 '22 06:10

vikiiii