0% found this document useful (0 votes)
2 views9 pages

Unit 3 Java Quick Revision Notes

Uploaded by

grovernneetu73
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Unit 3 Java Quick Revision Notes

Uploaded by

grovernneetu73
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit - 3: Fundamentals of Java Programming

Comments:
 All the grey parts are comments.
 Comments are used in code by programmers to document their programs -
to provide explanatory notes to other people who read the code.
 This is especially useful in the real world, where large programs are written
by one programmer and maintained by other programmers.
 You can write comments in a Java program in the following two ways:
 Beginning a comment line with two consecutive forward slashes (//)
 Writing the comment between the symbols /* and */

 All Java statements must end with a semicolon.


 To Save-File > Save (Ctrl + S) or File > Save All (Ctrl + Shift + S) to save
the Java program NetBeans has a default Compile on Save feature, you do
not have to compile your program manually, it is compiled automatically
when you save it.
 To execute the Java Program -click on Run > Run Main Project (F6)or
Run >Run File (Shift + F6)
Package:
 The first line in the program is a package statement.
 A package in java is a group of related classes.
 All classes in a package can share their data and code.
 The package name can be different from either the class or the source file
name.

Example: Java program: Helloworld.


package HelloWorld;
public class HelloWorld {
public static void main (String[] args)
{}
}
 In above program this statement declares that the HelloWorld. Java
program is part of the HelloWorld package.
 The next line declares a class called Helloworld.
Class
 Java demands that the class name should be the same as the source file
name.
 The contents of a class are enclosed within curly braces.
 If you make any errors while typing your code, for example, if you forget
a semicolon at the end of the statement or if you misspell a keyword,
NetBeans will warn you with a glyph - an exclamation mark in a red
circle, in the left margin of the line If you bring the cursor near the
warning, you will see helpful hints to correct the errors. You can use these
hints to correct your errors
Method is a group of statements written to perform a specific task. The
method body is enclosed within a pair of curly braces and contains the
statements that the method will execute.
Variables:

 To store the program data we will use variables.


 A variable is a placeholder for data that can change its value during
program execution.
 Technically, a variable is the name for a storage location in the
computer's internal memory.
 All data variables in Java have to be declared and initialized before
they are used.
 When declaring variables, we have to specify the data type of
information that the member will hold – integer, fractional,
alphanumeric, and so on.
 The type of a variable tells the compiler, how much memory to
reserve when storing a variable of that type the main method, we
declare these variables, we also assign them values using the =
operator.
Arrays
 Arrays are variables that can hold more than one value, they can hold a list
of values of the same type.
 The use of \t to print a tab between the numbers in the print statement.
 It Occupies contiguous memory space when declared and each space is
called Array elements which can store individual value.
 Each array Element is uniquely identified by a number called Array index
which begins from 0.
 The [] brackets after the data type tells the Java compiler that variable is an
array that can hold more than one value.

You might also like