Grade_8_-Review1-JAVA_ReferenceMaterials
Grade_8_-Review1-JAVA_ReferenceMaterials
INTRODUCTION TO JAVA
I. FEATURES OF JAVA
Java program is entered into the computer using a text editor such as Notepad++ or
Notepad.
ENTERING:
Steps given below to enter the program using Notepad++ or Notepad:
1. Click on the Windows icon and open Notepad++
2. Type the program in the New Document.
3. Select File Save menu option in the Notepad to save the program.
4. Select all files option in the Save as type box of the Save As dialog box and type the
name of the file with extension name .java in File name box.
5. Then, click on the Save button.
Note: Notepad++ or Notepad can be used for entering the program in Java.
COMPILING
Java program is compiled at the DOS prompt. So, you need to go to the Command prompt
in order to compile your program. Now, to compile the Java program, follow the steps given
below:
1. Click on Windows icon ->Command Prompt menu options for accessing the DOS
prompt.
2. In command prompt, we need to create a folder by the command md <folder name>,
then change to the directory by cd <folder name>
3. In command prompt, to compile the program, type javac <file name with
extension>.The program will be compiled.
EXECUTING
In order to run the compiled Java program, type the command, java <file name without
extension>. The program will run and you will get the output.
SYNTAX
Example:
// JAVA Program to print I am learning JAVA
LINE 1 :This creates a class called Hello.All class names must start with a capital letter.
The public word means that it is accessible from any other classes.
LINE 2 : Two curly brackets {...} are used to group all the commands, so it is known that the
commands belong to that class or method.
LINE 3 :The compiler ignores comment block. Comment can be used anywhere in the program
to add info about the program or code block, which will be helpful for developers to understand
the existing code in the future easily.
LINE 4 : When the main method is declared public, it means that it can also be used by code
outside of its class, due to which the main method is declared public.
The word static used when we want to access a method without creating its object, as we call
the main method, before creating any class objects.
The word void indicates that a method does not return a value. main() is declared as void
because it does not return a value.main is a method; this is a starting point of a Java program.
String[] args It is an array where each element of it is a string, which has been named as
"args". If your Java program is run through the console, you can pass the input parameter,
and main() method takes it as input.
LINE 5 : This statement is used to print text on the screen as output, where the system is a
predefined class, and out is an object of the PrintWriter class defined in the system. The
method println prints the text on the screen with a new line. You can also use print() method
instead of println() method. All Java statement ends with a semicolon.
Remember: You will notice that the main method code has been moved to some spaces left.
It is called indentation which used to make a program easier to read and understand.
Int, string
SYNTAX
datatype variable1 = value1; variable2 = value2;
System.out.println(+value1 +value2 +value3);
6. Write a program to declare one variable of each data type and display value in it(name,
age,)
OUTPUT
7.Write a program to get the below output.You need to use only one println statement
}
16. public class programb
{
public static void main(String[] args)
{
System.out.println("My name is:");System.out.println("Jane Doe");System.out.println("I am
studying in Gr8"); }
}
17. public class programc
{
int x = 10;
public static void main(String[] args)
{
System.out.println("The number is" +x);
}
}
*********************************************************************************************************