Java Notes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

java

----> types of java programs

APPLETS APPLICATION PROGRAMS

** Applets:-> java program that are embedded with in a web-page


** Application programs:-> java programs that are written for specific
application and that runs on any machine that support java

types of application programs


(1)-> consol application:-> programs that support I/O intext format
(2):->GUI(graphical user interfaces) :->> program that can create and
manage multiple window and provide GUI mechanism of a window
based program

JAVA ENVIRONMENT:-->
Print(“hello”);
System. Out .print(“hello”);
Compiler java

window Unix os c:>java demo.java


c:>java demo.java show(“hello”); display (“hello”);
Call that function of os that send output
Show(“hello”); Display(“hello”);
screen(“hello”);
// for window // for Unix os

*java is platform independent , but JVM is platform dependent


*we can run over java program on a wide variety of computer this‘s
possible because over java program does not execute directly on a
computer it run on a standardized hypothetically computer call java
virtual machine (JVM) which is implement in a computer by a program
(JAVA interpreter)

Demo.java c:>java demo.java demo. Class

Java source Compiler Java object


code code

Object code is verified


And loaded into JVM

* java interpreter executed our


Compiler code and handle all
Java virtual machine
Communication with os
Java interpreter

• we can run over java program on a wild verity of computer


Operating system
• the java program that we write is converted by java compiler to a
binary file consisting of byte code, bye code are binary instruction for
java interpreter.
•the java interpreter inspects byte code checks out ensure that it’s safe
to execute, and than it execute the action specify with in JVM.

compiling a java program:


Java c is compiler that compile a program
and create some file with a extension. class the class file contain byte
code that are binary instruction for java interpreter
C:> java c demo. Java
(to run application program)
• A java program must be save with a extension .java
•we must save the program file with a same name as that of the class
defined with in it.
•A java program is a collection one or more classes there is at-least one
class in every program.
•we must put the code for each class in separate file.

Variable:-->
Variable is a named value holder in primary memory.
When a variable is declare the compiler is able to check that it’s not
being use in a manner or context that is a inappropriate to it’s time.
variable name:---->
The name we chose for a variable is called Is
identifier and identifier can be of any length but it must beginning with
in alpha bate(a ,b ,c) & $,&__ the rest of an identifier can include
digits also.
Operator spaces are not allowed in an identifier .
•we can’t use java keywords as a name for something keywords are
words that are essential part of java language.
•java is a case-sensitive language.
Int max, mAx , maX, MAX ; √
ab cd (wrong because space is present, space is not allowed )
ab + cd (wrong)
ab – cd (wrong)
ab @ cd (wrong, because @ not allowed)
while (wrong, loop is present)
While (right √)
ab$123 (right √ )
$ab_123 (right statement )
_ab123(right )
123abs (wrong , because start with digits )
*Calculate Total Marks // class
*calculate Total Maeks // variable
*calculate Total Marks() //method

☹☹☹
Note :::::::: java
{function<-->method} c++
{const<-->final}
{.dlldata link library }
[os + java interpreter => JVM]

constant ::---> final int MAX=100; // CONSTANT


if a variable is declared final it’s value can’t be changed

LITERALS :::----->>> explicit data value that appear in a program are


called literals
EX:-- int no = 24;

Variable literals

Char ch = A;
**String str = ”java”;
Variable literals
Boolean b = true;
COMMENT ::--> comment are non executable statement , that are
ignored by compiler they are use just increase readability of the code.
// single line comment
/*------
--------------------
*/ multiple line comment
•A variable can be declare anywhere in java program just before it’s
use.
•we can spread in a single declaration over several lines .
EX:::---
Int miles = 0 ; // one mile is 8 yards
Furlongs = 0 ; // any comment
Yards =0; // any comment
Feet =0; // any comment

EXPRESSION ::::----->>>> an expression is a valid combination of


operators & operand
TYPES OF EXPRESSION
(1) Constant expression :-> all of the operands are either constants or
literals
• evaluated at compiler time
Eg: (i) 2+3
(ii) 20*4/2
(iii) final int No=20;
No*7/4
(iv) 25

(2):::---->>> if any of the operands is a variable , it become variable


expression
• evaluated at Run-time.
Eg: (i) a+b
(ii) a*20+4
(iii) a
(iv) int b = a+2;

DATA TYPE CONVERSION::--- ☹ use:(small to larger)


Int a=25;
double b=3.14;
b=a; // widening of data type

implicit type cast use ☹use:( large to small)


a=b; // narrowing of data type
complier time error
☹☹narrowing data type is not allowed in java (compiler time error)

NOTE:-> underscore (_) is allowed in numeric literal they are use


increase readability of the code. They are automatically removed at the
compiler time.
• underscore(_) can appear anywhere is numeric literals, but it should
not appear at the beginning and end of the written.
Eg: int no=1234;
Or
Int no=1_2_3_4; {allowed statement }
Eg: int a= _1234;
Int b=1234_;
{not allowed underscore start and end}

DATA TYPES ::----->>> there are 8 data types defied with in the
language , these fundamental type are also called primitive data types.
•integer data type ::---> these are four data type that can store integer
value.
☹all of these are signed
Data types description size
{1} byte -128 to 127 1 byte
{2} short -32768 to 32767 2 byte
{3} int 2147483648 to 4 byte
2147483647
{4} long -9223372036854775808 8 byte
To
9223372036854775807
*size  n bits }calculate size to range
Range  -2ki power n-1 to +2 ki power n-1 -1
😉😊
Int no = 23; // decimal no.
Int no =023; // octal no.
Int no =0x23; // hexadecimal no.
Int no = 0b0100; // binary no.

Eg: int no = 039;


// compiler time error because octal are contain only
0 to 7
int a =32;
long b= 32;
long b= 32 L;
32 l;

You might also like