JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

25 years? A mere beginner.
<boasting mode>I joined IBM as a trainee programmer in July 1969 and wrote my latest line of code three days ago.Yes, that's more than 50 years coding</boasting mode>
(but I think Reverend Jim may be able to top that?)

jwenting commented: ah, so you're not stone aged but walking with dinosaurs :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

half your life / 10 years sitting at a terminal hardly qualifies anyone as a "renaissance man"...

the term Renaissance man, often applied to the gifted people of that age who sought to develop their abilities in all areas of accomplishment: intellectual, artistic, social, physical, and spiritual. (WikiPedia)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Dimitrilc

OK, thanks for the reply. That's what I thought, but I just wanted to check that I hadn't missed something.

It is 100% valid Java, even if it's redundant. My preference is in the 60% who would skip it, so when I saw it there I immediatley started to look for a variable shadowing situation, while also wondering why that situation would have been created here.

The jetbrains survey is interesting. I seem to remember another of their surveys thats showed that jetbrains was massively more popular than Eclipse or Netbeans, which seemed suspicious. Maybe it over-represents jetbrains users?

JDK 8 is out of support. JDK11 is the current LTS, so moving to the new goodies (like HttpClient) makes good sense. Thanks for taking the time to prepare and post this. How about some more? :)
J.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Keyboard handling in Swing is always a challenge because the focus is often not where you think. You can often get round that by creating a keyboard handler and adding that to all the components where it could possibly make sense.

The "right" solution according to Oracle is not to use the low-level event handlers at all, but to use keybindings. See https://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm sorry, but I don;t have anything positive for yoi here.
Back in the day I contributed literally thousands of hours to helping others and thus creating value for DaniWeb. I certainly didn't expect to pay to do that.
With the current traffic there's little I can contribute, and litte that interests me (although we did get a couple of Java questions recently).
Increased rep power? To whatever extent that matters I think I have enough.
No ads? I don't have a problem with the ads.

Maybe that's all just me, or maybe it's not untypical of the "seasoned" members? If so you need to re-think the target market and look towards newer members who are looking to gain something from DaniWeb and could be willing to pay a bit to get it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its the other one, line 405, where the problem starts. What's on that?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

And what exactly is at com.mycompany.smarttraveller.Form.<init>(Form.java:73) (and the preceeding few lines)

ps (may be nothing)

at com.mycompany.smarttraveller.Form.<init>(Form.java:73)
at com.mycompany.smarttraveller.Form$8.run(Form.java:625)

that seems a bit odd. Form$8 is an anonymous inner class of Form, but it seems to be ceating a new instance of Form.
Is that what you intended?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, this is the right way, and will work just fine when NetBeans puts it all in a Jar.
We need to see the full Stack trace from the exception, and the exact line of your code that it refers to.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like your files are in the wrong place.
As used in your code, getResource will look for the files in same folder (or package if you are runnng from a jar) that the current class was loaded from. I don't see any class files in that directory.

It looks like you are using NetBeans?
If so, create a package called (eg) images in your project's Source Packages alongside the package containing your source code. Add all the image files to it. Reference them like getClass().getResource("/images/auth.jpg");
Netbeans will create the correct folder or jar struture for you and put things in the right place.

Here's an example

Screenshot_2021-07-26_at_12_51_44.png

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't like posting code for people to copy without understanding, so please do take the time to read and understand this in conjunction with my previous posts before copying it...

a.setVisible(false);
b.setVisible(true);
// create a timer to call its ActionListener after 1000mSec
Timer t = new Timer(1000, new ActionListener() {
       public void actionPerformed(ActionEvent evt) {
            b.setVisible(false);
            a.setVisible(true);
       }
  });
t.setRepeats(false);
t.start();

you'll need to import javax.swing.Timer and maybe java.awt.event.ActionListener

techlifelk commented: Thank you a lot +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ps:

There's the same problem with calling get on an ApiFuture - you will block the Swing thread while waitig for the future to complete. In this case you may not be bothered by that, but in general it's a bad idea.

techlifelk commented: I removed ith API Future but i am still confused on how to apply the timer could you please apply it for just one. Thank you +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, the solution is fairly easy, and absolutely standard, so it's worth learning.

What you wanted to do is:

a.setVisible(false);
b.setVisible(true);

Thread.sleep(1000);

b.setVisible(false);
a.setVisible(true);

... but it doesn't work because Swing won't update the screen until that method returns.

So what you have to do is get rid of the sleep and use a timer, like this

    a.setVisible(false);
    b.setVisible(true);

    // start a 2 second timer with its actionPerformed as
    // {
    //    b.setVisible(false);
    //    a.setVisible(true);
    // }

    // let your method return normally. When the timer 
    // expires that will execute the actionPerformed

See the API doc for details - the example code shows what you need. (Except you want the timer to fire once only, so you will also need to call setRepeats(false) before you start the timer)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

techlifelk commented: It is a void function

That doesn't matter.

Everything to do with Swing runs on the same single thread, including all your Listeners. That also includes any screen updaing. There will be no screen updates as long as one of your listeners has the thread. So it's essential that your listeners execute and return very quickly. Sleeping in a listener will block all Swing activity until the sleep finishes and the listener returns. That's why you don't see the panels disappearing and re-appearing.

techlifelk commented: Can you please give a fixing +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which thread is that method running on?
If it's the Swing thread (eg because it's responding to a button click) then it will hold up all Swing activity until it returns. Only after the method returns will Swing perform all those visiblity changes, and probably optimise them ot of existance anyway.

Thread.sleep is almost never the right thing to do in Java. What you should do is make the new panel visible then start a javax.swing.Timer with a 2 second delay. In the Timer's actionPerformed change the visiblities back.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Short answer: small projects (eg < 1 man-month) rarely need interfaces or abstract classes, but large projects use them to define exacty how different parts of the app will communicate with each other.

This section from Oracle's Java tutorials explains it pretty well.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess I would count as a "seasoned member". So what would I get that would be worth $60 in a year? I can't see the value proposition.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

IF your plan is to do nothing, wait until the day before the cutoff, then expect someone else to drop everything and do it for you...
... then nobody here is qualified to give you the kindof help you really need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i think you'll find that still adds the -1 to the total before exiting the loop.

Given the need to exit the loop after validating the input but before processing it I would suggest this pattern:

while true
   get and validate input
   if (input = SENTINEL) break;
   process input
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

plainText gets updated on each pass of the loop. Should be OK, but maybe... ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For what it's worth I tried a little test in Java and the AES encrypted output was always the same for the same input values.

I'm no expert, but from my reading of a few web sites the algorithm looks like there is no dependency on anything other than the explicit inputs,
Mybe the problem lies elsewhere in your code?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Two problems with that code:

It creates a second Scanner (line 20). Two Scanners on the same input stream is a formula for chaos. Either of them may read ahead from the stream thus preventing the other from seeing those characters, with unpredictable results. One program -> one Scanner(System.in).

It treats all invalid values of judge (eg "no") as equivalent to "Y"
The else continue does nothing. Line 26 should do some kind of error handing for invalid inout.

(But please let me thank you for posting clean correctly indented code - you;ld be surprised what tat some people post)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"Java 2": Oh yes. That label was created for Java version 1.2 (released December 1998). It was dropped after version 5 (released September 2004).

Looks like a teacher somewhere has failed to update his/her teaching materials for a decade or two. Very worrying.

rproffitt commented: "Today we'll learn to use a rotary dial phone and the IBM Selectric Typewriter." - Same teacher most likely. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think they are looking for a simple trainee exercise, not a commercial-grade full system.

What's "Java 2"? We're currently on Java 15.

rproffitt commented: I can only hope the teacher handed out a better description of the exercise. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You shoild be able to get the key from the BIOS by opening an Admin command prompt and entering
wmic path SoftwareLicensingService get OA3xOriginalProductKey

(however, you shouldn't need to do this as Windows should find it and activate automatically after installation)

rproffitt commented: Good to know. But for me, working far too hard as I don't need this info because... digital license, etc. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In Java hashes are calculated by the MessageDigest class.
Here's the documentation: https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/security/MessageDigest.html

Come back here if you need help after taking the time to read and understand that

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The close bracket on line 4 ends the class definition, so whatever follows has to be a new class/interface/enum.
Line 7 attempts to define a method inside the method definition starting on line 5. You cannot nest method definitions.

Plus (not exectly errors, but bad style):
Class names should be nouns - the kind of thing that the class represents.
Method names should be verbs - what the method does.
It's baffling that a method called "price" should return something called "service"
Java code is usually indented like this

int getTotal() {
   return quantity*unitPrice;
}

Worrying about names or indentation may look like nit-picking, but in reality it's essential for making code understandable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Reading existing code can be a good way to learn IF that code is of good quaility. Tha;s especially true of O.O. because most code written in OO languages does not follow real OO principles.
Reading poor or irelevant code will just give you bad coding habits and hold back your eventual skills development.

How do you find code that's good enough to learn from? That's really hard. For Java it would suggest the Java standard class library as a huge body of verified best practice. Maybe others here can suggest examples of non-trivial verified best practice object oriented C++.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

where to start? Start with design. Classes that represent the nouns of the probem domain with their public interfaces that model the verbs. Don't worry about code yet.
Here's a good site that talks through how to do that: https://www.eventhelix.com/object-oriented/object-oriented-design-tips/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm frankly baffled by the requirement for a static void method to calculate what should be an instance variable, using existing instance variables. It makes absolutely no sense.

rproffitt commented: I've seen bad programming habits taught in classrooms for decades now. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why write your own bubble sort when Collections.sort exists and does it better?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An ArraylIst of ArrayLists is like a 2d array. Which means that there's no single definition of what it means to sort it. Eg
Sort each sub list ?
sort the sublists within the main list according to some criteria ?
sort all of the data and store the result in the same sized 2d array?
(etc).

You need to specify what you mean by sort in this case.

ps: the Double class already implememnts Comparable, so you can use Collections.sort on a List of Doubles without any other code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hint (also applies to your other thread):

You can get the nth element in a List as follows: list.get(n)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

take a moment to think through the value(s) of j on lines 6 and 7.
on each pass of the loop you do the whole calculation for just one value of j, then you do that multiple times.

pseudo-code the solution on paper and step throught it a couple of times... don't write any java code until you are sure you have the logic right.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Go to adobe.com and purchase the kind of licence that suits you best.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What exactly is the point of this? How many people are going to do a clean install of WIndows 10 on a 32 bit machine in 2021?
To quote Microsoft: "Beginning with Windows 10, version 2004, all new Windows 10 systems will be required to use 64-bit builds"

rproffitt commented: TIL! Recently we've moved the line. What line? We get a lot of old laptops, we set the line to 64 bit CPUs for CloudReady installs. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which line and variable does the NPE refer to?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

looks like a simple array sort to me. If so the pseudo code is already well known and you just have to match it to the details of this implementation

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The instructions are almost pseudo-code for the actual solution. Each sentence represents a few lines of code, all in the right order.
So start with "Read from the user the number of cities " and code that, then go on to the next line.

If you get stuck come back here, post what you have done so far, explain what's blocking you, and you will get help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It seems like it's looking for your java file in the wrong place.
It's looking in c:\Program Files\java, presumably because that's your working directory (?). That's a really bad place to put your own source code projects.

What directory is Main.java in?
What exectly is the command you are using?
Is c:\Program Files\java in your system PATH variable?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Its a very bad idea to have multiple Scanners usig the same input stream (System.in). You never know which Scanner will read the next character from the stream, or which Scanners may have read ahead and thus consumed characters that you hoped to read with a different Scanner.
Create just one Scanner at the start of the program and use that for everything.

Your bracketing/indentaton style is confusing (although perfectly legal).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I've been programming in Java since the mid-90s (working for HP Consulting), and programming since 1969, but I'm not prepared to call myself a "master". The more I learn, the more aware I am how much I still don't know.

Anyway, my first answer is that the only way to progess past beginner is to work on real-life applications but never never do just the easy part and ignore the nasty corner cases and error handling. It's in that last 2% that advanced skills are most valuable.

For me the thing that reveals an "advanced" coder is when I read his/her code. The easier and more obvious it looks, the better the coder. That isn't just about knowing which APIs to use, it's an attitude towards architecture, naming, commenting, layout, refactoring. ... which leads me to another answer:
Work in code maintenance for a while. Then write everything as if it's going to be you who will have to maintain it in 10 years time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thanks it works.

So what did you do- edit the .bat or upgrade to 64 bit?

ps: As a wise man once said as part of his DaniWeb signature: "Remember to mark your thread answered if your question has been answered."

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you running a 64 bit JRE? 32 bit JREs won't support 4g of anything

"JADX" - is that the android de-compiler?
I'm looking at jadx.bat where I see:

set DEFAULT_JVM_OPTS="-Xms128M" "-Xmx4g" "-XX:+UseG1GC"
...
@rem Execute jadx
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %JADX_OPTS%  -classpath "%CLASSPATH%" jadx.cli.JadxCLI %*
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's nothing quite like repeating the same mistake...

You hijack a 15 year old thread to post uncommented UNINDENTED Python?
And you expect us to do what?

rproffitt commented: A fine case here for closing old discussions. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You hijack a 15 year old thread to post uncommented UNINDENTED Python?
And you expect us to do what?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry - I don't have an Adroid SDK to test on.
The Date class was superceeded by the NIO Path/Files classes years ago. Maybe try the NIO equivalent? ...

System.out.println(Files.getLastModifiedTime(f.toPath()));
KINYUA_1 commented: Thankslet me try that code +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can't see anything wrong with that code. I pasted it into a little stand-alone test and it works perfectly...

JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showOpenDialog(null);
File f = fileChooser.getSelectedFile();
long time = f.lastModified();
System.out.println(new Date(time));
KINYUA_1 commented: Am debugging on android, when i toast the date in string format, it shows 1970 as the year +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java/ Javascript is usually client side

There's no such thing as "Java/ Javascript"

javascript is client side. Java (not the same thing) is used for both, but the majority of Java development today is corporate server-side.

rproffitt commented: My haste is my undoing on that. Thanks for the correction and clarification. +15
Arunshree commented: Then seems like a dead end to me +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

9999999999

That's 10 digits, not 7 and as such can hold values > 2^31 which cannot be stored in an int.

(Although I have no idea if that is actually the problem. Just sayin')

Papa_Don commented: I see the issue now. The int data type can store whole numbers from -2147483648 to 2147483647. +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you have a question relating to that code?