DEV Community

Calin Baenen
Calin Baenen

Posted on

IntelliJ doesn't open .class files, unlike VSCode???

I was suggested IntelliJ as an IDE for Java, since it's "better" than VSCode (in my experience, it looks weird in comparison, and isn't as "easy" to use), but, I tried ctrl+lclicking on String, but it said it couldn't find a definition, I tried it with some other java.lang classes, and apparently none of them are defined? Why?
VSCode never had an issue, and this IDE feels like a downgrade.

Can anyone explain how I can get this feature (viewing classes by ctrl and lclicking on the name) to work, and how I can make it more like my old VSCode setup?

Thanks.
Cheers.

Top comments (25)

Collapse
 
alainvanhout profile image
Alain Van Hout

Let's take a step back here. Could you first answer of the following questions, so that we can get some idea about what your goal is:

  1. Why do you want to open a class file?
  2. What is it that you want to do with Java? For example, do you just want to play around with the language? Or are you using Java as a way to learn the basics of coding/programming? Or do you ultimately want to do professional software development, using Java?
Collapse
 
baenencalin profile image
Calin Baenen

To answer question 2, I want to kind of dip into a more proff environment. I'm using the language to make a game (one you may or may not know, "RuntDeale").

To answer number one, just to play around, and look at the methods myself, I want to look at the .class file so I can see what's going on BTS, so I know I'm using something properly (should there be no documentation to help).
Plus, I personally think looking at the code myself is fun.


Hopefully these answer your question. If you need any more data, lmk.

Collapse
 
alainvanhout profile image
Alain Van Hout

In that case, it's relevant to mention that a professional Java developer generally never looks at the bytecode inside a class file, except in very very rare circumstances. A better way to see whether you're using library or language feature properly, would be to test your assumptions against what you actually get, for example by writing unit tests (which is an important skill in professional software development). As for the bytecode, that's not what most would consider the 'code'. The code in .java files, that you write yourself or use through libraries, that's the actual Java code.

It's probably also useful to first have a look at an IntelliJ tutorial: jetbrains.com/help/idea/guided-tou.... That will allow you to get a grasp of the basic features and counter some assumption you might make based on previous experience with editors (rather than IDEs). There's obviously a learning curve there, but it'll be smaller then if you'd need to fully customise editor to efficiently work with Java.

Software development in general, and Java development in particular, requires a fair amount of time and effort to get started and to eventually get good at it. Trying things out, but also googling a lot and asking for input from other people, will help with that :-).

Thread Thread
 
baenencalin profile image
Calin Baenen • Edited

I wasn't looking at the Bytecode, I wanted it to decompile it to raw Java, so I could see the REAL code.
I don't want to disqualify the nice block you wrote ne, but VSCode also decompiled BC to let me read the Java.

Thread Thread
 
alainvanhout profile image
Alain Van Hout

In IntelliJ I regularly make use of libraries that consist of jar-packaged class files, and there I can easily just ctrl+click (or cmd+click) on those the usages of those classes and thereby open the decompiled bytecode (though IntelliJ often also allows easily downloading the source files for those, so you can look at the actual Java code rather than decompiled bytecode). But there the decompiled code is just a stand-in for the actual source files, because it's those that I'm interested in (to do my job correctly).

As I mentioned before, looking at bytecode files (whether compiled or decompiled) is generally not something that needed for Java development. You can of course do that, but there's not much point in it (= it won't improve your basic programming skills), and it requires effort that could be put to better use. Of course if you want to play around with it, then that's also fine. But my answer here is based on your reply to my question "What is it that you want to do with Java?". That's why I started with that question.

Thread Thread
 
baenencalin profile image
Calin Baenen

Mmkay.

Thanks for the advice(? Right word?).

Collapse
 
siy profile image
Sergiy Yevtushenko

Probably it worth to look into some IntelliJ tutorial. It's quite naive to expect that complex tool will be immediately intuitively understandable. In particular, setting up Java project in IntelliJ first time requires additional steps such as configuring JDK. JDK also should have sources installed. Once you configure JDK and IntelliJ finish indexing, you will be able to navigate to all available classes.

VSCode is just a bloated text editor. Unlike real IDE's it has no "understanding" of the code and can't perform advanced operations like refactoring, usage search with separation of found usages into categories, suggesting code improvements or type-sensitive autocompletion.

Collapse
 
baenencalin profile image
Calin Baenen

It seems to be able to do refactoring(?).

Note: What is refactoring? It's never really made sense to me.

Collapse
 
redcreator37 profile image
RedCreator37

Basic refactoring, yes. Where IJ excels at are advanced refactors, things like extracting methods/superclasses, analyzing dataflow, finding duplicated code and so on. Sure, you can do the same using VSCode, it's just sometimes more time consuming (and you might end up breaking other things in the process).

This is possible because IJ first indexes the entire project and therefore "understands" the structure of the code and its dependencies. Hence it's important that you set up the project properly (as Sergiy said). IJ is just as complex as any other "professional" software (ex. Movie Maker vs. Premiere Pro, or MS Paint vs. GIMP).

Take time to learn it properly and it'll save you a lot of hassle in the future. But don't immediately discard it as "Poor quality" and "POS" just because it has a steeper learning curve.

Thread Thread
 
baenencalin profile image
Calin Baenen

Sure, complex tools will look complex, but why don't complex tools also have beginners in mind? I know, it'd be strange for a beginner to use such a program, but I think it'd be smart for a complex program to have a more basic UI, with a serving of basic features; being able to switch between the two (or three, for a "intermediate" UI) at any given time.

But thanks for your help, and understanding.

Thread Thread
 
redcreator37 profile image
RedCreator37

It's something they're actively working on. They've recently added a "light edit" mode to edit a file without creating a new project, revamped the Version Control and Run menus, revamped the Run configurations dialog and so on. It's fairly hard to design a UI that at the same time looks simple to beginners and appeals to all advanced users.

Thread Thread
 
baenencalin profile image
Calin Baenen

Again, that's why a toggleable option would save the day.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

In fact such an option has very little sense. It will not take long when you'll be using and understanding most of the menus and options.

Collapse
 
siy profile image
Sergiy Yevtushenko

martinfowler.com/books/refactoring...

Refactoring is one of the fundamental techniques for any software developer. In short, refactoring is the reworking code to improve its characteristics (design, readability, extensibility, etc.) without changing functionality of the code.

Collapse
 
dhruvgarg79 profile image
Dhruv garg • Edited

As someone who uses both daily. There is no comparison that for java Intellij Idea is hands down better than VS code.

From the problem you are describing I think project JDK is not selected. check that. otherwise class definition error wouldn't have occurred.

Collapse
 
baenencalin profile image
Calin Baenen

Wdym the project SDK was not selected??

Collapse
 
dhruvgarg79 profile image
Dhruv garg • Edited

from project structure settings check if any JDK is selected.

Just google it, "how to select project sdk in intellj idea"

for me intellj shows decompiled code formatted beautifully(when viewing any library code). reader mode of intellj idea 2020.3 is just awesome.

Thread Thread
 
baenencalin profile image
Calin Baenen

I know VSCode is juat an over the top text editor, but I never had to dp this.

Why xan't IntelliJ just do all this for me? It seems to overcomplicate a process that (to me,) VSCode did easier, automatically.

Also, "project"??? I don't understand. Like a package, or some shit?
Because all I'm doing is making my game on a per-file basis, and grouping my code in to packages that all get used by Main.java.

Thread Thread
 
dhruvgarg79 profile image
Dhruv garg • Edited

frustration is understandable but intellj is also used for complex projects and for those it does a best job in my view (you certainly won't like other java IDEs 😂), though there is lite mode which you can start from terminal. Lite mode does not work for me as I have installed idea using snap.

I would suggest to just google these problems and watch any Intellij tutorial on YT, also intellij has plugin which helps beginners to learn IDE features. In long run it will help you.

Otherwise, VS code is not bad you can still do most of the work by using plugins.

Collapse
 
c7tt8nt2p profile image
c7tt8nt2p

I guess the ctrl+click exists by default in IntelliJ you don't have to do anything. Did you configure JDK properly?

Collapse
 
baenencalin profile image
Calin Baenen

I didn't change my JDK in between the time I was using VSCode and IntelliJ.
It just says no definition exists for String, Object, JFrame, etc...

Collapse
 
c7tt8nt2p profile image
c7tt8nt2p

crtl+alt+shift+s to open a project structure window and see the project SDK which version of JDK are you using, is it the valid one? or try to change it to a new one (there is an option to download a new JDK in the same window)

Thread Thread
 
baenencalin profile image
Calin Baenen

All I did was install IntelliJ, and open my .java files with it. Nothing else.

I'm using JDK 15.0.1.

Thread Thread
 
gklijs profile image
Gerard Klijs

Yes, so you need to configure it. When you open as a project, by opening the pom.xml for example, it will ask for it. I'm not sure IntelliJ is objectively better. I do prefer it, but tbh I didn't realy try any other IDE. If VSCODE works for you why not stick to it?

Thread Thread
 
baenencalin profile image
Calin Baenen

Because people say IntelliJ is better, and I was recommended it because it can "do things VSCode can't".

But, for me, it's the worst tool I've ever used.
It has poor quality, poor indentation, it's way more of a hassle to use than VSCode.
Why would ANYONE want to use this POS tool!?
What about IntelliJ is attractive??