Different students have different learning styles, which are corresponding to their performances and make them behave differently in the learning process. Discovering the learning style of the students can help the development of teaching plans the students would accept more likely. It is a pity that few people dedicate to programming the learning style diagnosis. In view of the learning style, which is always closely linked with the learning performance, the programming learning behavior is introduced to programme the learning style diagnosis. This paper identifies the learning style of programming students in the learning process through their behavior preferences. To make the diagnosis more accurate, Particle Swarm Optimization (PSO) algorithm is introduced. The experiments invite junior students, senior students, graduate students and teachers of the College of Computer Science and Technology in the authors' university to fill out questionnaires as data. The experimental results show that PSO provides a great contribution.