Feature of Java
simple and easy to learn
open source
plateform independent.
Secure (bit code)
embedded
compiled and interpreted
Robust (garbage collector ased)
large library and frameworks
Why Java is so Popular
-Software
-Web development
-application
What is Java? Full explaination.
Java is a class-based, high-level, object-oriented programming language developed by "James Grosing and his Friends in 1995.
Java is a programming language known for its versatility and platform independence. It operates on the "Write Once, Run Anywhere" principle, achieved by compiling code into an intermediate form (byte code) interpreted by the Java Virtual Machine (JVM). Emphasizing object-oriented programming, Java employs classes and objects and includes core principles like encapsulation, inheritance, and polymorphism. With a syntax similar to C and C++, Java's clean and simple structure reduces programming errors. Automatic garbage collection manages memory, freeing developers from manual memory tasks. Java supports multithreading, facilitating concurrent execution. The language boasts a rich standard library (Java API) covering utilities, networking, databases, GUI development, and more. This library accelerates development by simplifying common tasks. Security features, such as sandbox environments for applets and a security manager, enhance Java's robustness. The language has a vibrant community and an extensive ecosystem, featuring frameworks like Spring and Hibernate. Portability is a key strength; once compiled, Java code can run on any device with a compatible JVM. Java is employed in diverse applications, from web and mobile development (Android) to enterprise-level and scientific applications. With various releases introducing new features, Java remains a popular choice in the software development industry.
Note:
The first version of Java (JOK 1.0) was realized on January 23, 1996, by Sun Microsystem. The latest version of Java (JOK the day of March 2021) was released by Oracle.
syntax-
Closing class name.
{
public static void main (string avg s [])
// code
}
main = method.
public = executed the program present in the main code by Jum
static = execute code without make object void value not written
String = pre-define Class
Java comment
1) A single-line comment
2) multi-line comment
What is data type & Full explaination.
The data type specifies the different types of values that are stored in the variable.
Java data types define the types of data that can be stored in variables. The primitive and references data types are the two primary classifications.
Early Data Types:
Integral Categories:
Byte: signed integer with 8 bits.
brief: a signed 16-bit integer.
int: a signed 32-bit integer, commonly used for integers.
long: signed integer of 64 bits.
Types of Floating Points:
float: floating-point, 32-bit data.
double: floating-point data with 64 bits (common for decimals).
Type of Character:
char: A Unicode character of 16 bits.
Boolean Category:
Boolean: shows what is true or untrue.
Types of Reference Data:
Items:
Classes have instances that are objects.
User-defined classes, String, and Array are a few examples.
Unique Types:
No object reference is represented by null.
Early Data Types:
Integral Categories:
byte: Integers between -128 and 127.
larger integer (-32,768 to 32,767) in brief.
int: Common to the majority of integers.
long: Exceptionally big integers.
Types of Floating Points:
float: The accuracy in the middle
type
*Primitive
1) numeric 2) Non-numeric
Byte(1) char(2)
Short(2) boolean (1)
Int(4)
long(8)
double (8)
Float
*Non primitive
Class
array
String
etc
set
What is a variable and a full explanation
variable is the name of the memory location where we store different types of values.
*Type
local {
Static/static kywords use
instance // class {_}
Final: Do not change the value.
Program (data type)
Class second {
int a=10;// instant variable
Static double b=20.5; // static variable
Public static void main (string[]arg) {
Boolean c=true;// local variable
Second = new second ();
System.out.print In (s, a);
System.out.print In (b);
System.out.print In (n);
}
}
*Output :
10
20.5
True
*Second method
system.out.print in (s, a+--+b+--+C);
Output!:
10,20.5,true
What s keyword ?. Full explanation
Keywords are reserved words whose meaning is already defined in the Java compiler.
Note :- we can't personal keyword use keyword for our are are the case-Sensitive-
Java keywords! -
byte boolean extend
Short if implements
Int else final
Long do try
Float for catch
Double while through
void break throws
char continue static
Volatile default private
Protected public imports
Interface: new native
Instance of the case package
Return this super
Switch const abstract
Const*
Go to*
Strict fp**
Enum****
assert***
What is identifier & Full explanation
What is the identifier and full explanation?
Identifiers refer to the name of the variable method, class, etc. On
ex -
int a;// variable
void mi();// method
Class A;//class
interface B;
Note -
All identifiers are not variables, methods, classes, etc., but all variables, methods, and classes are identifiers.
#Input and output
input: Scanner Class (java.util.Scanner)
*syntax-
Scanner obj-name = new Scanner(System.in);
*Scanner class method
1) Next Int() for integer value
2) next line() - for double value
3) NextDouble()→ For double value.
*output -
System class (Java.lang.System)
*syntax!-
System.out.print(" ");
Q- W. A. P to add two numbers?
import java.util.Scanner;
public class A{
public static void main(String []arg) {
int a, b, c
System.out.print ("Enter any two numbers.) Scanner s=new Scanner(System.in);
a = s next Int ();
b = s next Int();
C=a+b;
System.out.print ("Sum of two numbers: ");
}
output :
Enter any two numbers.
20, 10
sum of turo number 30
#control flow:
1) a conditional statement.
2) looping statement
3) transfer statement
* Conditional statement
If statement: It is used when we want to test a single condition.
Syntax-
if (condition)
{
//statement
}
FlowCharts:
![]() |
Flowcharts of If statement |
Program
public class condition IF {
public static void main (string[] args){
int pwd;
System out.print ("Enter password: ");
Scanner obj-new Scanner (System.in);
pwd=obj.nextInt();
if (pwd: 2731) //2731 == 2731
{
system out print in ("my name:= Kirti");
System.out print ("my age:=25");
System.out.print("My contact: 4567856995");
}
Output-
Enter password: 2731
My name:=kirti
My age:=25
My contact:=4567856995
2) if-else statement:
It is used when we want to execute a statement for a single condition.
syntax:
if(condition)
{
Statement 1;
}
else
{
Statement 2;
}
FlowCharts:
![]() |
Flowcharts of if else statement |
Program:-
public-class condition. It etse {
public static void main(String ang [])
int pwd;
System.out.print ("Enter password:")
Scanner obj=new.scanner (system.in);
pwd=obj.next int();
if (pwd=2731) //2731==2731
{
System.out.print ("my name=priti:")
System.out.print ("My age is 23")
System.out.print ("my contact=206766:")
}
else
{
System.out.print ("sorry, wrong password");
}
}
}
Output
Enter passwords:=8954
Sorry, wrong password.
Advantage of Java:
Designed around OOP principles, promoting code organization, modularity, and reusability through classes and objects.
Rich Standard Library:
Extensive standard library (Java API) provides pre-built modules, simplifying development and reducing the need for custom code.
Multithreading:
Supports multithreading for concurrent applications, enhancing performance and responsiveness.
Automatic Memory Management:
Features automatic garbage collection, handling memory management and reducing the risk of memory leaks.
Security:
Built-in security features, including a sandbox for applets and a security manager, control access to system resources.
Exception Handling:
Robust exception handling mechanism helps manage errors, improving application reliability.
Scalability:
Applications are scalable, suitable for both small-scale and large-scale projects.
Portability:
Platform independence ensures applications can run on different operating systems without modification.
Performance:
Optimized performance through Just-In-Time (JIT) compilation, translating bytecode into native machine code at runtime.
Enterprise-Level Development:
Widely used for enterprise-level development, supporting the creation of robust and scalable applications.