The boy, named Azka Maulana Malik, had been trapped for two days and was found alive next to the body of his dead grandmother.
The boy’s mother had been killed in Monday’s quake.
The death toll from the magnitude 5.6 earthquake in the west of the densely-populated Java island now stands at 271, but authorities expect that number to rise because some remote areas have yet to be reached and heavy rain has hampered rescue efforts. About 40 people remain missing and more than 2,000 are injured.