Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Thursday, February 26, 2015

Some Theory Part in JAVA



Now , lets look at the "Theory" part of JAVA.Before that , refer The "terms" used in all programming languages also.

Programming in JAVA

This module is covering the following topics :

  1. Difference between Applets and Application
  2. Java Buzzwords (Java features)
  3. Components of JAVA platform
  4. JAVA libraries
  5. Starting with a JAVA program
  6. Java is Object Oriented Programming (OOP) language. What are it's advantages?
  7. Data type in JAVA
  8. Identifiers in JAVA
  9. Some syntax used in JAVA (variables & Literals)
  10. Operators in Java
  11. Precedence of operators
  12. Java keywords
  13. Type casting


--------------------------------------------------------------------------------------------------------------

1. Difference between Applets and Application

Java offers two flavours of programming, APPLETS and APPLICATION . (Both are composed of CLASS extension and require JVM or Java Virtual Machine to execute machine independent JAVA BYTECODE ).

In simple terms, an applet runs under the control of a browser,(so that , it can be embedded in HTML and can be downloaded from Internet) , whereas an application runs stand-alone, with the support of a virtual machine.
Applets are the programs written specially for distribution over a network , and can be executed inside a Java-compatible container (modern network) , but Application are system level programs and can be executed from the command line.

2. Java Buzzwords

 They are nothing but some "features" provided by JAVA.
  • Simple
  • Object Oriented (means, JAVA focuses DESIGN on the data and on the interfaces rather than the functionalists and the tools used to develop them)
  • Robust
  • Secure
  • Architecture Neutral
  • Portable
  • Interpreted
  • Multithreaded
  • Dynamic

3. Components of Java Platform

2 platforms (hardware or software environment) are there,
  1. JVM (Java Virtual Machine)
  2. Java API (Java Application Program Interface)
JVM is an abstract machine .The "bytecode"  into which a JAVA Program is compiled and run in this JVM , and thus it is portable and architecture independent.

The Java API is a large collection of ready made software components , that provide many useful features , such as GUI (Graphical User Interface) widgets.API is grouped into librars(packages) of related components.

4. Java Libraries

The libraries(packages) of JAVA used to develop multi-patform applications.They are,
  1. java.lang
  2. java.io
  3. java.util
  4. java.awt
  5. java.net

5. Starting with a Java Program

Let us consider a small JAVA program.Refer Introduction to JAVA .

// This is my first Program (This line will be ignored by the compiler) .
              public class firstprogram
                   {
                       public static void main(String args[ ])
                              {
                                  System.out.println("Hai...Welcome...");
                               }
                    }



  • // This is my first Program Here, this first line  is used for Documentation purpose. It will be ignored by the compiler. This That means , this is used for understanding about a program. For larger programs , this is very helpful to know the purpose of a particular part of code
  • class is a "keyword" .Everything should be in a class.
  • public is a also a "keyword" which makes this class available and accessible by any one , which means it can be accessed from any package , or any class.
  • firstprogram is the name of the public class.
  • static is a "keyword" which signifies that this method will be called without creating an object of   firstprogram. And this method will be invoked first and only once by the JVM.
  • void is the return type of the main method , which means that , this method is not going to return any value.
  • System.out.println is used to print anything on the console.
  • in java , the semicolon ; will terminate a program.
How to compile and run a JAVA program ? Click here to read.

6. Java is an OOP . what is it's advatages ?

The main advantage that it allows you to control the complexity. You can create an object which represents some real one, put the logic inside it and hide all the implementation details behind some interface, which is public.

That way, the client has no idea how the object is implemented but deals with public interface to control it. For understanding suggest the program interface of the car:Every vehicles have some implementation details, but all have the common interface, and don't need cleint to be aware of implementation details.

  • Java is not source compatible with any other languages,so that JAVA has the freedom to design with a blank state.
  • The object model of JAVA is simple and easy to extend , while simple types (such as integers) , are kept as high-performance non-objects.
Advantages are :
  • Flexibility
  • Modularity
  • Reusability
Using OOP methodology , a program need not be redesigned from scratch.Using this concept,software can be developed based on already existing project.

(This is a wide topic , so refer to study yourself).

7. Data type in Java 

A data type in a programming language is a set of data with values having predefined characteristics.Two different categories are there,

  • Primitive Type (8 numbers)
  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. char
  8. boolean
  • Reference Type

8. Identifiers in Java 

Identifiers are the names of ,
  • variables (Variable names are case-sensitive)
  • methods
  • classes
  • packages
  • interfaces
Identifiers must be composed of ,
  • letters
  • numbers
  • underscore
  • dollar sign $
Identifiers may only begin with ,
  • a letter
  • underscore
  • dollar sign $

9. Syntax used in Java 

Variable :
  • Syntax to create a character variable is 
Char ch = 'b' ;

This means , the variable ch has been assigned the value of the letter b .
Single quotes aound the letter b ( 'b' ) tells the compiler that , we want the value of b , rather than the letter b.
  • Syntax to create an integer variable is 
byte x=10 
short y =15
int p = 20
long q= 25 : etc
  • Syntax to create a Boolean variable is 
boolean b=true:

It has only 2 values (true or false)
  • Syntax to create a Float variable is 
float f1=3.14:
float f2=1.402e-2   
etc.

Literals :

They are pieces of Java Source Code 
Java has 4 kinds of Literals ,
  1. String (Example : "Hellow World") .
  2. Character (here, single quotes are used instead of double quotes, example : 'c' )
  3. Number (there are 2 types of numeric literals integers & floating point numbers).
  4. Boolean (Can have either true or false)

10. Operators in Java 

The are used to build expressions.They are categorized as ,
  • Relational and Equality operators ( < , >= etc)
  • Assignment Operators 
  • Arithmetic
  • Bitwise
  • Increment and decrement operators
  • Logical
(Study this by referring books) .

11. Predecence of Operators in Java 

Precedence of operators : Study from text

12. Java keywords

They are reserved and cannot be used as a variable.There are 45 keywords.

13. Type Casting

int / int = int
doube / double = double
But , what about an int divided by a double or a double divided by an int?

Assigning a value of one type to a variable of another type is known as "Type Casting".

A cast lets the compiler know that you are serious about the conversion you plan to make.
See the example CJ-26 : Accept Radius in meter








=========================================================

Will Continue.....

Back to JAVA

No comments: