MgB2 and BeB2: A comparative study of their electronic and superconducting properties