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 :
- Difference between Applets and Application
- Java Buzzwords (Java features)
- Components of JAVA platform
- JAVA libraries
- Starting with a JAVA program
- Java is Object Oriented Programming (OOP) language. What are it's advantages?
- Data type in JAVA
- Identifiers in JAVA
- Some syntax used in JAVA (variables & Literals)
- Operators in Java
- Precedence of operators
- Java keywords
- 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 ).
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,- JVM (Java Virtual Machine)
- 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,- java.lang
- java.io
- java.util
- java.awt
- 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...");
}
}
{
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
(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)
- byte
- short
- int
- long
- float
- double
- char
- 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 $
- a letter
- underscore
- dollar sign $
9. Syntax used in Java
Variable :
- Syntax to create a character variable is
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
short y =15
int p = 20
long q= 25 : etc
- Syntax to create a Boolean variable is
boolean b=true:
- Syntax to create a Float variable is
float f1=3.14:
float f2=1.402e-2
etc.
Literals :
Literals :
They are pieces of Java Source Code
Java has 4 kinds of Literals ,
- String (Example : "Hellow World") .
- Character (here, single quotes are used instead of double quotes, example : 'c' )
- Number (there are 2 types of numeric literals integers & floating point numbers).
- 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
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