Optimizations in energy consumption are critical for battery-powered hard real-time embedded systems. Energy management is often accomplished by dynamic frequency scaling which requires compilers to insert special instructions in the code at appropriate places, which are then used by the operating system and the processor to calculate and change the frequency at these places in the code. The addition of code snippets for frequency change may affect the worst-case execution time of the program, which is a major concern for hard real-time systems. In addition to the above problem, run time calculation of the optimal frequency prohibits a compile-time estimate of the battery life by the system designers. In this paper, we present compiler optimizations for hard real-time Java applications executing on a time predictable Java processor, which reduces the energy consumption of the program while retaining the original worst-case execution time for the program intact. We also generate a compile-time frequency change schedule for the program resulting in compile-time estimates for worst-case energy consumption. We found that on average, reduction in energy consumption is better in run-time frequency schedule based mechanism but the compile-time frequency schedule allows us to get bounds on energy consumption at the compile-time.