Win a copy of Spring Boot in Practice this week in the Spring forum!

Jason de Vere

+ Follow
since Jul 01, 2021
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jason de Vere

Sorry, what I meant was that the list is mutable, since that is what I was changing. The string was meant to be totally replaced with the line: fruit = fruit.replace(substring, "alloon")

I didn't really understand your explanation but it did help me see that I never actually touched the list. I would have said I changed a copy of one of the list's values, but I'm sure that's not correct either. My solution would be:

Thanks for the help.
2 months ago
Can someone explain why this won't work?

output: ['bananas', 'apples', 'pears']

The list remains unchanged, even though it is a mutable type. It works fine it it's not in a list:

output: ['balloons', 'apples', 'pears']

2 months ago
Thanks. Exactly what I was looking for.
3 months ago
I keep seeing syntax in Python like this:

It's useful because we can do things like this with it:

I know what it does but I don't know what this syntax is called or where to read up on it. It seems to be some kind of implementation of a for loop, but inside a list. can anyone shed some light?

Many thanks
3 months ago

Campbell Ritchie wrote:

Jason de Vere wrote:. . . netbeans does . . .

Does it? Good grief!

It does indeed if you use the drag and drop code generation feature in the latest Netbeans. I agree, by the way, that composition is the way to do it, rather than inheritance. However, the inheritance approach is so widespread that it's seems to have become acceptable. I notice that Schildt avoids it though.
9 months ago

Rob Camick wrote:You have been given a link to the Swing tutorial. Read the tutorial and play with examples of the tutorial.

Your posted code looks nothing like the examples in the tutorial . For example, you should NOT be extending JFrame. You SHOULD be using "invokeLater()" to create the GUI.

Learn from the examples and from the API.

I know this is an old thread, but why shouldn't we extend JFrame? Netbeans does this and probably half the tutorials on the Internet do it.
9 months ago

Tim Moores wrote:It's done all the time :-) In the simplest of cases, you'd use the JAX-RS API to create REST WS running on your choice of servlet container (Tomcat, Jetty, you name it). The kind of client(s) (browser, desktop app, mobile app, other web apps) wouldn't matter much.

Can it be done with Spring?
9 months ago
How feasible is it to make a simple REST-based Java applications that works with both browsers and a desktop (Swing) front end? Is this a thing?

Many thanks
9 months ago
Ah yes I forgot to assign it exactly as you said it. A stupid error, but thanks!
1 year ago

I made an array of type 'node',  where 'node' is an object that holds two integer fields. However these 'node' objects must be manually inserted, and to do that I must first check that there isn't one there already. I thought I could do this by checking for null, but I can't. I get a null pointer exception. So how can I check if these array elements are present or not?

and then:

After instantiating Vmemory as memory and Node as node, the node object must be inserted in the array. To do that I must check that the array index doesn't have one of these objects in it already with something like if (memory.node[i] != null)...but that gives a nul pointer exception. I don't know how to do this can anyone help?

1 year ago

Junilu Lacar wrote:

Jason de Vere wrote:At the moment I'd doing a course in Algorithms and Datastructures, where most of the time we are discussing mathematical concepts and using pseudocode. The lecturers advise us to use C++ to implement it if we want to try it out. However, I haven't got a clue about C++ so I was doing it with Java. That is why I am avoiding using any advanced methods.

There's not much difference in C++ and Java as it relates to writing a program like this. The implementation language is not that important here. It's how you organize the ideas that make up your solution that's crucial. If you're studying algorithms and data structures then sure, you're going to have build almost everything yourself instead of using parts/assemblies that are already available for you to just use.

This is what i thought. I did some tutorials on C++ and it seemed straight forward enough. Then one of the University exercises provided us with some skeletal code in C++, in the form of one .hpp file and one .cpp file. The header seemed to be a just declarations of methods, while the cpp seemed to be the actual method minus their code. It looked straight forward but not matter what i did I could not get it to compile. The problem for me there is understanding the program structure and approach, rather than the ins and outs of using statements. So I did that in Java too.
1 year ago

Junilu Lacar wrote:The CS curriculum (over 30 years ago now) I went through had us learn a programming language first before we studied algorithms and data structures. That is, CS101 - Computer Programming (in Pascal) was a pre-requisite for CS204 Algorithms and Data Structures (in Pascal). It seems it would be difficult to learn about the latter if you didn't already have some basic mastery of the implementation language you were using.

I know. it's a bit strange. This is ADS2, Algorithms and Data Structures 2, a computer science course at London University. It is a level 6 course and the only prerequisite was that students have completed the required level 5 courses, none of which involved C++. In fact, one of them was ADS1, where they used JavaScript. C++ was offered only as an optional summer course, but I missed that opportunity because I transferred from another programme where we'd been doing Java. Although they have said that it is not mandatory to use C++ in ADS2. It would be nice to know the basics of C++ but having just invested some time in Java, I want to keep learning that for now.
1 year ago

Winston Gutkowski wrote:I think you're doing fine, and I particularly like the fact that you're explaining each step in your code. You'd be amazed how many experienced programmers forget to do that.

I also like the fact that you've named your method expand(), because that's exactly what it's doing. It's also a verb, and methods are usually actions of some sort.

However, what I don't like is that your method takes no parameters and returns no value. This makes it highly "coupled" - meaning that it doesn't stand on its own.

If you look at Junilu's example, his method takes the original array as a parameter and spits back a "modified" array, so the only thing left to do is assign it somewhere. And his code never references anything outside the method.
This is called "re-usability" and means you can - for example - copy and paste it into another program to do something similar, or (probably better) add it to a static library of generic "Array" methods, which is precisely what java.util.Arrays is.

As you go forward, what you'll discover is that most methods follow the "IPO" pattern - IPO standing for "Input - Process - Output".
That is: they take an input (in your case, an array), perform some sort of process on it (in your case enlarging it), and produce a result (the expanded array).

So the general signature pattern for most methods is:
{public/protected/private} final return-value method-name(parameter1, [parameter2, ...])

And don't forget that "final", even though it's redundant for private methods. Just get into the habit of adding it, because one of these days it will save your bacon. :-)



Thanks for your feedback.

At the moment I'd doing a course in Algorithms and Datastructures, where most of the time we are discussing mathematical concepts and using pseudocode. The lecturers advise us to use C++ to implement it if we want to try it out. However, I haven't got a clue about C++ so I was doing it with Java. That is why I am avoiding using any advanced methods.
1 year ago