The document provides an overview of Java programming, covering basic syntax, the structure of a Java program, and the execution process. It explains the Java program life cycle, including compilation and execution by the JVM, as well as the concept of byte code and Java keywords. Additionally, it discusses primitive data types, variables, and the significance of comments in Java source code.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
7 views13 pages
Core Java - Introduction
The document provides an overview of Java programming, covering basic syntax, the structure of a Java program, and the execution process. It explains the Java program life cycle, including compilation and execution by the JVM, as well as the concept of byte code and Java keywords. Additionally, it discusses primitive data types, variables, and the significance of comments in Java source code.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 13
Basic Syntax
1, Class
+ It is the most basic fundamental unit of writing a Java Program
2. Main Method
* It is the entry for execution inside a Java Program.
‘Syntax:
class Classname
public statie void main(String] args)
{
{Source Code
}
Example Program
class FirstlavaProgram
{
public static void main(String[] args)
{
System.out.printin(“Welcome to Java Class”);
}Procedure to execute Java Code in Cmd
* Always save the java file as Filename.java
Execution Commend:
+ javac Filename,java
+ java classname
+ Note: Filename and Classname not necessary to be same but highly
recommended to give the same name for both.
System.out.printin();
* It is a Java statement.
* This statement is used by a programmer to display content on the
output screen.
Note:
1. String values should be in double quotes.
2. Single Characters should be in single quotes.
3. Numbers and Boolean values are displayed directly.String, Single value, Numbers and Boolean
* FAMEHUB ---->> String —--> ”SMVITM”
+ 2020 --> Whole number -----> 2020
9.95 --> Decimal number ----> 9.95
“Ss --> Single Character -----> ‘Ss’
* true
* false Boolean (first letter should not be in capital letter)
Example Program
class Example
{
public static void main(String{] args)
{
System.out.printin(“Adhiyamaan”);
System.out.printin(2020};
System.out.printin(9.90);
System.out.printin(true);
}JAVA PROGRAM LIFE CYCLE
+The programmer creates the source code and saves program with file
name and “java” file extension.
+ The “java” file is provides to the compiler which checks the syntax level
mistakes made by the programmer.
1.If mistakes are found the compiler displays appropriate error
message.
2.If no mistakes are found the compiler generates “.class” file which
contains java Byte code.
+ The java byte code is executed by the JVM with the help of subsystems in
the JRE.
* The programmer performs basic output analysis.
JAVA PROGRAM LIFE CYCLE
, , ,
ja dass file
ad
Cateod
Classname classByte Code
+ It is a highly optimized version of the java source code.
* It is generated by the compiler and is present in the “class” file.
* The byte code is not human readable.
* The JVM can understand bytecode and it can be considered as java
executable code.
JAVA C
+ Java is the name of the Java Compiler.
* It takes the java source code in “java” file as input and checks for the
syntax level mistakes.
*If programmer has made mistakes it displays corresponding error
messages.
* If there is no mistakes the compiler generates “class” file with the
byte code.
Java Virtual Machine(JVM)
* This is the execution engine of java language.
* The JVM is responsible for all run time activities in Java Language.
+ The JVM executes byte code line by line and generates output.
* It is a Virtual Machine and does not have physical existence.JAVA RUNTIME ENVIRONMENT (JRE)
* The JVM uses several tools during execution like
* Loaders
* Linkers
* Verifiers
* Memory Managers
* Event Handlers etc.
* This collection of tools is necessary for execution in package as the
JRE.
* All activities in the JRE is controlled by the JVM.
“+” Operator
* The “+” operator in java performs the following two operations.
* Addition
* Concatenation(Joining)
* String + Any Value --> Concatenation
Order of Execution
* In java the vertical order of execution in top-bottom.
+ In java the horizontal order of execution in left-right.
Top
Let Right
BottomCOMMENTS
+ Comments are notes made by the programmer in Java Source Code.
+ Comments are used by the programmer to provide code description
or documentation.
+ In java comments are of two types.
* Single Line Comment (//)
* Multi Line Comment(/* */)
* Comments generally appear in green color.
History of JAVA
* Java was commercially released in the year 1995 by Sun
microsystems.
* James Goosling is called as the father of Java Programming language.
* Initially named as “Oak” was later renamed as “Java”.
* There have been several releases of the Java Programming language.
* The current latest version is Java 22 or Java SE 22.
+ However the stable version in use is Java 17 or Java SE 17.
* Currently Sun microsystems is wholly owned by Oracle.
What is JAVA?
+ Java is a multipurpose, High level, Object Oriented, Platform
independent, Programming Language.JAVA IS PLATFORM INDEPENDENT
* Java programs written in one platform can be directly executed in
‘other platform.
a
unus => works
Platform
* A platform is a combination of the hardware and software
components in a Computer.KEYWORDS
* Keywords are inbuilt words in Java Language that have special
meaning.
* As a programmer we can use these keywords in our program but cant
change their meaning.
* Keywords are completely in lower case.
* Keyword in a standard editor will appear in the shade of blue color.
+ Java Provides a total of 53 Keywords.
Special Note: “goto” and “const” are two keywords has no meaning.
53-KEYWORDS
byte short int long float double char boolean void true false null class
enum interface extends implements
if else switch case break default for do while continue assert
return new instanceof abstract static final native transient volatile
strictfp synchronized try catch finally throws throw this super public
private
protected package import
goto constPRIMITIVES AND VARIABLES
+ Primitives and variables will help programmer to store values in a Java
Program
PRIMITIVES
+ Primitives are inbuilt datatypes, it is available in java as Keyword.
* Primitives inform what types of value can be stored.
+ Primitives are used to create variables
+ Java offers a total of eight primitives.
1. byte-1Byte 5. float - 4 Bytes
2. short-2 Bytes 6. double - 8 Bytes
3. int-4Bytes 7. char- 2 Bytes
4,
Jong —8 Bytes & Boolean NA (1-bit)PRIMITIVES
+ Primitives are inbuilt datatypes, it is available in java as Keyword.
* Primitives inform what types of value can be stored.
+ Pri
+ Java offers a total of eight primitives.
1. byte-1Byte 5, float - 4 Bytes
itives are used to create variables
2. short-2 Bytes 6. double - 8 Bytes
3. int—4 Bytes 7 cher ~ 2 Bytes vi
4. long —8 Bytes 8. boolean - NA (1-bit)
PRIMITIVES
+ Primitives are inbuilt datatypes, it is available in java as Keyword.
* Primitives inform what types of value can be stored.
+ Pri
+ Java offers a total of eight primitives.
1. byte -1 Byte 5. float - 4 Bytes
short-2 Bytes 6. double - 8 Bytes
int-4 Bytes 7: char -2 Bytes
8. boolean — NA (1-bit)
long - 8 Bytes
ives are used to create variables
ayNPRIMITIVE TREE
PRIMITIVE
NUMBERS CHARACTERS BOOLEAN
WHOLE IRRATIONAL
NUMBER — NUMBER * char * boolean
+ byte + float
* short — + double
* int
+ long
VARIABLES
* Variables are tokens/containers that hold a value
SYNTAX
Approach 1
datatype variableName;
variableName = Value;
Approach 2
datatype Variable Name = Value;FLOAT AND LONG
+ Playing with long and float values.
Long Datatype
* In Java all the whole numbers by default considered as int type
values.
* All long values should be suffixed with the alphabets “L” or “I”.
Float Datatype
+ In Java all the decimal point values are considered as double type by
default.
* All float values should be suffixed with the alphabets “F” or “f”.
RE-INITIALIZATION
+ Re-initialization is the concept of replacing the old value in a variable
with the new value.
FINAL VARIABLE
* Any variable that is created with final keyword is called as final
variable.
* It is not possible to re-initialize the final variable.