JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well done! Thats not an easy project.

One bug I noticed still outstanding
new Thread(this).stop();
creates a new Thread and stops it (null op because it was never started)

If you want to stop the threads you started earlier you need to keep track of them, eg

Thread thead1 = new Thread(myRunnable);
thread1.start();
...
thread1.stop();

(Thread.stop is deprecated, but if you are doing it as part of a shutdown then you should be OK.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For future reference: If you are asking for help with a problem and you have an Exception message... TELL US ABOUT IT!
It's the single most important piece of information and you have to share it with us.

NPE in line 104. There are only two variables that can be null on that line, ta and dis.
So either the text area or the input stream has not been initialised when that line is executed.
Let's halve the problem by finding out which it is. Print them both immediately before line104. The fact that the client -> server case works suggests that the text area is ok, but its still best to test that assumption.

Look at the startup process for a JavaFX app, in particular the difference between init and start and the order in which they are called. I sense a confusion about which code should be in which method.

(ps: The fact that client to server is working means you have successfully implemented 99 % of the difficult stuff. Well done.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are not giving much info to help debug this. Please explain exactly what the test procedure was and exactly what messages were (or were not) displayed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Little thread tutorial....

Creating a subclass of Thread (as in your code above) is perfectly valid but most people would not recommend it... by extending Thread you remove any possibility of extending anything else. And it's just not good design - the subclass is NOT a kind of Thread, it's a thing that can be executed in a Thread. In general it's much better to make your code a Runnable (ie has a run()method) and pass that to a Thread for execution. eg

private class ConnectionHandler implements Runnable {

        @Override
        public void run(){
            etc etc

...

 new Thread(new ConnectionHandler()).start();

But even better, if you have got as far as lambdas in Java, you can bypass creating a new class altogether and just have a simple method, eg

public void connectionListener() {
    try {
        s = new Socket("localhost", 5279);
        etc etc

new Thread(this::connectionListener).start();
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I just need to loop this: ta.appendText(dis.readUTF() + "\n"); right?

Yes, but it has to be in its own thread so it doesn't block everything else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like a design problem around when you read the input from the ObjectInputStreams - you only try to read them after sending something. So the client can send something but the server won't respond until something is typed a the server.

The way this is normally done is to have a new thread (yes, more threading!) that sits in a loop waiting for input from the ObjectInputStream and copying whatever it receives to the user interface text field. You do that in both the server and the client. Then whenever you send anything, in either direction, the message is received and processed immediatly.

ps: You don't need a ConnectionThread for the Client's connection. The client must make a connection straight away and cannot do anything else until the connection is made, so that doesn't need a separete thread.

Vin vin commented: I just need to loop this: ta.appendText(dis.readUTF() + "\n"); right? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, yes. You have created a new thread for the server accept, so it no longer blocks anything else. That's good.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's really close, but
in copying (length+1) bytes (lines 26-31): you copy the same byte repeatedly.
in replicating one byte (lines34-38) you don't skip the byte you are copying.

Testing code on real data is easy - it either works or it doesn't. But debugging it is a nightmare because it's too complex and there's too much data. You know it's wromg but you don't know why.
So
Before you try to fix the code, just create a tiny test case so simple that you can immeditately see what's happening.
Maybe as simple as a byte array 0, 'a', 2, b', c','d', 255 ,'e' which should give abcdee as output

rproffitt commented: Thanks for this. As to homework, we would be guessing. For such work I will admit to using ImageMagick. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
      For Each HDDDET In HDD.Get
          HDD_DETLAIS = etc
          TextBox1.Text = HDD_DETLAIS
      Next

You loop through all the disks setting the text box to dosplay their details BUT each one immediately overwrites the previous one so all you ever see is the last.

To see all the disks you need to concatenate all the details for all the disks (with newlines inbetwen) in the loop, then display that after the loop.
If you want to display just some disks, test the details to see if you want this one before concatenating its details.

rproffitt commented: The devil is in the DETLAIS. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

new Runnable(){@Override public void run() {}};

Thats one part of one way to start a new thread. Without the other part it does nothing.
You still have AnimationTimers that make no sense at all.

You are now wasting your time (and mine) by cutting and pasting code you don't understand.

Read about threads in computing.
Then read about threads in Java (see the Oracle tutorials)
Then read about threads in JavaJX
Then you will know what you need to do, and why.

There is no short cut to this. Do it properly or don't do it.

Vin vin commented: I am going to do that, sorry for wasting your time, I am going to do my very best to understand this topic. +0
rproffitt commented: Here's hoping Vin Vin will wake up soon. Elsewhere this would result in much worse. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What part of " if it's someone else's example code then no, you cannot post it here or anywhere else without the copyright owner's permission." didn't you understand?

Research the concepts and write your own code. It's the only way to learn.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you want to post code do it as part of a code block or inline ciode (icons 3 and 4 above the text input box). But if it's someone else's example code then no, you cannot post it here or anywhere else without the copyright owner's permission.
I watched about 15 secs from near the beginning and the first thing I saw was a Thread for the connect, so that's a good start. Unfortunately the way he did it is not recommended best practice.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So basicly I have to find a way to unblock ui events in my program

Yes, or, more accurately, avoid blocking them in the first place. The most obvious way is start a new thread and call your waitForConnection() in that thread. Like that it can sit waiting for connections without blocking any other activity. You may need to read up on threads in general to get the concepts, but having done that it's like 1 line of code to do it in Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know what you mean with thread

OK, that's going to be a problem with an app like this. Threads and Threading are a fundamental topic in computing, and relate to how a program can do multiple things at the same time (eg respond to user input while waiting for a network connectin). To do two things like that at the same time required two threads. You are converting a Swing application, but Swing and JavaFX use threads in slightly different ways (see techy note below), so the code cannot always be simply tramslated.
All I can suggest is that you find a tutorial about threads on the web that matches your current level of expetise, then check out some of the web sites that explain how JavaFX uses threads.

ps: I have no idea why you are using those AnimationTimers - you do know that their handle methods will be called 60 times per second?

Techy note: A Swing app starts in the main program thread and Swing has its own thread for any UI stuff. That means you can exter a wait-for-connection in your startup code (main app thread) while UI events continue to be handled. JavaFX calls your start method on the same thread that it uses to handle UI events,so it you wait in the start method all UI events are blocked. (AnimationTimer handle methods are also queued/called on the same thread.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ like he said.

Waiting for a connection has to be done in its own thread if you want the app to respond to anything else while waiting.
Same goes for the whileChatting loop

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can simply keep the constructors as they are and in the employee's one do this

Yes, that's what I intended!

ps: When I mentioned "suitable accessors" for the Employee list I should have been more specific. You dont want any other code modifying that list, so the only accessor should be something like

   public static List<Employee> getEmployees() {
        return Collections.unmodifiableList(employees);
    }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Quickest solution is to have the list in the Employee superclass as a static member with suitable public accessors. The constructor for Employee can simply add this to the list.

The purist answer is that Employees need an Employer (Company or whatever) and that's where the list belongs. It's the way to go if you are holding data for more than one Company/Employer.

ps: To be nit-picking... class names should be nouns (ie not "readData") and your data reading method is a classic case for using a try-with-resources.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't have time for a full reply now (I'll try later) but the short version is:

Start with the API definitions for the distinct layers. Eg if its just MVC then define the model's API.
In multi-layer systems I would still start ith the API for the layer below the UI because that effectively defines the system's visible functionality.
This gives you a clean architecture and allows development of the layers to proceed in parallel. It also maximises the chances that the client may understand exactly what he is signing up for.

ps: rproffit: I was Principal Consultant at Easel when Jeff Sutherland et al developed Scrum based on the informal processes we were using in the field, and I remain a fan to this day. Almost anything woud be better than the traditional guaranteed-to-fail waterfall method!

rproffitt commented: Thanks for that. I should have written more about how we are somewhere in the middle of full Agile to Waterfall on the spectrum. i.e. middle of road. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If the deck is shuffled then it makes no difference which card you remove, so why not just remove the last one? (May make no difference in Python, but for languages with simple arrays it's lot easier.)

Reverend Jim commented: Doh! +15
rproffitt commented: Double up! +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

See this

rproffitt commented: Why won't folk do this on their own? My only thought is it's a shill posting. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First you will need something to iterate through all the character sequences. See my previous post for hints about how to do that.
(Out of interest I tried this myself. Its a couple of dozen lines of code, using a Predicate<String> to delegate what to do with each sequence.)

Then you need to decide what to do with all thise sequences. Your description seems incomplete, but it sounds like you will ignore all sequences not 7 chars long, then put all the others into a List, sort the list aphabetically, and run through ot once comparing consecutive entries to see if they meet the criterion for common initial characters.

How far have you got so far?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

yes, affected

Presumably you will have downloaded that library and incorporated it into your deliverable, so nothing that happens on GitHub will affect it.
It it were removed I'd be more worried about (a) confirming that its licence allows you to continue to do what you are doing and (b) what will happen when that library needs to be updated for some future change in Android?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

well, yes. In my opinion you will learn a lot by going through the process of parsing the JSON and creating the objects.
When you've done that try adding something like this to the Customer class
List<Product> purchasedProducts ...// getter and setter as needed for JavaBean compliance
and find out how to handle that in JSON.

Having done that you will understand how to compare JASON with JSONParser etc, and maybe others.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

so basicallly you have m times n starting points for the first character
for each of those you append the character in each of the (up to) 8 surrounding points
... and for each of those the (up to) 8 surrounding points
... ... and for each of those etc
... ... ... etc
... ... ... until the sequence of chars is the right length

that's going to be 2 nested loops for the starting point, and a recursive call to append the 8 surrounding characters.
You'll also need to keep track of which points you have visited to avoid zig-zagging back over yourself.

Overall this is not a trivial piece of code to write clearly and efficiently.

(I guess you will also want to test the sequence to see if it matches some criteria? Otherwize that's going to generate a very large number of sequences - approaching n.m.8^length)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A couple of quick comments:
no need for get/set server in client!

Test:
Soon after posting I edited the post to improve the test code to pass the resource class rather than a name to the client method that performs the request. Apart from being more logical, it also removes the need for the horrible unsafe casts - I see you have it commented out, but that is the version you should use. The test code calls a Client method, that you need to write, to construct the REST request and pass that to the server. I should have a signature something like
public <T> T get(Class<T> t, int id)
ie tell me what class of object, and what it's ID (primary key) is, and I'll return you the instance of that class

Server getRsource should be private. That's it's back-end database and there's no way the client can eccess that directly. Server needs a public method like
String request(String request) // returns requested resource as JSON

that accepts the REST request and returns the resource in the format specified in the accept. That's the method the client will call.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, let's have some fun. Here's some code that will create test environment for you to code against..
First here's a couple of data classes (JavaBeans compliant)

class Customer {

    private int id;
    private String name;

    public Customer() {
    }

    public Customer(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Customer{" + "id=" + id + ", name=" + name + '}';
    }
}

class Product {

    private int id;
    private String name;

    public Product() {
    }

    public Product(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Product{" + "id=" + id + ", name=" + name + '}';
    }

(you'll need those in both the client and the server.)

Now some test code for the client...

    void test() {
        System.out.println(client.get(Customer.class, 1));
        System.out.println(client.get(Product.class, 2));
        // should print the toString for Customer and Product
    }

... and an object database (!) that the server can use to retrieve resources that the client requests...

    Object getResource(String type, int id) {
        switch (type) {
            case "Customer":
                return new …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you look at that complete string it’s all simple characters and can be parsed by splitting on blanks... except for the URL that may contain all kinds of stuff including embedded blanks. By encoding the URL down to simple non-blank characters you can do simple parsing (split on white space) for the whole thing.
I suggest you pass the raw URL to the method that builds the command, eg
String reply = get(“client/“ + searchID);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The request URL needs to be encoded (it may contain blanks etc), but not the whole request. I believe URLEncoder will deal with the character set, so lines 24,25 are redundant. Build the request from its constituent parts.

JSONObjectBuilder and JSONObject are useful, but I would suggest getting this working with some simple string concatenation first. IMHO Jackson is far more useful when building real systems, but to make the comparison you first need to understand what problems they are solving. All libraries come with their own learning curve that will just make things harder right now.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It would be uselful to print option before the switch.
But line 11 you have an assignment where you should have a equals test,.
And even if you fix that then someBooleanExp == true is EXACTLY the same as someBooleanExp

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without seeing the code its impossible to say what's wrong with it!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

My comment is to think defensively when coding as above. I think the code will fail with null strings so some check would be needed to avoid that in some cases

Absolutely. For example, I happened to notice that this code will fail if there are two spaces between the words in the input. Other coders may spot other possible failures, based on their own unique backgrounds. In any case a statement like myArray[0] or charAt[0] needs to be protected against zero length arrays or Strings.
Same thing goes for possible null values - the biilion dollar mistake. (Swift is so much better, with not-nullable variables unless explicity declared as nullable. I'd love to see that in a future Java.)

rproffitt commented: I didn't see that as my brain halted on the null and didn't look further. Two Spaces? Sounds like a movie title. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The truth is that a minute spent thinking before coding saves ten minutes debugging after coding.
It doesn't have to be complicated or formal. Personally I start by coding my method signatures and a few comments that describe how I see the code working. Call that pseudocode if you like, but it flows seamlessly into completing the real code.
I also start with a lot of assert statements, especially around the values passed into methods. These immediatly document the pre-conditions for the code that will follow, and provide runtime confirmation that those conditions are not being violated.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In the real world you would probably use somethinhg like Spring to implement a real application. But to work with Spring (etc) you need a reasonable understanding of what it's doing for you and why you need to configure the things you need to configure. That's why I recommend starting by coding a simple case yourself.
Where to start? Nothing too big or hard:

Client and Server classes. Instatiate one of each, Give the Client a ref to the Server. In the Client construct a complete correctly formatted GET request and pass it to the Server. In the Server parse the request and return an arbitrary value correctly formtted (eg JSON). In the client parse the returned message and print the value. (For starters I would assume a resource called "Dummy" with an id of 1 and a price of 9.99. I'd hard code those into the Server.)
That will demonstrate that you have understood all the essentials of how REST messages and resource states are created, formatted, parsed.
Enhance it to do a PUT.
Create a more interesting Resource class and enhance your code to GET/PUT that. That will demonstrate that you have understood some of the issues around how REST servers and clients interact with POJOs.

Now look at things like Spring to see how they can simplify your development process in real life - at least you will understand what they are doing for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yeah. I would just move on now, and remember that Scanner nextInt and nextLine don't mix well!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a well-known problem with Scanner's design - so many people fall into this trap.

your nextInt reads the menu number, leaving its newline character in the input buffer. The nextLine reads that and returns a zero-length String. See below for more discussion.

You have some input with an int followed by some text, eg
101
John Doe
... and you try to read it with
int num = scanner.nextInt();
String name = scanner.nextLine();
... and name is an empty String ("")!

Here's why:
Your input looks like this with the new line characters shown explicitly
101\nJohn Doe\n
nextInt takes the int value from the scanner, and stops when it finds a chaacter that's not part of an int, so it takes the "101", leaving this in the scanner
"\nJohn Doe\n"
then nextLine takes everything up to the first \n character - a zero-length String ("").

Possible fixes:

  1. Add add extra nextLine() between the nextInt and the real nextLine to clear the unwanted \n. This may be difficult if the nextInt and the nextLine are in different areas of code which are not always executed together.

  2. Give up on nextInt (etc) and just read whole lines and parse then into ints (etc) with Integer.parseInt (etc) - in which case you can junk the whole scanner and use a BufferedReader instead.
    new BufferedReader(new InputStreamReader(System.in))

  3. Use this class instead of Scanner:
    https://www.daniweb.com/programming/code/506346/a-simpler-safer-alternative-to-java-util-scanner
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That seems backewards to me. For a first learning exercise in REST maybe it would be better to start with the essential univeral REST components - a Client and a Server. They should implement the relevant commands (GET etc). You could start with just one resource that the server has a hard-coded test value for. Goal 1 is that the client can send commands to the server, the server parse them, the server respond (JSON, XML?), and the client process the responses (including error codes).
Then I would move on to creating some more challenging data (Brick, Customer) and plugging that in to your working REST infrastructure.

For learning I would avoid existing solutions. First do it yourself so you really undertand the protocol and the issues. Only then will you know how to evaluate alternative solutions and configure them.

Fi=nally, I think any discussion of what database technology to use is not going to help you learn about REST. Ignore it for now.

rproffitt commented: "It's always best to start at the beginning – and all you do is follow the Yellow Brick Road." - Wizard Of Oz (film) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

those two overriden methods are not doing anything,

My point was not that they were not used, it was that they are not overriding anything.

rproffitt commented: MY EYES! THE GOGGLES DO NOTHING! +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Current versions of Java do support multiple inheritance from interfaces. So your question is in error.

rproffitt commented: That's what I thought. Then again they tagged the discussion with asp.net and left out Java version in use. I have a legacy app on (gasp) 1.8. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What'ss the problem?
You sort the collection based on the names, and you get your collection sorted in name order.
What did you expect?

ps: Your two "override" comments are wrong - those methods override nothing (which is why you haven't been able to annotate them)

Violet_82 commented: Doh! Yes, I'm ordering them by name and not by value - sorry I was evidently very tired when I posted this. +7
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why the parseInts? Don't you just want to insert the character that represents 1,2,3 etc?

And why the === (identity test) rather than a simple == (equals)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All http sites in the world? Do you have any idea how many terabytes (zettabytes?) that is?

Ayush_5 commented: Thanks, James. One Last thing? If that wont work then Can i create script which could filter out all the https results in a search result +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Before you do anything else fix your empty catch blocks by printing the complete details of any exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know firebase, but as nobobdy else has answered....

MAYBE there's a time attached to that data, eg
30-5-2019 10am
31-5-2019 11am
and your query is defaulting to midnight, ie 30-5-2019 00:00 to 31-5-2019 00:00
???

If so the fix is to end the date range with a date one day later.

rproffitt commented: The more I thought about your reply the more likely that's it. +15
Saboor880 commented: Thanks for trying James. Actually there was need to convert the string date in date object, I did so and the problem solved +3
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I hope you have the permission of the copyright owner to publish their work in its entirity withoit any pretence of fair use, comment etc. Or are your homework assignment descriptions in the public doamin?

You didn't ask any questions or tell us what you want us to do with that infiormation. Do your homeowrk for you maybe?

You seem to think that "WIndows 10" is enough for people to know which language you would like your homework done for you in.

Take a deep breath, ENGAGE YOUR BRAIN, and start gain.

rproffitt commented: Asking the hard questions. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 92 You just print the last item. Think about how to use the loop variable a

Also
Line 77 If you want to test for two Strings containing the same sequence of characters then use the equals method.
== tests if they are exacty same object.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like a mathematical solution is v. hard, so maybe in a C.S. context it's asking for a numerical solution (approximation) using some kind of iterative approach?

ps: It looks like there are two positive real solutions, approx 0.0035 and 25.7

rproffitt commented: It's pretty interesting there are two positive solutions. That's math for you. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about something to manage Users... logon, password verification, privileges/authorisations, preferences etc
You could have it as a API then optionally layer a GUI on top.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's some pseudo-code to point you in the right direction

do
    get two random numbers 1-6
    sum  them together
while( the sum is not 7 or 11)
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That would be 531 441 different combinations,

... on a machine that can do a BILLION if tests in a second. Do the sums.
Unless there's some aspect of this that you're not sharing you do not have a perfomance problem and trying to select a language based on the speed of of its compiled code is irrelevant. Even so there's a ton of benchmark data that shows all the major compiled languages having very similar perfomance averaged across a range of realistic tests. Chose one that expresses the algorithm in the clearest code.

rproffitt commented: That's also my experience. Maybe, long ago there was more of a difference but today, not so much. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

C Language is used to be considered as most powerful programming language.

... which is why everyone uses it for any kind of application all the time. No, wait a minute, that can't be right....

In terms of the capabilities and features of the language itself raw C is, of course, just about the least "powerful" language ever. "Simplest and fastest" maybe, provided that you are talking about writing device drivers.