0% found this document useful (0 votes)
35 views10 pages

Java Notes 2025 First Term

Java is an object-oriented programming language created by James Gosling at Sun Microsystems, first released in 1995. It features characteristics such as WORA (Write Once Run Anywhere), robustness, and security, and uses the UNICODE character set. Key elements include tokens, data types, variables, and operators, with specific rules for naming identifiers and creating variables.

Uploaded by

magicalanims
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views10 pages

Java Notes 2025 First Term

Java is an object-oriented programming language created by James Gosling at Sun Microsystems, first released in 1995. It features characteristics such as WORA (Write Once Run Anywhere), robustness, and security, and uses the UNICODE character set. Key elements include tokens, data types, variables, and operators, with specific rules for naming identifiers and creating variables.

Uploaded by

magicalanims
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Java is an object-oriented programming language developed by James Gosling and colleagues at

Sun Microsystems in the early 1990s.


The First name of this language was OAK.
The first public implementation was Java 1.0 in 1995.
Characteristics of Java
• Java is WORA(Write Once Run Anywhere) language. Means Java programs can be run on any
platform (Linux,Window,Mac)
• It is a Robust language. Robust simply means strong.
Java encourages error-free programming by being strictly typed and performing run-time checks.
• Java provides secure way to access web applications.
• Pure OOPS language
Character Set Of Java
• A set of valid characters which a language can recognized is known a character set .
• Java’s Character set is UNICODE.
ASCII UNICODE
1. It is a One Byte character set. 1. It is a Two Byte character set.

2. It can represent maximum of 256 2. It can represent maximum of 65536


characters.(0-255) characters.(0-65535)

3. It can store data only in English language. 3. It can store data in any worldly language.

Source Code Object Code

1. The program code written by the programmer 1. The code created by the compiler after
using any computer language. successful compilation.

Ordinary Compilation Java Compilation

1. Compiles and convert the code directly 1. Compiles and convert the code to byte code.
to machine code.
2. Directly executable on machine. 2. Needs Interpreter (JVM) to execute.

Byte Code and JVM


Byte code :-It is the intermediate code language of java The java compiler compiles the
source code and converts it into byte code.
JVM:- It stands for Java Virtual Machine. It is a java interpreter which converts the byte
code to machine code during execution

Types Of Java Program


Applet:- Applet Programs are small java programs developed for internet applications.
Applets are embedded in HTML documents. Applet programs can be run using the applet
viewer or web browser.
Application :- The Java stand-alone applications are the programs written in Java to carry
out certain tasks. These applications run directly by the Java interpreter.

Elements of Java
1. Tokens
2. Data Types
3. Variables
4. Statement
5. Block
Token
It is the smallest meaningful unit of Java program.
Types of Tokens:
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators(separators)
Keyword
Special words which convey some special meaning to java compiler. They cannot be
used for any other purpose.
Eg. if, for, while etc.
Note: Are written in only small alphabets.
Java is a case sensitive language.
Identifiers
The user defined names used inside a program are known as Identifiers.
Eg. Variable names, methods names, class names.
Rules for naming Identifiers:
1. Keywords cannot be used.
2. Can contain alphabet (a to z, A to Z), digits( 0 to 9) and 2 special character
_(underscore) and $(dollar) .
3. Must not starts with a digit.
4. Should not contain any embedded spaces.
5. Should be unique inside a program.
Eg. Valid Identifiers: Emp1, a , A , name_emp, t$m , $t
Invalid Identifiers: 1Emp, a@1 , name emp, for
Literals
Any fixed or constant value used inside a program.
Eg. “Rita”, 49 , ‘A’ etc.

The Six Types of Literals are:


1. Integer Literals: Constant numeric values without .(Decimal).
Eg. 12,67, -78, 9 , -5 etc.
2. Real Literals: Constant numeric values with .(Decimal).
Eg. 12.9, 67.0, -78.7 , 9.6 , -5.0 etc.
3. Character Literals: A single character inside single quotes.(‘’).
Eg. ‘A’, ‘&’ , ‘b’ , ‘#’ etc.
4. String Literals: Zero or more characters inside double quotes(“”). Eg . “Rita”, “56”,
“9.0” , “St. Thomas”, “true”.
5. Boolean Literals: The two java reserved words true and false are known as Boolean
literals.
6. Null Literal: The java reserved word null which refers to nothing.

Operators
These are the special symbols of java , which when used with
operands triggers some specific action.
eg.
3 + 4 [3 and 4 are the operands and + is the operator]

Punctuators(Separators)
These are the special symbols used to separate different parts of a program.
Eg. ; , : {} () ‘ ’ “ ” etc.

Statement:

A Valid combination of java tokens is known as statement . It always ends with semicolon (;)
Eg1. System.out.println(“hello);
Eg2. String h=“Thomas”;

Block:

A group of statement enclosed inside {} is known as block . It is considered as one compound statement of
java.
Eg1. {
int a=97;
String m=“Ria”;
System.out.println(“Name = ”+ m + ”Marks= ” + a);
}

Data Types
These are the means to store the different types of literals inside variables. It also refers to
the operators associated to the literal.
Types of Data Types:
1. Primitive data type
2. Reference data type

Primitive Data Type


It is a set of predefined (inbuilt) data types of java.

These again are categorized as follows:


1. Integer data types
2. Real data types
3. Character data types
4. Boolean data type
Integer (Primitive) Data Types

Data Type Size Range Default


Name Value

byte 1 byte -27 to 27 -1 0

(8 bits) -128 to 127


short 2 bytes -215 to 215 -1 0

(16 bits) -32768 to 32767

int 4 bytes -231 to 231 -1 0

(32 bits)

long 8 bytes -263 to 263 -1 0L

(64 bits)

Real (Primitive) Data Types


Data Type Size Range Default
Name Value

float 4 bytes -3.4E38 to 3.4E38 0.0f

double 8 bytes -1.7E308 to 1.7E308 0.0d

Character (Primitive) Data Type

Data Type Name Size Range Default


Value
char 2 bytes 0 to 65535 ‘\u0000’

Some important characters and their numeric values:


Characters Numeric Value( ASCII)

A to Z 65 to 90

a to z 97 to 122

0 to 9 48 to 57

Boolean (Primitive) Data Type


Data Type Name Size Range Default
Value

boolean 1 byte true / false false

Reference Data Type


Data types which are created with the help to existing (primitive or reference) data types.
Also known as User defined data types or Composite data types.
These are class, arrays and interfaces.
Eg.: String class
*size depends on value stored
* Default value is null for String and Objects.

Variables
These are the named memory places. used to store literals in it according to their data type
mentioned.

Creation of Variables
Method 1 (without Initial value):
Syntax:
<Data type name> <variable name> ;
[ Variable is an identifier so remember the rules of it]
For storing a numeric value without decimal(Integer Literal):
int a; long b;
For storing a numeric value with decimal(Real Literal):
float n; double a;

For storing a single character(Character Literal):


char ch;
For storing true or false(boolean Literal):
boolean b;
For storing more than one character(String Literal):
String name;

Method 2 (with Initial value):


Syntax:
<Data type name> <variable name>=value ;
[ Variable is an identifier so remember the rules of it]
For storing a numeric value 56 (Integer Literal):
int a=56;
For storing a numeric value 6.5 (Real Literal):
float n=6.5f; double a=6.5; [You can also write 6.5d]
For storing a single character H (Character Literal):
char ch=‘H’;
For storing true (boolean Literal):
boolean b=true;
For storing Rita (String Literal):
String name=“Rita”;
Multiple variables of same data type can be created in one line by using Comma(,) between them.
Eg.: int a; int a,b;
int b;
double d=4.5; double d=4.5 , m;
double m;
Self Testing Time
Write the variable creation one line statement:
1. Declare a variable to store your father’s name.
2. Declare variables for storing your and your best friend’s marks, marks doesn’t contain any
decimal value.
3. Declare a variable and store symbol @ in it.
4. Declare a Variable to store the value false.
5. Declare a variable to store 3.14.

Operators In Java
1. Unary operator
2. Binary operator
3. Assignment operator
4. Concat operator
Unary Operators
Operators which works on only one operands.
These are:
+, - , ++(Prefix- Postfix increment) , --(Prefix- Postfix decrement)
Eg1:
int a=5,b;
b=-a; // means b = - ( 5 )
System.out.println(b); Output : -5
Eg2:
int a=-5,b;
b=-a; // means b = - ( - 5 )
System.out.println(b); Output : 5
Eg3:
int a=5,b;
b= +a; // means b = + ( 5 )
System.out.println(b); Output : 5
Eg4:
int a=-5,b;
b=+a; // means b = + ( - 5 )
System.out.println(b); Output : -5

++(Prefix- Postfix increment) , --(Prefix- Postfix decrement)


These operator increment or decrement the value of operand by 1.Prefix means operator before
operand and postfix means operator after operand.
Eg1:
int a=5;
++a;
System.out.println(a); Output : 6
Eg2:
int a=5;
a++;
System.out.println(a); Output : 6

Prefix Principal:- Change than Use


Eg1:
int a=5;
++a; // Used Independently here
System.out.println(a); Output : 6
Eg2:
int a=5;
System.out.println(++a);
// Used with another operation
System.out.println(a);

Output : 6
6

Postfix Principal:- Use than Change


Eg1:int a=5;
a++; // Used Independently here
System.out.println(a); Output : 6
Eg2:
int a=5;
System.out.println(a++);
// Used with another operation
System.out.println(a);

Output : 5
6

Eg3:
int a=5, b;
b=++a; // prefix Used with another operation so first a will get new value than b will gets its value
System.out.println(“a= “ +a);
System.out.println(“b = “ + b); Output : a= 6
b= 6
Eg4:
int a=5, b;
b=a++; // postfix Used with another operation so first b will get new value than a will gets its value
System.out.println(“a= “ +a);
System.out.println(“b = “ + b); Output : a= 6
b= 5
Eg5:
char ch=‘A’,ch1;
ch1=++ch;
System.out.println(“ch= “ +ch);
System.out.println(“ch1 = “ + ch1);
Output :
ch= B
ch1= B
Eg6:
char ch=‘A’,ch1;
ch1=ch++;
System.out.println(“ch= “ +ch);
System.out.println(“ch1 = “ + ch1);
Output :
ch= B
ch1= A

Binary Operators
Operators which works on two operands and does some arithmetic operation on them.
These are:
+, - , / , * , %
Eg. int a=4, b;
b= a + 5; //Operand 1 → a Operand 2 → 5
System.out.println(b); Output : 9
% is known as modulus it is used to find the remainder of division operation eg. 15%3 will give 0 ,
15%4 will give 3.

Concat operator
The + operator used with a String literal or variable is known as concat operator. It is used to join
String value with others.
Eg. int a=10;
System.out.println(“Value in a = ” +a); Output:
Value in a =10
String fname=“Rita”, lname=“Arya”;
System.out.println(“First name :”+fname+ “ Last name:” +lname);
Output:
First name :Rita Last name:Arya

Printing In Java

1. System.out.println()
It prints the contents on screen and the print cursor moves to next line.

[means next print statement will print the contents in a newline]

Eg. System.out.println(“Hello”);
System.out.println(“World”);
Output:
Hello
World
2. System.out.print():
It prints the contents on screen and the print cursor moves to next position in same line.
[means next print statement will print the contents in same line without any gap]]
Eg. System.out.print(“Hello”);
System.out.println(“World”);
Output:
HelloWorld

Comment Entries : Entries which are ignored by the compiler are known as comments.
These are used for documentation of program. Can be written in any part of program.
The three types of comment Entries :
1. Single line Comment entry ( //….)
2. Multi line Comment Entries (/*……. */)

Scanner Class
• It is a predefined class of java.util package
• It is a collection of many input functions of java
• Each data type contains its own method for input.
import java.util.* ; →util package contain Scanner class
class classname
{
public static void main()
{
// creating Scanner object
Scanner sc=new Scanner(System.in); →Creation of Scanner object.
// other code lines
}
}
Scanner Class Methods

Data Types Methods

byte nextByte()

short nextShort()

int nextInt()

long nextLong()
float nextFloat()

double nextDouble()
boolean nextBoolean()

char next().charAt(0)

String 1. next() // for One word


Input
2. nextLine() // for
multiple
word(sentence) input

Eg1.
WAP to accept grade of your examination and display it with message.

import java.util.* ;
class message
{
public static void main()
{
Scanner sc=new Scanner(System.in);
char g;
System.out.print(“Enter Grade “);
g= sc.next().charAt(0);
System.out.println(“Grade Entered= “ +g);
}
}

You might also like