How do you quickly compile and run in BlueJ? - java

I've used IntelliJ and VSC before, both of which had nice one-button solutions to compile and run, even going as far as having keyboard shortcuts for it as well. But unfortunately, for reasons I'm not in the mood to get into right now, and cannot change, I have to use BlueJ for certain projects in my class.
Don't get me wrong, I actually do like using BlueJ on simpler and smaller projects with it's simple interface, but one thing that really limits the speed I work at is having to hit "Compile", right-clicking the tester class, clicking "void main", and then hitting "Okay", EVERY single time I want to test the code. It's sluggish and takes infinitely longer than one button or a keyboard shortcut.
Is there any way, external modification or otherwise, that I could have a simpler method for compiling and running code in BlueJ? Even saving on one or two of these clicks would be greatly appreciated.

Related

'Problems' in VSC not finding basic typing errors

I'm writing code in Java using Visual Studio Code for a project I'm working on. I've been quite pleased with the environment until now, when the 'Problems' window seemed to stop detecting I've made basic typing errors. Right now it detects some errors, but it doesn't detect, for example, when I'm using variables that haven't been declared.
E.g. if I would just have a basic main function and run only the line "int a = 0 + foo", VSC would not detect that 'foo' hasn't been declared. Does someone have an idea about what could be causing this? I might add that I have not done anything out of the ordinary that could causes this (the best I know), and I've done 3-4 projects before without running into this problem.
I've only tried Googling the problem. Since I'm quite inexperienced in this field I don't really have any thoughts on what could be the cause of this.

In IntelliJ is there an easier way to set up the "Complete Current Statement" like eclipse?

I have used Eclipse for Java for the last few years and am trying out Intellij. I'm not using it permanently because it isn't as useful for quick programming (like how you can't just drag in files into the src folder) but for doing certain things, I think it will be faster for me.
I know there is Ctrl+Shift+Enter, but this is just annoying to press. Not because it is awkward to press, but because it takes so much time compared to just pressing enter like you can in Eclipse. I tried to rebind it to enter, but then it just doesn't work.
Is there a way to set up the Complete Current Statement so that it happens when I press enter?
Like, is there a way that I can bind it to Enter, but have it checked before the editor checks for enter as move to next line?
If you want only basic Code completion and not Type completion, use Ctrl+Space
IntelliJ and Android Studio are pretty highly customisable. You can rebind shortcuts too, I believe. Have you looked here? https://www.jetbrains.com/idea/help/configuring-keyboard-shortcuts.html
Also cheatsheet might be of use: https://www.jetbrains.com/idea/docs/IntelliJIDEA_ReferenceCard.pdf
And Android specific bindings: https://developer.android.com/sdk/installing/studio-tips.html

How can I make it so Eclipse automatically updates my code in a window as I edit it?

How can I make it so Eclipse automatically updates my code in a window as I edit it? I've seen the feature before in youtube videos but I cannot find it. For example : I change a JApplet rectangle width from 20 to 10, I want to see it update immediately.
I've seen Notch do this on development videos (Minecraft), it is awesome but I don't know exactly how he does it.
-- EDIT --
This has been bugging me so I went and googled "how does notch code" and found this on a blog page https://gun.io/blog/what-i-learned-from-watching-notch-code/. It doesn't say exactly how it was done but gives a good hint (HotSwap) and makes it seem like he set it up himself without external software. Here's the most relevant section:
Incredibly Fast Testing
He began by building the engine, and to do this he used the ‘HotSwap’ functionality of the Java JVM 1.4.2, which continuously updates the running code when it detects that a class has changed.
When building the engine, Notch wrote a function which would continuously pan the camera around and clip through the walls and keep the view on top, so he could make changes to the code and see the effects they made in real time. I’m used to testing by writing a function, building it, installing it on the device I’m testing on, and then seeing the result, which can take up to a minute at a time, so it’s easy to see how HotSwapping could save a lot of development time.
--- ORIGINAL POST CONTINUED ---
I get a similar effect by using groovysh though, works smoothly and can use all your java classes as is.
What I'll usually do is write all my code in java, then go and fire up "Groovysh" where it will give you a little window to enter commands (You may have to ensure the classpath works correctly outside of eclipse). I can then "new" any of my classes and call methods on them one line at a time. When you do myFrame.setSize([100,100]) you will see it change immediately.
A good test is to just run groovysh and type something like:
import javax.swing.*
f=new JFrame()
f.setVisible(true)
f.setSize(100,100)
or the groovier version:
f=new JFrame(visible:true, size:[100,100])
and you will see your frame resize on the screen. You can even drag it bigger and then do something like:
println f.getWidth()
to show your new width. It's fun to interact this way but it's more complicated if you want to actually change your class definition and see it pick up the change, I have no idea how Notch did that. I looked into it a little--it's possible he was using something like JRebel
It requires something special since you would have to dynamically reload the classfile into your running system on every save--something that should have serious classloader issues.
By the way there is also a way to get your Java program to throw out a little GroovyConsole which will allow you to inspect and modify all the variables in your running code (but again you can't replace definitions of existing classes).
Also see answer here:
Change a method at runtime via a hot swap mechanism

How on earth does he debug a running application like this, and more importantly, how can I?

"Debugception!"
You may notice that within the first 15 seconds of this YouTube video (from 1:01:01 to 1:01:16), Markus Persson (aka "Notch", creator of Minecraft) has somehow managed to save/update an application and attach a debugger to it while it was already under the process of being debugged, supposedly all with a simple keyboard shortcut. The previously coded application somehow magically became the newly edited one, and seemingly without relaunching it or spawning a new process... It's possible that this is just some form of locally remote debugging, but something about it just doesn't seem quite right.
I've spent several days Googling and asking around on how he was able to do this, yet to no avail. I've found no such option under Eclipse preferences, and whenever I try to save & debug an already running application, it simply launches a separate instance of the newly updated application, side-by-side with the older, outdated one.
Am I missing something? How was this possible?
How was he able to utilize such an astounding, powerful debugging feature?
Thanks in advance!
Update
Okay, so this appears to be a standard feature specific to Eclipse.
Coming from a background in NetBeans and Visual Studio, I'm astounded that this doesn't seem to exist elsewhere (or at least in NetBeans!)...
This is a built-in feature of Eclipse. If you edit a method while the program is running in debug mode, it will compile the new method, and replace the old method with the new version. If some thread was already running that method, it will jump back to the beginning (AFAIK; this might only happen when the program is paused).
You don't need to re-launch the program or set any special preferences. Just edit and save, and the magic will happen.
Eclipse can't always figure out how to merge your changes into the running program - usually if you changed anything outside a method body (including the method's parameters or return type). In this case, you will get a warning dialog, with the option to stop the program, restart the program or ignore the changes.

Java eclipse - value changes itself at the start of the program

Usually I know what the problem is or how to describe it. But this is just beyond my understanding.
I have a set of public static variables in my main class, the first thing that happens in the main(String[] a) method of the project is displaying two of those. But for some reason when I changed it in the declaration, the program still runs of the old one. I have attempted removing the static and calling them from within the method with the same result. As far as I can test all variables in this section of the program suffer from the same problem.
Here is the screenshot of the code and variable (I made a break point on the main method just to be sure nothing else runs):
In case this matters, I have actually changed computers since the last version of the app, I have a new installation of everything but I rebuild all directories as they were and besides this variable change (or lack there of) everything runs with no issues.
Ok it took a bit of thinking outside of the box but I've fixed it (not all steps may be required, but when tried on their own they didn't work):
Close all tabs (files) in Eclipse
Close Eclipse
Open and save (without editing) the .java file in other program (like Notepad++)
Open Eclipse
Right-Click inside Package Explorer and 'Refresh' (or use F5)
Open the file and build the project
It's a very strange bug and I hope if someone else finds it the 'fix' will work for them.

Categories

Resources