I was asked in an interview what are structs in Java.I had never heard so replied saying sorry I don't know. Later when I checked I did not find any struts in Java but it is there in C++. I am thinking that interviewer might have meant equivalent of structs in Java. Does Java have it or its equivalent ?
The logical equivalent of a struct in Java is a Java Class. There is no physical equivalent.
In C, a struct defines not only a data association, but also memory mapping. That is, knowing the characteristics of a particular compiler for a particular machine and OS, I can compute to the byte how much memory a struct will occupy and where, within that struct, each of its data elements are. You cannot do that with a Java class.
C++, incidentally gets a little funny. Unless someone's tightened definitions, the only difference between a C++ struct and a C++ class is the initial scope of its member declaraions. A struct starts out with public scope, a class starts out with private scope. But C++ classes (including structs) can define virtual resources, and if they do, the location and composition of those resources may make it harder to predict storage sizes and offsets.
Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.