Mitandao

WRITING SIMPLE JAVA PROGRAM RCS 102 (22/3/16)

 
As typed By Okiki
 
Things to consider
  1. All java code are written inside a class
  2. A java program must consist of a class which is literally a blue print / template of a program
  3. In writing a java program we start by the key word "public" which means that the it is accessible anywhere in the code, then "class" which defines it as the basic unit, then follows a class name e.g HelloWorld and opens a curly bracket which initiates the start of the block of code thereafter close the curly bracket.
    • Example
                   
                     public class HelloWord{
                         //block of code here
                     }
  1. The name of the class by convention starts with a capital letter
  2. Not all java programs are programs even if every java program must have at least one class.
  3. A class that contains the main method is the main class.
    • Main Method is
               
                    public static void main(String[] args({
                         //code here
                         }
  1. Curly brackets signifies the beginning and ending of a block of code. Static method does not depend on the creation of objects, it just executes as it is not part of an object it is just a part of the class. Void means it is not a value return method. Normal brackets are conventionally used in methods to indicate that the object is a method. Square brackets indicate that an object is an Array.
  2. To output anything to the screen, we have to use a special class system
    • example
                     System.out.println("Hello World");

  1. Each statement must end with a semi-colon " ; " this tells the compiler that the statement has come to an end.

Variables
     - These are named memory locations. Variables comprises of the following;
    • Name of the variable
    • Content of the variable
    • Type of the content of the variable
     Data types in Java
     - They are divided into two major types
  1. Primitive Data types
    • It is a data type that is indivisible, meaning it can not be divided into smaller parts. It is said mythically to be atomic in nature
    • Numeric Data types
      • Whole numbers
        • Byte
        • Int
        • Long
        • Short
      • Floating Point numbers
        • Float
        • Double
    • Non-Numeric data types
      • Char - it is of 2-bytes as it is a Unicode character
      • Boolean - Occupies 1 bit i.e 0 or 1
  2. Reference data types / Objects
    • These are types which are made from classes
    • String are reference 

Variable declaration syntax
     - Syntax - The rules of a certain language. They are grammatical rules of a programming language
     
     [variable-type variable-name] e.g int age;
- Initalize : Giving an initial value to a variable. 
- In some cases you can declare and initialize at the same time.
          e.g. double distance = 10.1;

- Data types are associated with operators. These iinclude;
  1. Arithmetic Operators
    • + - Addition
    • - Subtraction / Minus
    • / Division
    • * Multiplication
    • % Modulus division
  2. Assignment Operators
    • =
    • x ++ Post Increment
    • x -- Post-Decrement
    • ++x Pre-Increment
    • --x Pre-Decrement
  3. Relational Operators
    • > Greater than
    • < Less than
    • == Exactly equal to
    • ! Not
    • >= Greater or Equal to
    • <= Less or Equal to
    • || OR
    • && And

Related

Recent 927856712866934172

Post a Comment


  1. Hi Admin, its an informative post, Java is most popular programming language and it offer huge career prospects for the talented professionals.
    J2EE Training in Chennai|JAVA Training Chennai|JAVA J2EE Training in Chennai

    ReplyDelete

emo-but-icon

BSC I SEM II DRAFT II TIMETABLE


Ruaha Catholic University

RUCO MIRROR 2014 EDITION

Almanac 2015/2016

Our Facebook Page

.

Portal Admin


ADVERTISEMENTS

soccer league tables

Football results provided by whatsthescore.com

Mechi Live

Our Recent Visitors

item