JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To make your Ukley class sortable you make it implement Comparable. Comparable is an interface with one method - compareTo(other) - that you implement by comparing the year, then the month etc.
Once you do that you can use Collections.sort to sort any list of Ukleys.
Check the web for examples of Comparable

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My ambitions to do a PhD in Theoretical Physics were destroyed when I discovered the joys of cannabis in 1968. My resulting BSc grade left me looking for a job. IBM offered me one as something called a "trainee programmer" which sounded quite interesting. The rest is history...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I need someone who can write the program and explain it to me

Do you have the slightest idea what a university course is for? What are you studying - a BA in plagiarism? A BSc in cheating?
Your C++ is there to teach you how to write programs in C++. It's not easy, but most students manage it.
If you don't know how to write the code, go back over your course materials. If you still don't know how to start then pick a more suitable course such as hairdressing.

Валенти commented: I know the code, but this is my term paper and I have to defend it. +0
rproffitt commented: +1 +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You must have a new nestedList for each parent. Having just one and re-using it is not the answer because all the parents will share the same values. Remember that the parents just have a reference to the nestedList. Re-use the list and they will all have references to the same list. Change that list's values and they will all see the same new values. This is not a problem about RecyclerView; it's just basic Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's why you use Lists not an arrays. Just create a new one and keep adding members as required. This seems very simple. Am I missing something from your requirements?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like you have just one nestedList for all of the parents. What you need is a new nestedList for each parent.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are almost there for the yes/no.
You correctly read the user's input into the variable N, but then you compare the wrong variable (n) with "No" and `"Yes".

It really helps if you give variables meaningful names because the code is then easier to read, and mistakes are more obvious,
Eg compare your code with this (just the names changed)

String userReply = scanner.next();
if (userReply.equalsIgnoreCase("no")). etc
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why not List<List<String>> ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

One tiny point… XML is alive and kicking in Java 17. It’s just the EE related JAX stuff that was removed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean the Java 7 that was released in 2011? Last public updates 2015? With all its unfixed bugs and security vulnerabilities? The 7 that's so old it doesn't even have lambdas?
Unless someone is forcing you to use that at gunpoint you should stop doing anything else until you have updated to Java 17 (the current long term support version).

rproffitt commented: +1 +16
Saboor880 commented: I agree with you . But the problem is I had written the code of that specific application in java 7. Will this app run flawlessly with Java 17? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Derby is not included in current JDK distributions, you need to download it separately and add the jars to your classpoath or project libraries.
Maybe your Windows JDK is old (pre JDK 9?) or maybe it was downloaded at some time in the past and is still there?
Ps The old ClassForName thing has been obsolete since Java 6. It's embarrassing how many web tutorials still show it.
All you need is getConnection with a suitable URL, eg

        var dbURL = "jdbc:derby:/users/james/derbyTest;create=true";
        Connection conn = DriverManager.getConnection(dbURL);

(Yes, I just tested that under Catalina on a M1 Mac)

Saboor880 commented: I am using Java 7. I am trying to add Class Path on my clients PC using terminal. Terminal is saying : access denied +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you call setup you always pass 0 as the index, so all the Tile instances are stored in tile[0] and all the other elements of tile are still null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you instal the MacOS Derby jar? Did you add that jar to your CLASSPATH?

See https://db.apache.org/derby/papers/DerbyTut/install_software.html

Saboor880 commented: James the Derby comes already with JDK. Do I need to install it Separately Specially on Mac? Because on windows the program is running perfectly. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Dani is right. But to specify a location within your home folder in MacOS use the Tilda, eg ~/Documents/softechdb

Saboor880 commented: I know I am replying very late, Yes it was the Path format error. But there is only one problem +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, definitely a missing import.
In general we would advise against importing whole libraries (eg. import java.util.* ) because you are adding a huge number of names that you don't know to your namespace. That can lead to really baffling errors when a name clashes (eg awt.List vs util.List), or even worse when you accidentally mis-spell a name and make a valid reference to some random class in java.util

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JCreator ? Never heard of it. wikipedia shows its last release as being in 2015, and the web site that links to is no longer there. It doesn't even use the standard JAVA runtime. Unless someone knows better it looks like a real dead-end. Best avoided.
If you want a Java IDE the "big 3" are Eclipse, IntelliJ IDEA, and NetBeans. In my opinion Eclipse and NetBeans are best suited to professional developers - feature-packed but a huge learning curve. IntelliJ IDEA is the one I would suggest for a beginner, but BlueJ is also popular.
But remember you don't need an IDE at all for simple programs, and you may get a better grasp of the basics by using a simple text editor and Java.exe

rproffitt commented: I find instructors to make up the lesson plan and then never update it for a decade or more. +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like you are using a directory inside c:\Program Files\ for your own files. That's never a good idea.
Create a directory in your home for such use. Make sure that's the working dir in your command prompt. Make sure the JDK dir with javac.exe etc is in your PATH.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How far have you got? What’s stopping you?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That code does not match the exception - it has no ImageIcons

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without seeing the code there's no way to know.
Why are you trying to get the graphics context? The usual way to draw stuff in Java is to subclass JPanel and override it's paintComponent to draw whatever is needed. Anything else can get very messy because you will be fighting Swing's double buffered smart painting, rather than working with it. Have a look at https://www.oracle.com/java/technologies/painting.html

dgrovespdxdgpdx commented: True, and to do that you need a graphics context. Trying to do that is when I get the error. Is there a way to post the code? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Good choice! Any problems come back here and I'll help.
For starters I highly recommend Oracle's tutorial

dgrovespdxdgpdx commented: Thanks again. I will check it out. I need all the help I can get. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have options here:
Populate the JPane with two JPanes left and right (use the default FlowLayout) then populate the left pane with the canvas and right pane with a vertical stack of components (use a BoxLayout or a GridLayout).
or
GridBagLayout will do it all. Steep learning curve but this is the one to use if you're really fussy about getting complex layouts just right, especially when they're resized.

dgrovespdxdgpdx commented: Many thanks for the response. I will try GridBagLayout. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Given some way to set memory bytes, then it's totally possible. I did something like that with an IBM System 7 process control machine when we were preparing low-level software around 1970 in preparation for the first hardware shipments. It didn't even have an assembler at that time, so I hacked one together in APL and punched the resulting binary onto paper tape. We then set the hardware to read the contents of the tape verbatim into memory starting at address 0 then start executing at address 0.

So all you need to do is to write the necessary minimum code in an assembly-like language and compile it by hand into binary for input to the hardware.
The main (only?) problem I see is that, where you could do something useful on a System 7 in a few kilobytes, you will need megabyte upon megabyte of code for x86 class machine. With zero transcription errors.
Good luck. Maybe your children and grandchildren will be able to take over and finish it for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Help: yes. Write it for you: no.
What help do you need to get started?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How close is the 1:2 since there's that one green slot.

Like I said, with one zero its 18:37 (ie 1:2.055). With 2 zeros its 18:38 (1:2.111)

rproffitt commented: "This house always wins." +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

roulette wheels generally have slots with both a color and a number, and you have to get both right to pay off

Each number is red or black according to a fixed pattern: "In number ranges from 1 to 10 and 19 to 28, odd numbers are red and even are black. In ranges from 11 to 18 and 29 to 36, odd numbers are black and even are red." (WikiPedia).
So a bet in a number is implicitly a bet on a colour and still only gets the 1:36 odds
Conversely a bet on a colour is independent of the number and gets a 1:2 payout.
(Strictly speaking with one or two zeros the odds are 1:37 or 1:38 for numbers, 18:37 or 18:38 for colours.)

Schol-R-LEA commented: Oh, I didn't know that. My apologizes. +15
rproffitt commented: How close is the 1:2 since there's that one green slot. +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you get the value from the 3rd text field you could check if it's empty and treat that as a zero, eg something like

int value3;
if (field3.getText().trim().length() > 0) value3 = Integer.parseInt(field3.getText());
else value3 = 0;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's not clear what yo are asking... can you explain your question in more detail?

Just_3 commented: and third textfield need to insert value . So, what can I do with this problem? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Assuming that your results should include "project management" rather than "project", then it looks like the logic is something like:

for each word in all words
    if the word is in keywords
    and the previous word is in keywords
       the previous word and the word form a multi-keyword

(etc for triple etc)

is that correct?
If so, what's blocking your progress?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

wow, all that uncommented code with zero error handling just to replace getDesktop().browse(uri);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The instructions are pretty clear and detailed, so what exactly is stopping you from making progress?

Ps: what is the ConsoleInput class? It’s not part of the Java SE API.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

SimpleDateFormate? Where does that come from?

Did you mean the standard API class SimpleDateFormat ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I've been building Java GUIs since the mid 90's and in my opinion the best builder is no builder.
Yes, you can drag and drop a pile of controls into a layout, and get a few hundred lines of incomprehensible code, but as soon as you start to think about re-sizing behaviour or multiple target screen resolutions it all goes Pete Tong. It's a total maintenance nightmare.
If it's a simple dialog just stick with a default BorderLayout with a simple sub JPanel or two.
Anything more complicated then draw it out on paper and be sure where all the underlying grid lines are and how they should move on a re-size. Then code it using a GridBagLayout.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

99% of the time this problem arises because the keyboard focus is not on the component that has the listener. It can often be fixed by the slightly tacky approach of adding the listener to all the JComponents involved.

The better solution is explained in this Oracle tutorial.

ps: looping with a sleep has problems as the app gets more complex. Use a ScheduledThreadPoolExecutor to run your updates at a fixed speed (and to simplify your code!).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's the it was. My first real program as a trainee programmer for IBM in 1969 was hand-written over a weekend at home on a hundred-odd pages of coding forms. On Monday they went to the punch bureau to be punched into 80 column cards and by by Wednesday they were fed into an IBM 360/30 and on Thursday morning I got my first set of compiler error messages in my (physical, plastic) in box.

rproffitt commented: Also, almost nightly we would hear "And that's the way it is." - Walter Cronkite +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This web site may be the answer...

It seems there are "zero rated" web sites set up by various governments and ISPs for social purposes - especially for educational or COVID-relate info. Somehow using these sites is literally free from any ISP data usage charges or requirements. "Bug hosts" are zero-rated sites with known security holes that allow you to use them as a kind of proxy to access ordinary internet services. Ha Tunnel seems to use these bug hosts.

jwenting commented: that'd be highly dependent on your mobile network... +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Basically these kind of Apps allow you to access internet even if you don't have data at all

I believe you are mistaken about this. VPNs and tunnels still need to transmit your bytes over your internet connection.
What makes you think otherwise?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

System.out.println("pennies is 2");

rproffitt commented: 2 pennies? I wanted a peanut. -Homer Simpson. +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In theory you should be able to code and test on a sufficiently up-market Android phone.
There are also quite few apps that teach you the basics of programming on Android or iPhones. They coud be a good place to start.
In any case it's going to be painful working on such a small screen.
With enough patience I guess you could become fairly competent at writing code, but you;ll never be able to develop skills around the toolkits and frameworks that represent 90%+ of the knwledge that a commercial programmer needs.

Did you ever seen anyone who can be perfect ?

No. Not even me :)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

rproffitt commented: Yes, it seems like another form of ransomware

Worse than that - it woild be dishonest ransomeware because the perpetrator has admitted to not having the means to decrpt the files.

rproffitt commented: I know folk dislike it but the perp may be lying. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What possible reason would any sane person have to encrypt huge swathes of thir hard disk with no way to decrypt them.
Or is this intended as a weapon to cause massive harm to someone else's machine?

rproffitt commented: Yes, it seems like another form of ransomware. +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ps you may want to add a note about how text blocks can contain single and double quotes with escaping them... it makes a great improvement in readabiltiy for things like sql commands where there are lots of quotes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I love the way these posts reveal little goodies hat have slipped into Java over time. I failed to notice String.indent (new in Java 12), and that also lead me to discover stripIndent() which arrived with Java 15.

I also love String'sformatted(...)method (new in Java 15) that works so well with SQL commands in a text block

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The filter() and map() methods automatically perform the Optional emptiness check for us, and return an empty Optional object downstream

Thank you so much for this little gem.

I was always disappointed with Optional, too much overhead and verbiage compared to the ?. syntax of some other languages. But I hadn't realised the way they work with streams, and that changes everything.

Great thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ankitdixit:

In your opinion, why is an online web-basedIDE better than an IDE on your own computer?

rproffitt commented: So you don't have to worry if your code is kept private or safe any longer? +16
jwenting commented: it isn't. They're slower, usually very clunky, and of course you've no idea whether your code is secure from being stolen by whomever runs the website +16
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Good stuff.

In addition to the above, I'm a big fan of the classes in Collections.unmodifiable , eg Collections.unmodifiableList. Collections.unmodifiableMap etc
Anytime you need to give limited access to a private Collection just provide a getter that returns the Collection wrapped in the corresponding Collections.unmodifiable. Now the user can see the contents but not modify them. These classes are just a wraper round the original Collection, so are very lightweight.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Googling "pin block encryption java" got me. lot of hits. Is that what you meant?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The brute force search is a good solution for a small dictionary and a small number of searches, but gets very CPU intensive otherwise.
I hit this implementing a Scrabble solver where each move requires checking all the subsets of 7 or more letters against a dictionary of 230k words.
There's a solution that trades a 1 second startup cost for sub-microsecond searches. If anyone's interested I can share it here.
JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

AFAIK there isn't anything, which is why I hacked this together a while back.
Feel free to use it without any warrenty.

SImply call ConsoleWindow.withInput(); and continue to use System.out (or err) as usual. Read from System.in as usual, eg via a Scanner.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import static java.awt.GridBagConstraints.*;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;

/**
 * Creates a window with a scrolling text pane diverts all subsequent System.out
 * and System.err to it allows system input via text field and enter button
 * "cls\n" sent to System,out or err will clear the window
 *
 * Default action when closed is to exit the whole app, but can be overridden
 *
 * eg: ConsoleWindow.withInput(); // now System.in/out/err go here
 *
 * @author James
 */
public class ConsoleWindow extends JFrame {

    // factory methods for window with/without input field...
    public static ConsoleWindow displayOnly() {
        return new ConsoleWindow(false);
    }

    public static ConsoleWindow withInput() {
        return new ConsoleWindow(true);
    }

    // (optional) override default window close action (exit program)
    public ConsoleWindow setClose(Runnable r) {
        // Runnable to execute when this window is closed.
        closeHandler = r;
        return this;
    }

    // end of public members.  Private implementation follows...

    private final String CLEAR_SCREEN = "cls\n";

    private final JTextPane textPane = new JTextPane();
    private final JTextField inputField = …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As was the case with manual labour, smart machines will increasingly offer better price/performance than humans over more and more activities, replace them, thus creating more unemployment. That will be true not just of existing jobs, but also any new jobs that the change creates.
In countries with an ethos of social social responsibilty (Sweden etc) the "utopia" is entirely possible.
In countires based on selfishness (USA etc) the wealthy who own the machines wil continue to keep all the gains for themselves regardless of the consequences for their fellow countrymen. Everybody else will either get a job providing personal services to the rich, or join the abandoned sub-class to survive as best they can on scavenging and crime. Is that pessimistic? I think not, it's already happening.