A construction machine comprising: a battery device that is capable to charge and discharge; an electric motor that is driven by electric power of the battery device, an engine that is mechanically coupled to the etectric motor, a hydraulic pump that is driven by the engine and the electric motor; and a controller that controls charging/discharging of the battery device, whereby the controller is adapted to control the charging/discharging of the battery device in such a manner that, in case that an average value of discharging current of the battery device in a unit period, in which a heavy load task where an output of the hydraulic pump is large and a light load task where the output of the hydraulic pump is smaller than the output of the hydraulic pump in the heavy load task are alternately performed, is equal or lower than a predetermined value, when the output of the hydraulic pump during the heavy load task is increased or a time proportion of the heavy load task in the unit period is increased, an average value of charging current of the battery device per the unit period increases, and characterized in that the controller is further adapted to control the charging/discharging of the battery device in such a manner that in case that the average value of the discharge current of the battery device in the unit period exceeds the predetermined value, when the output of the hydraulic pump during the heavy load task is increased or the time proportion of the heavy load task in the unit period is increased, then the average value of the charging current of the battery device per the unit period decreases. a battery device that is capable to charge and discharge; an electric motor that is driven by electric power of the battery device, an engine that is mechanically coupled to the etectric motor, a hydraulic pump that is driven by the engine and the electric motor; and a controller that controls charging/discharging of the battery device, whereby the controller is adapted to control the charging/discharging of the battery device in such a manner that, in case that an average value of discharging current of the battery device in a unit period, in which a heavy load task where an output of the hydraulic pump is large and a light load task where the output of the hydraulic pump is smaller than the output of the hydraulic pump in the heavy load task are alternately performed, is equal or lower than a predetermined value, when the output of the hydraulic pump during the heavy load task is increased or a time proportion of the heavy load task in the unit period is increased, an average value of charging current of the battery device per the unit period increases, and characterized in that the controller is further adapted to control the charging/discharging of the battery device in such a manner that in case that the average value of the discharge current of the battery device in the unit period exceeds the predetermined value, when the output of the hydraulic pump during the heavy load task is increased or the time proportion of the heavy load task in the unit period is increased, then the average value of the charging current of the battery device per the unit period decreases.