Can someone please tell me if there are structs in Java? I am familiar with C programming, thats why I ask, but when I search for 'Java structs' I havent really found anything and I suspect that just structs are simply different and may be called something different so I thought I'd ask.
If there are structs can someone please write like a 2-3 line code declaring a struct with strings and integers, I would just like to see how it works, how the declarations look, and how they are used in 'main'.
So I wrote some sample code trying to implement structs using classes but it is not really working out. The program compiles, and then throws an exception (NullPointerException).
Can anyone put me on the right track? I don't understand why a null pointer exception is thrown to begin with, the program is coded in a way that I just store information in the slot zero of the array of classes, then I try to print it out. My logic suggests that this should work, but I am sure my logic FAILS once again lol.
Honestly, any help or fix to this simple program will be really really appreciated.
Something to avoid, more likely. Because the fields are not private you are losing encapsulation and those are equivalent to global variables. You are losing all the advantages of object orientation. If you want to use structs like that, go back to C, which lacks the concept of public and private.