I am new to Java and I am trying to find out a way to store information like a struct in C. Say for example I want to have a program hire employees. It would take from the user a first name, last name, and id number and would store it. The user could then view that information based off a condition (if the database had more than 1 employee for example). Can any suggest the best way for doing this?
Yes, Java doesn't have a struct/value type yet. But you have good news as well. Project JUnion delivers struct types for Java programming language. So you can use Struct types in java by using Project JUnion plugin by annotating a class with @Struct annotation.
A struct is the Java equivalent of a C++ struct. Use structs to group domain definitions and other struct classes to form programmatic record definitions. Use struct classes as arguments to operations of entity and process classes.
Select Data Structure on the Add Object form and click the OK button. Enter the name, description, and product code of a data structure. For a regular data structure, select Regular Data Structure. Complete the Add Object form and select Regular Data Structure, then click the OK button.
Which programming language is best for data structures and algorithms? Data structures and algorithms are not language specific and hence you can use any language be it JavaScript, C, C++, Java or Python. You should feel comfortable with the syntax of the language and you are good to go.
In Java 16 there are Records
(JDK Enhancement Proposal 395):
public record Employee(String firstName, String lastName, String id) {
}
This comes with a canonical constructor, field accessors, hashCode()
, equals()
and toString()
implementations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With