Java Notes
Java Notes
Syntex
The following table summarizes all versions of Java SE from its early days to the latest.
Java SE
19 19
Versions 1.0 and 1.1 are named as JDK (Java Development Kit).
From versions 1.2 to 1.4, the platform is named as J2SE (Java 2 Standard
Edition).
From versions 1.5, Sun introduces internal and external versions. Internal
version is continuous from previous ones (1.5 after 1.4), but the external
version has a big jump (5.0 for 1.5). This could make confusion for someone,
so keep in mind that version 1.5 and version 5.0 are just two different version
names for only one thing.
From Java 6, the version name is Java SE X.
2) Hello is our class name. First letter of class name should be in uppercase. It
is not a condition but it is just a convention.
6) System is also a final class from java.lang package. out is a static member
of System class of type PrintStream. println is a method
of PrintStream class.
7) You can explore the source code of both System class and String class. Go
to JDK installation directory and extract the ‘src‘ zip file. Then go to src –> java
–> lang. In lang folder, you will find both System and String Java files.
Source code
class Hello
Int a=10;
System.out.println(“Hello”);
System.out.println(“Hello ” + “World”);
Compiler – analyse the code and find the syntax error in the programs
Which read the lines one by one and display the error
package com.corejava.demo;
/*advantage of java
Object oriented programming language
Functional programming language - task why
the java is called functional programming
language
platform independent
simple - python
multithreded-
Interpreted language
High performance - JIT(Just In time)
Java editor
Notepad
Eclipse
Netbeans
VScode
Java Identifiers
All Java components require names. Names
used for classes,
variables, and methods are called
identifiers.
• All identifiers should begin with a
letter (A to Z or a to z), currency
character ($) or an underscore (_).
• After the first character, identifiers
can have any combination of characters.
• A key word cannot be used as an
identifier.
• Most importantly, identifiers are case
sensitive.
Java Variable
variable is a container
A-Z to a-z
3 types
• Local variables
• Local variables are declared in methods,
constructors, or blocks
• Local variables are created when the
method, constructor or block
is entered and the variable will be
destroyed once it exits the method,
constructor, or block.
• Local variables are visible only within
the declared method, constructor, or block
• There is no default value for local
variables, so local variables should
be declared and an initial value should be
assigned before the first use
• Instance variables
• Instance variables are declared in a
class,
but outside a method, constructor or any
block.
• Instance variables are created when an
object is
created with the use of the keyword 'new'
and destroyed when the object
is destroyed.
• The instance variables are visible for
all methods,
constructors and block in the class.
• Instance variables have default values.
• Class/Static variables
a=s; character
a=10.5 floating number
a=padmaja world string (collection of
character)
class NameOfTheClass
{
//Body of the class
//what it includes in the body
//data member
// member functions
}
/*
* class ABC { int a; } class Student {
//data member int id; // instance
* variable String name address course int
dob
*
* // member functions accessspecifier
returntype methodname(parameter list)
*
* public void display() {
*
* }
*
* store
*
* view
*
* }
*/
// Relatinonal operator
System.out.println("a > b = "
+ (a > b));
System.out.println("a < b = "
+ (a < b));
System.out.println("a >= b = "
+ (a >= b));
System.out.println("a <= b = "
+ (a <= b));
System.out.println("a == b = "
+ (a == b));
System.out.println("a != b = "
+ (a != b));
// bitwise operator
/*
* Java defines several
bitwise operators,
* which can be applied to the
integer types, long, int,
* short, char, and byte.
Bitwise operator works on bits and
performs bit-by-bit operation
*/
int m=60; // 0011 1100
// 128 64 32 16 8 4 2
1
// 0 0 1 1 1 1 0
0 =60
int n=13; // 0 0 0 0 1 1
0 1 =13
// a&b = 0000 1100 = 12
/*
* a|b = 0011 1101 =61
a^b = 0011 0001 =49
~a = 1100 0011 =
*/
result=m & n;
System.out.println(result);
result=m | n;
System.out.println(result);
result=m ^ n;
System.out.println(result);
result=m & n;
System.out.println(result);
result=m >> 2; // 15
System.out.println("m >> 2" +
result);
result=m << 2; // 15
System.out.println("m << 2" +
result);
// Ternary Operator
int min=(a<b)? a : b;
System.out.println(min);
// assignemnt/complex operator
System.out.println("a=a+b " +
(a +=b));
System.out.println("a=a-b " +
(a -=b));
System.out.println("a=a*b " +
(a *=b));
System.out.println("a=a/b " +
(a /=b));