Prasad Saya

Rancher
+ Follow
since Jun 05, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Prasad Saya

In Java, a literal integer number, like 5 or 123456, is of type int, by default. But, the language also has other types of integral numbers.

As per the Java Language Specification (JLS):

4.2.1 Integral Types and Values

The values of the integral types are integers in the following ranges:
•  For byte, from -128 to 127, inclusive
•  For short, from -32768 to 32767, inclusive
•  For int, from -2147483648 to 2147483647, inclusive
•  For long, from -9223372036854775808 to 9223372036854775807, inclusive
•  For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535

3.10.1 Integer Literals

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1). The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit
1 (one).




So, it is the language definition (or standard) that requires you to use the letter L with the number.
9 months ago
Login window typically has functions to enter user login info (username, password) and an option to create a new user.

Your app's GUI typically connects to a database. More specifically, to a program which accesses the database. You send data to that program. Since, you don't have access to that program you can create some dummy data in a dummy program (or function or method) - where you can read and write from a dummy database.  The dummy database can be defined as a data structure, defined as a variable. For example, an array (or list) of user data as below:

In case of a web browser GUI, using JavaScript you can define one like this:



In case of a Java desktop GUI, you can have a list of User objects (you will need to create a Java class called as User with attributes name and password):



I suspect this is what you have already tried or thinking about. It will be a good exercise and experience if you try. But, I don't know if its required or not.

Somethings to think about are - does the GUI has the ability to show warning messages due to an unsuccessful login, or incomplete or invalid login data entry? An option to create a new user profile?
1 year ago
Okay, I was able to make the JSON-B API work to read the data by changing the POJO class little bit. I was using a slightly customized version of a POJO class and after changing it to a normal POJO with constructor, setters and getters to match the fields it worked fine.  

In my case, for casual use it didn't matter if I used Gson or any other library. Thanks for pointing to the JSON-B API. I am sure there are advantages with using each of the libraries.


Thanks for reading my post and the comments.

I was not aware of the JSON-B Java APIs availability. I did lookup now and tried with my code. The app ran without any exceptions. The serialization does create the data. But, the de-serialization did not work with the default configuration (code samples below). The data fields with List<String> returned empty lists. I suspect this requires some configuration using the JsonbConfig.

For example, the following Gson based code:



and its conversion to JSON-B:



Hello.

I wrote this post at another website couple of weeks back and can be useful for some ranchers: Notes About Quiz App's Data


- Prasad
With so many programming languages over the years it is difficult to pick one. It is a matter of personal preference. A programming language has many attributes of its own, and these have evolved over time. For example, one of the aspects of consideration is the paradigms a language supports - procedural, object-oriented, functional and reactive. Another aspect is the functionaity, or the specific problem the language can solve. Yet, another aspect is the voting counts on a popular forum.
2 years ago
Writing a desktop GUI is much simpler than a web app with GUI (a Spring Boot app). And, it will give you an opportunity to learn about the GUI component layout, the listener methods, the data flow between a database and the user interface - you will need these concepts when you write a web app (and more). Writing a web app would be very challenging if you are newbie - there are more concepts you will need to learn. Once, you get the hang out of the various aspects of GUI programming all the knowledge and concepts come in handy when writing web apps. That said, you can still create a new IDE, or a text editor, or a iTunes like desktop app and that would be fun too.
2 years ago
There is a simple way to create your Java  code for MongoDB Aggregation queries. The MongoDB Compass (a GUI desktop tool) has the features to create the native (or shell) Aggregation query and then export it to your favorite programming language (Java, Python, etc.). Here are the links to the Compass docs about the usage:

  • Aggregation Pipeline Builder
  • Export Pipeline to Specific Language
  • 2 years ago
    Hello. Just some thoughts on the error and its handling.

    "errmsg":"E11000 duplicate key error collection: crypto.btc_ohlc_minute index: _id_ dup key: { _id: ObjectId('6255cce8bdfc280a8c8d6ee8') }"...



    This error says that the unique index constraint on the _id field is violated. Every MongoDB collection document has this mandatory field, which functions as a "primary key", is of type ObjectId and is created by default. This value can be user supplied, optionally.

    When doing a bulk insert (as using the insertMany method), when any error occurs the operation is aborted - as in this case. But, there is an option to continue with the bulk insert even when there is an error. And you can try to use it. The insertMany has an optional parameter ordered, and is by default True - the process aborts when there is an error. When set to False, the insert operation continues even when there is an error. This is useful when inserting many documents and do not need to stop the process in case of an error, like an "E11000". This kind of situation is quite common in MongoDB bulk operations.
    2 years ago
    The User and Address data is a one-to-many relationship. A user can have, in general, 1 to 3 ( a small number) addresses. In MongoDB, this is modeled by embedding the address data into the user data.

    It is unusual, to create two collections one for each of the user and the address - especially when the addresses are going to be a very small number, and the kind of data being stored. The document structure would be something like this in a "user" collection:



    Note the address is an array type field, with multiple address elements.

    The two Java POJOs are the User and the Address. The User class will have a property called as address of type List<Address>. Using Spring-Data APIs for MongoDB, the CRUD operations can be performed on the "user" collection. For example, using MongoTemplate class:



    References:
  • Data Model Design
  • MongoTemplate


  • NOTE: One can also consider using MongoDB Java Driver APIs for the same application.

    4 years ago
    This is a post about the usage of PropertyChangeListener as an Observer using a Swing example. This can be used in place of the java.util.Observer and Observable (deprecated in Java 9).

    Read my post here: Java PropertyChangeListener as an Observer

    Prasad.
    Closing a topic is not an end to anything really. George G. can always solve the way he perceives it. He can try to understand whats posted by the ranchers and figure the solution. May be there is another way. Sometimes pausing little bit can clear things up.

    Perhaps there are many thoughts and ideas to focus on. May be its little overwhelming (it can be sometimes when there is pressure to figure a solution on time, etc.). Can't say what are the factors affecting. Over years I have come to know that the most deterring factor in solving an issue in software field is human and his intervention; its never a technology or hardware or software.
    6 years ago
    Good to know you are finishing your code without any issues   . While posting the code make sure its properly indented (and do remove the commented code). Also, if code comments (saying what it does) are placed strategically helps others to read the code and respond with a comment or a suggestion.
    6 years ago
    RandomAccessFile has mechanism called file pointer which allows access to data from a known particular position in a file. But, I don't know if it can be used with a file with serialized objects.

    In case you choose to use a List collection to store and then retrieve objects from it, one can navigate thru a list using a ListIterator - an iterator for lists that allows traversal of the list in either direction.

    But what i want in my project is to get first object , last object, previous etc. ...

    6 years ago

    Prasad Saya wrote:I think, first you may have to write the code without streams API (functional-style programming) using pre-Java 8 constructs and find the solution. And, then translate or refactor it into using the streams API.



    Enthusiasm to do functional-style programming is not enough. It requires study and effort. Switching from OO style programming to functional-style requires understanding of why functional style, what are the differences, advantages and disadvantages, use cases, etc. Learning or browsing thru the API's is not sufficient, one needs to know how the provided features can be used and in the right situations.

    A way to learn (other than books, tutorials, tests, etc) is to actually take some non-functional code and convert it. One can immediately see the differences - like the compactness of the code, the self-documentation, the new features and the efficiency.
    6 years ago