Calculating energy from mass and light speed I'm learning Java JDK 1.8 since one day and I'm using Java's methods to the first time. I have never used Java before because I'm a Python/Django developer.

I created a method which let to get energy in function of two parameters: mass and light speed. I would like to know if my method is well-written or if I made some mistakes about method, call, etc.

import java.util.Scanner;

public class methodes {

    public static double Energie(double m, double c)
      {
       return (double) (m*Math.pow(c, 2));
      }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int C = 300000 ;
        double m ;

        System.out.println("Valeur de la masse en kg : ");
        m = sc.nextDouble();

        double E = Energie(m,C);
        System.out.println("Pour " + m + " kg donné, l'énergie équivaut à " + E + " Joules");

    }

}
The implementation looks fine. Only the conventions on capital letters and spacing might be a bit different in the java community.

A class name always starts with a capital letter

public class Methodes


General utility classes are usually called Util but Methodes is fine depending on your own project preference. Especially when you're not native English it might change depending on who you work with, and how well you know the language.

Method names start with a lower case. And the opening { is placed at the same line as the method name

public static double energie(double m, double c) {
    return (double) (m*Math.pow(c, 2));
}


If you really want to place { at the line after the method name that's fine as long as you're consistent. So either do it always, or do it never. (big discussion in general about which is better, the community overal prefers on the same line).

Variables start with a lower case letter and are camel case, constants are written full uppercase and separated with _. Preferably use meaningful names, although m, C and e in this context are already pretty decent.

public class ExampleClass {
    //this is a constant. Since java 7 (?) you can also use _ in numbers to read easier.
    public static final int SPEED_OF_LIGHT = 300_000;

    public static int calculateEnergy(double mass) {
        return (double) (mass*Math.pow(SPEED_OF_LIGHT , 2));
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("Valeur de la masse en kg : ");
        double mass = sc.nextDouble();

        double energy = calculateEnergy(mass);
        System.out.println("Pour " + mass + " kg donné, l'énergie équivaut à " 
                          + energy + " Joules");
    }
}