Hi I'm looking for a thesis topic and I came up with the idea but I want to consult some of you first if this might be done.

Java Code Automatic Refactoring and Code Optimization.

but I have read that this might be mutually exclusive because code optimization might make your program long and difficult to maintain which contrast the idea of refactoring. Another question is does refactoring help with code optimization process? Please enlighten me.

So, if you have read that, what did you do to verify or disprove the legitimacy of the claim? Whether it is primarily coding or primarily a paper, you have to do the research.

You might also want to consider whether Java is the most appropriate language for this project: Another research topic.

Is it doctorate level or major level work?

thesis [ˈθiːsɪs]
n pl -ses [-siːz]
1. (Social Science / Education) a dissertation resulting from original research, esp when submitted by a candidate for a degree or diploma
2. a doctrine maintained or promoted in argument
3. (Social Science / Education) a subject for a discussion or essay
4. (Philosophy / Logic) an unproved statement, esp one put forward as a premise in an argument

I could imagine that you could pick up the topic and do series of papers on it and some major work after seeing where you end up. But do check widely and read up what you can find through net. Discuss the topic with instructors. Record your checking process and include it in your study credits for the preparation of the thesis.