Page 229 - IT-802_class_12
P. 229

In the IDE toolbar, click on Run → Run Project(HelloWorld) (F6)or Run → Run File (Shift + F6) to execute the Java
            Program.




















            You can also run your program by clicking the green arrow button on the toolbar
            The NetBeans IDE compiles and then executes your programs if there are no mistakes in it. The program output (the
            “Hello World” message) should now appear in the Output Display Window near the bottom of the IDE like follows:





















            3.1.2 Java Language Elements
            Java language elements are the fundamental building blocks that make up the Java programming language. These
            elements include syntax, keywords, data types, operators, control flow constructs, classes, methods, comments and
            more. Let us study some key Java language elements.

              3.2 varIaBLES and data tYPES

            You learned how to develop and run a simple Java program in the previous section. Let’s develop a software that performs
            something more useful than just display a message this time. We’ll create a data-handling application. Our program will
            determine a student’s percentage based on the marks he or she received and the overall number of marks for a test. We’ll
            also figure out the percentages for two students.
            3.2.1 Variables

            Variables are used to store the program’s data. A variable is a placeholder for data that can change throughout the
            execution of a program. A variable is the designation for a storage place in the computer’s internal memory in technical
            terms. The contents at that place are the variable’s value. We’ll utilise three variables in our percentage calculator
            program: marks obtained, total marks, and percentage. (We placed an underscore between the terms “marks” and
            “obtained,” “total” and “marks” because variable names must be one word.)
            Before they can be utilised, all data variables in Java must be declared and initialised. We must indicate the data type
            of information that the member will retain when declaring variables - integer, fractional, alphanumeric, and so on.
            The type of a variable instructs the compiler how much memory to set aside for that type of variable when storing it.
                                                                               Fundamentals of Java Programming  227
   224   225   226   227   228   229   230   231   232   233   234