2. What is program?
A set of instructions that you give to a computer so that it will do a
particular task.
A computer program is a sequence or set of instructions in a
programming language for a computer to execute.
A computer program in its human-readable form is called source
code.
3. Java is different from other Technologies &
Java Versions
Its cross-platform capabilities
Memory management system
Pure oop approach
Large and active community
Popularity in enterprise applications all set it apart from other
languages.
4. Compiling & executing Java Program
public class MyFirstJavaProgram {
public static void main(String []args) {
System.out.println("Hello World"); // prints Hello World
}
}
C:> javac MyFirstJavaProgram.java
C:> java MyFirstJavaProgram
Case Sensitivity − Java is case sensitive
Class Names − For all class names, the first letter should be in Upper Case
Method Names − All method names should start with a Lower Case letter
ex. public void myMethodName()
5. Keep in Mind! (Analysis)
Program File Name − Name of the program file should exactly match the class
name.
public static void main(String args[]) − Java program processing starts from
the main() method which is a mandatory part of every Java program
public − scope of the class. Public means visible to all.
class − declares the class in java.
static − marks element as static so that it can be accessed without creating the
object.
void − return type of the function. void refers to nothing.
String[] args − command line arguments.
System.out.println() − print the statement on the console.
public static void main() − the main method is startup method of java program.
It is visible to all, it is static, so no object is required, and it is not returning any
7. JVM, JRE, JDK
1. JVM:
It Stands For Java Virtual Machine. JVM Is A “Platform Dependent”.
Also, It Executes The Bytecode Generated By The Java Compiler.
Thus, It Provides The Run-Time Environment For The Applications To
Execute/Run.
JVM Takes Care Of The Memory Area, Register Set, Also Provides A
Garbage Collection Heap.
2. JRE:
JRE Stands For Java Runtime Environment.
It Also Gives An Environment To Run The Java Program.
Thus, It Consists Of JVM And Java Class Libraries.
JRE However Provides A Package Of Tools For Running Java Codes.
8. 3. JDK:
JDK Stands For Java Development Kit.
Though It Consists Of The Necessary Tools To Create Java Programs.
Therefore, It Includes JRE, Compilers, Java Debugger, Javadoc.
Also Require To Create, Compile, And Run The Java Source Code.
In Simple Terms, It Is A Package Of Tools For Developing Java-Based
Software.
It Requires A JRE Because Running Java Programs Is Part Of Developing
The Java Codes And Applications.
4. ByteCode:
Javac Compiles The Java Code And Generates Bytecode Which Is Saved
In A .Class File.
9. Features of java
Why Java?
Portable- WORA
Security
Designed for network programming
Multi-thread(multiple simultaneous task)
Dynamic & Extensible – Loaded only when needed, classes stored in
separate files
12. Type Casting in Java
In Java, type casting is a method or process that converts a data
type into another data type in both ways manually and automatically.
Convert a value from one data type to another data type is known
as type casting.
1.Widening Type Casting
Converting a lower data type into a higher one is called widening type
casting. It is also known as implicit conversion or casting down
The target type must be larger than the source type.
byte -> short -> char -> int -> long -> float -> double
2.Narrowing Type Casting
Converting a higher data type into a lower one is called narrowing type casting. It
is also known as explicit conversion or casting up.
double -> float -> long -> int -> char -> short -> byte