The structure, stability and electronic properties of composite BxCyNz nano
tubes and related heterojunctions have been studied using both ab initio an
d semi-empirical approaches. Pure BN nanotubes present a very stable quasi
particle band gap around 5.5-6.0 eV independent of the tube radius and heli
city. The bottom of the conduction bands is controlled by a nearly-free-ele
ctronn state localized inside the nanotube, suggesting interesting properti
es under doping. In the case of nanotubes with BC2N stoichiometry, we show
that in the thermodynamic limit the system is driven towards segregation of
pure C and BN sections. This demixing significantly affects the electronic
properties of such materials. The same process of segregation into BC3 isl
ands is evidenced in the case of B-doped carbon nanotubes. These spontaneou
s segregation processes lead to the formation of quantum dots or nanotube h
eterojunctions. In particular, C/BN superlattices or isolated junctions hav
e been investigated as specific examples of the wide variety of electronic
devices that can be realized using such nanotubes.