In programming, the “struct” corresponds to a keyword that creates a structure comprising variables, methods, constructors etc. This functionality does wonders in the “C” programming language. It is identical to classes that comprise various types of data. The “struct” is an effective approach as it creates objects which require less memory.
Does Java Support Struct?
Java doesn’t support “Structs”. It is such that there is no struct equivalent in Java, however, class is the nearest approximation as it can almost perform the same functionalities. With a Java class, the functionalities performed by a structure can be achieved.
Alternative Approach: Utilizing Class to Create a Java Structure
The core difference between a “struct” and a “class” is that the struct is public by default, whereas the class is private. Therefore, if we create a class and transform its methods to public, it will work identical to a “struct”.
Example
The following code demonstration uses a class to create a Java structure:
class RaiseEvaluation {
String name;
private static int salary;
RaiseEvaluation(String name, int salary){
this.name = name;
this.salary = salary;
}
public static int Raise(double percent) {
return (int) (salary * percent/100);
}}
public class Struct {
public static void main(String args[]) {
RaiseEvaluation calculate = new RaiseEvaluation("Harry", 25000);
System.out.println("The raise in salary is -> "+calculate.Raise(50));
}}
In the above code lines, apply the elbow-stated steps:
- Create a class named “RaiseEvaluation”.
- In its definition, specify the String and a “private” int member variable.
- Create a class constructor that assigns the argument values to the specified values using “this”.
- Now, define the function “Raise()” that returns the incremented salary based on the passed argument.
- Note: The method body and the method declaration for “Raise()” are applied within the Java “RaiseEvaluation” class. Also, the “salary” instance variable is declared as “private”. This indicates that an instance of this class can only invoke the salary info.
- In “main”, create a class object and pass the stated values as class constructor arguments.
- Lastly, invoke the defined function by passing the given value as its argument to retrieve the incremental salary by dividing the increment percentage with “100” in the function.
Output

This outcome implies that the salary is incremented appropriately.
Conclusion
Java doesn’t support “Structs”. However, the “Class” functionality is the nearest approximation as it can achieve almost the same functionalities. It can be achieved by defining a class and transforming its methods to “public”.