Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 38

IT ANDROID APP

JAVA SYNTAX AND


GRAMMARS
YOUR FIRST PROGRAM
BASIC GRAMMARS
About Java programs, it is very important to keep in mind the
following points.

 Case Sensitivity- Java is a case-sensitive language, which


means that the upper or lower case of letters in your Java
programs matter.
CASE SENSITIVITY
 Case sensitivity enforces capital or lower case in the text.
For example, suppose you have created three variables
called "endLoop", "Endloop", and "EndLoop". Even though
these variables are composed of the exact same letters in the
same exact order, Java does not consider them equal. It will
treat them all differently.
JAVA RESERVED WORD LIST
RESERVED WORD LIST

 Reserved words are words that cannot be used


as object or variable names in a Java program
because they're already used by the syntax of the
Java programming language.
LIST OF RESERVED JAVA KEYWORDS
abstract assert boolean break byte case
catch char class const continue default
double do else enum extends false
final finally float for goto if
implements import instanceof int interface long
native new null package private protected
public return short static strictfp super
switch synchronize this throw throws transient
d

true try void volatile while


EXAMPLE:
JAVA NAMING
CONVENTIONS
 JAVA NAMING CONVENTIONS
 A naming convention is a rule to follow as you decide what
to name your identifiers (e.g. class, package, variable,
method, etc.).

 Why Use Naming Conventions?


 Different java programmers can have different styles and
approaches to the way they program. By using standard Java naming
conventions they make their code easier to read for themselves and
for other programmers. Readability of Java code is important
because it means less time is spent trying to figure out what the code
does, leaving more time to fix or modify it.
IDENTIFIERS

 A Java identifier is a name given to a


package, class, interface, method, or
variable. It allows a programmer to refer to
the item from other places in the program.
BASIC GRAMMARS
About Java programs, it is very important to keep in mind the
following points.

 Class Names − For all class names the first letter should be in
Upper Case. If several words are used to form a name of the
class, each inner word's first letter should be in Upper Case.
 Class representing the name of a Java class. This class is unable
to changed, and can therefore be safely used by multiple threads.
 Example: class MyFirstJavaClass
CLASS NAME
BASIC GRAMMARS
About Java programs, it is very important to keep in mind the
following points.

 Method Names − All method names should start with a


Lower Case letter. If several words are used to form the
name of the method, then each inner word's first letter
should be in Upper Case.
 Example: public void myMethodName()
METHOD NAME
WHAT ARE METHODS?
 A method is a set of code which is referred to by
name and can be invoked at any point in a program
simply by utilizing the method's name. 
THERE ARE TWO BASIC TYPES OF
METHODS
Built-in:  Build-in methods are part of the compiler package,
such as 
System.out.println( ) and  System.exit(0).
 
User-defined: User-defined methods are created by you, the
programmer. These methods take-on names that you assign to
them and perform tasks that you create.
BASIC GRAMMARS
About Java programs, it is very important to keep in mind the
following points.

 public static void main(String args[]) − Java program


processing starts from the main() method which is a
mandatory part of every Java program.
EXAMPLE:
JAVA IDENTIFIERS
IDENTIFIERS

 A Java identifier is a name given to a


package, class, interface, method, or
variable. It allows a programmer to refer to
the item from other places in the program.
 Packages:  in java it is a mechanism to
encapsulate a group of classes, sub packages
and interfaces

 Classes: is a user-defined blueprint or prototype from


which objects are created.  It represents the set of properties
or methods that are common to all objects of one type. In
general, class declarations can include these components
 Interfaces: An interface is a completely "abstract class"
that is used to group related methods with empty bodies:

 Methods:  is a block of code which only runs when it is


called. You can pass data, known as parameters, into a
method. Methods are used to perform certain actions, and
they are also known as functions. Why use methods? To
reuse code: define the code once, and use it many times.
PACKAGE
 Package in java is a mechanism to encapsulate a group of
classes, sub packages and interfaces
TYPES OF PACKAGES
 Built-in Packages
These packages consist of a large number of classes which are a part
of Java API.Some of the commonly used built-in packages are

1) java.lang: Contains language support classes(e.g classed which


defines primitive data types, math operations). This package is
automatically imported.
2)  java.io: Contains classed for supporting input / output operations.
3)  java.util: Contains utility classes which implement data structures
like Linked List, Dictionary and support ; for Date / Time operations.
EXAMPLE OF JAVA.LANG
JAVA.IO
JAVA.UTIL
 User-defined packages
These are the packages that are defined by the user. First we
create a directory myPackage (name should be same as the
name of the package). Then create the MyClass inside the
directory with the first statement being the package names.
CLASSES
 CLASS: A class is a user-defined blueprint or prototype from which
objects are created.  It represents the set of properties or methods that
are common to all objects of one type. In general, class declarations can
include these components, in order:
Modifiers : A class can be
public or has default access.
Class name: The name
should begin with a initial
letter
Body: The class
body surrounded by braces,
{ }.
MODIFIERS
CLASS NAME
BODY
IT ANDROID APP

You might also like