0% found this document useful (0 votes)
4 views

Grade_8_-Review1-JAVA_ReferenceMaterials

The document provides an introduction to Java, highlighting its features such as object-oriented programming, platform independence, and multithreading. It outlines the installation process for Java Development Kit (JDK), as well as steps for entering, compiling, and executing Java programs. Additionally, it covers basic Java syntax, data types, and common programming errors, along with examples and exercises for practice.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Grade_8_-Review1-JAVA_ReferenceMaterials

The document provides an introduction to Java, highlighting its features such as object-oriented programming, platform independence, and multithreading. It outlines the installation process for Java Development Kit (JDK), as well as steps for entering, compiling, and executing Java programs. Additionally, it covers basic Java syntax, data types, and common programming errors, along with examples and exercises for practice.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

GR 8/COMPUTER SCIENCE/REVIEW-1

INTRODUCTION TO JAVA
I. FEATURES OF JAVA

● Java is an object-oriented language providing the features such as inheritance,


polymorphism and abstraction.
● Java can be used to develop distributed applications across the networks and the
Internet.
● Data in Java is defined as objects and procedures.
● Java programs can be interpreted as well as compiled. A Java program can be
executed directly on a computer that has Java interpreter. When compiled, the
source code is converted into the byte code, which is in binary and can be executed
on any platform.
● Java programs can be executed on any platform that have Java-enabled Internet
browser.
● Java supports multithreading, which is defined as the ability of an application to
perform multiple tasks at a time.

II. JAVA INSTALLATION


In order to develop applications on Java, we first need to install Java DevelopmentKit (JDK
ver.1.8.0) on our computer. Then, we follow the three-step procedure to develop
applications:
1. Enter the program in Notepad/Notepad ++
2. Compile the program with Java Compiler (javac)
3. Run the program in Java

III. ENTERING/COMPILING AND EXECUTING JAVA PROGRAM

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.

IV. BASIC STRUCTURE OF JAVA PROGRAM WITH


EXPLAINATION

SYNTAX

Example:
// JAVA Program to print I am learning JAVA

LINE 1 public class Hello


LINE 2 {
LINE 3 /* Writes the words "Hello Java" on the screen */
LINE 4 public static void main(String[] args)
{
LINE5 System.out.println("Hello Java");
}
}
EXPLAINATION

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.

V. EXECUTION OF SIMPLE JAVA PROGRAMS USING-


System.out.println

1. To display the message “Welcome to Java Programming!!”


2. Write JAVA program to get the output EXACTLY as shown below.

3.Write JAVA program to get the output EXACTLY as shown below.


4. Write JAVA program to get the output EXACTLY as shown below.

5.List the errors in the following program:


public static void main(String args[])
{
system.out.println("Hello")
}

VI. CHARACTER SET

Letters(a-z), digits(0-9), decimal digits

VII. JAVA TOKENS

Keywords, identifiers, constants, operators

VIII. DATA TYPES

Int, string

IX. VARIABLES AND DECLARING VARIABLES


SYNTAX
datatype variable = value;
X. DECLARE MANY VARIABLES

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

II..List the errors in the given code


8..public class program8
public static void main (String args[])
{
int number1='4';
String 4='test';
}
9.public class program9
public static void main (String args[])
{
int _number2=10;
}
10.public class program10
public static void main (String args[])
{
class String="Name";
}
11.public class program11
public static void main (String args[])
{
"Name" = x String;
}
12.public class program12
public static void main (String args[])
{
int @number1=600;
}
13.public class program13 {
public static main(String[] args) {
System.out.println("Hello World Example);
}
}
14.public class program14 {

public static void main (String args[])


{
String super="test";
}
III. Do the below programs have any errors?If yes,mention and write the output?

15. public class programa {

public static void main (String args[])


{
int _a = 10;
int $b = 20;
int C = 30;
int c = 40;
int result = _a + $b + C + c;
System.out.println("Result: " + result);

}
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);
}
}
*********************************************************************************************************

You might also like