Chinese characters first came to Japan on articles imported from China. An early instance of such an import was a gold seal given by the emperor of the Eastern Han Dynasty in 57 AD. It is not clear when Japanese people started to command Classical Chinese by themselves. The first Japanese documents were probably written by Chinese immigrants. For example, the diplomatic correspondence from King Bu of Wa to Emperor Shun of the Liu Song Dynasty in 478 has been praised for its skillful use of allusion. Later, groups of people called fuhito were organized under the monarch to read and write Classical Chinese. From the 6th century onwards, Chinese documents written in Japan tended to show interference from Japanese. This suggests the wide acceptance of Chinese characters in Japan.When first introduced, texts were written in the Chinese language and would have been read as such. Over time, however, a system known as kanbun emerged, essentially using Chinese text with diacritical marks to allow Japanese speakers to read the characters in accordance with the rules of Japanese grammar.
The Japanese language itself had no written form at that time. A writing system called man'yōgana (used in the ancient poetry anthology Man'yōshū) evolved that used a limited set of Chinese characters for their sound, rather than for their meaning.
In modern Japanese, kanji are used to write parts of the language such as nouns, adjective stems and verb stems, while hiragana are used to write inflected verb and adjective endings (okurigana), particles, native Japanese words, and words where the kanji is too difficult to read or remember. Katakana is used for representing onomatopoeia, non-Japanese loanwords, and for emphasis on certain words.
source: wikipedia