Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Core Java Part1

The document provides an overview of Core Java, highlighting its advantages such as simplicity, security, and platform independence. It covers fundamental concepts including printing statements, basic structure, variables, data types, operators, and typecasting. Additionally, it explains the characteristics of local and non-primitive variables, as well as various operator types and their functionalities.

Uploaded by

prithirumal
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Core Java Part1

The document provides an overview of Core Java, highlighting its advantages such as simplicity, security, and platform independence. It covers fundamental concepts including printing statements, basic structure, variables, data types, operators, and typecasting. Additionally, it explains the characteristics of local and non-primitive variables, as well as various operator types and their functionalities.

Uploaded by

prithirumal
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 8

CORE JAVA

JAVA: Java is a high level programming language which supports all the Oops Principles.

ADVANTAGES OF JAVA :

1.)Java is a Simple Programming Language.

2.)Java is a Secured language.

3.)Java is a Portable language.

4.)Java is a Platform Independent Language.

5.)Java Provides Rich built-in Libraries,which helps user to perform the complex jobs easily.

6.)It supports MultiThreading(MultiTasking).

7.)Java Supports Oops Principles Such as

Encapsulation,Inheritance,Polymorphism,Abstraction.

PRINTING STATEMENTS:

It is used to print the user written statements on the console.

*Java provides 2 printing(or)display statements:

1.) System.out.print() : Print will print the data and move the cursor to next position of same line.

*we cannot use it without passing the data.

2.) System.out.println(): Println will print the data and move the cursor to initial position of next line.

*we can use it without passing the data also.

BASIC STRUCTURE OF JAVA :

Tokens: A Smallest unit or Component of any programming language is known as Tokens.


1. Keyword: It is a Predefined meaning or Compiler Aware words are called as Keywords.

Rules:

*We Cannot Change the Keywords.

* These are also known as Reserved Words.

* The Keywords must always be in Lower Case , Because java is a case

Sensitive Language

Ex: class,public,static..etc…..

2. Identifier: Identifiers is a name given to the components of java.

Or The name provided by the programmers to the members of java is

known as Identifier.

Like: Variables,Methods,class,Interface.

Rules:

*We Cannot Start Identifiers with Numeric Values.

*Except Dollar($) and Underscore(_) no other special Char are allowed.

*We Cannot use Keywords as Identifiers.

Conventions: Industry Standards…

3. Literals: The Data Written by the Programmer in the Program is called as Literals.

 In java we have following literals

1.Number literals:

*we can pass the numericals values directly in java

---> Integers,Decimals.

2.Character literals: In java anything that we write within single quotes(‘ ’) is known as Characters.

* we can’t pass more than one value.

*The length of character should be one.

---> Alphabets ,Digits and Special Char.


3. String literals: String is a Group of Characters.

*In java if we want to pass any string ,it is mandatory to pass within double quotes.

4.Boolean Literals: It Represents logical data, there are 2 logical values . (True, False).

VARIABLES AND DATATYPES

Variable: Variable is a Named Block Of Memory, Where we can store or fetch the data using name.

*The Name provided by the user to the Container created is known as Variable.

* Variable can store the single value.

Characterstics of Variable:

*We can store or fetch the data using name.

*We can Store only one value.

*We cannot Store Multiple Values.

Note:

The data stored inside variable it is not permanent, it is Temporary data.

CREATE A VARIABLE:

Syntax: datatype identifier; (Variable Declaration Stmt).

CREATE MULTIPLE VARIABLE IN SINGLE STMT:

Syntax: datatype identifier1,identifier2……identifier_n;

Variables : 1) Based on Datatypes :- Primitive & Non Primitive Variable.

2.) Based on Scope: Local Variable , static & non-static Variable .

1.)Primitive variable: The Variable created for Primitive datatype is

known as Primitive variables.

*Datatype: It is Used to Specify size and type of data can be stored inside the container/variable.

*) Types of Datatypes:

i) Primitive datatypes.

ii) Non primitive datatypes.


i)Primitive Datatype: The datatypes which are used to store the

primitive data are known as Primitive datatypes.

*Primitive data: It is a data which can be stored in a single container

or single block.

Primitive datatypes in java are:

Byte,short,int,long,float,double,char,Boolean…( 8 types ).

ii) Non Primitive Datatype: The datatypes which are used to store non

primitive data are known as non primitive datatypes.

*Non-primitive data: It is a multivalue data which cannot be stored in

one block of memory.

*we need multi block of memory.. such as Array,Object.

*In java every classname is a Non-primitive datatype.

*null keyword is the default value for all non-primitive datatypes.

*we can create non-primitive variables(Reference variables) with the

help of non-primitive datatype.

2. Non-Primitive Variable(Reference variable): The Variable created

for Non-Primitive datatype , Which is used to store reference/Address

of an Object/Array is known as Primitive variables.

LOCAL VARIABLE:

A Variable declared inside method block or initializer block or main

method or Any block , Except Class block is known as Local Variable.

Rules of Local variable:

1.) We cannot use local variable without Assigining the data.

2.) we can use the local variable only inside the block where it is

declared.( we cannot use outside the block).


3.) We cannot declare 2 local variable with same name inside the same

scope.

OPERATORS:

Operators are pre-defined Symbols,which is used to perform a specific task on the operands

Operand: The values which user passes is known as Operand.

Types Of Operators:

1.) Based on Operands:- Unary , Binary , Ternary Operator.

i) Unary Operator: An Operator which can accept only one operand is known as Unary Operator.

Ex: Logical not , new , Typecast Operator, Increment & Decrement Operators etc……

ii) Binary Operator: An Operator which can accept only 2 operands is known as Binary Operator.

Ex: Arithmetic Op, Relational Op , Logical Op etc……

iii) Ternary Operator: An Operator which can accept only 3 Operands is known as Ternary Operator.

Ex: Conditional Operator.

2.) Based on type of task:-

i) Arithmetic Operator:

It is a Binary operator which are used to perform arithmetic operations (+,/,-,*,%).

*)Plus Operator(+):- In java plus operator will have 2 behaviours, One

is Concatenation & Another one is Normal Addition.

*)Division Operator: Whenever we are using division operator(/),the compiler will give the Quotient as
Output.

*)Modulus Operator: Whenever we are using Modulus operator(%),the compiler will give the Reminder
as Output.

Case i): If m>n then rem can be 0,1,2……3

Case ii): If m<n the reminder is m.

Case iii): If m==n the reminder is 0.

ii) Increment & Decrement Operator:


*) It is an Unary Operator.

*) The Increment Operator is Represented by (++) , Decrement operator is Represented by (--).

*) They can be used only along with Variables which are the primitive types…. Except the Boolean.

iii) Relational Operator:

*)It is used to Compare two values.(==,!=,>,<,>=,<=)

*)It is Binary Operator.

*)ReturnType of relational Operator is Always Boolean.

iv) Conditional Operator:

*) It is a Ternary Operator.

*) It is used to make a Decisions in java.

*) Syntax: Op1 ? Op2 : Op3

Op1: It Should be a Condition Or Boolean Literal

Op2 And Op3: value /variable/ exp.

*) In Conditional Operator ,the first operand must be of type boolean i.e we can directly write Boolean
literal or We can have an Expression which returns Boolean.

*) The ReturnType of Conditional Op is always depends on the datatype of Op2 & Op3.

Some Questions:

1.) wajp to find Largest of 2 Numbers ?

2.) wajp to check the given number is even or odd.

v) Logical Operators: (&& , || , !):

*) It is a binary operator.

*) The return type of logical operator is always a boolean type.

*) Logical Operator are used to merge more than one condition.

*) In java we have the following types of logical operators:

i) Logical And(&&)

ii) Logical Or(||)


iii) Logical Not(!)

i)Logical And(&&):

*) It is a Binary operator.

*) The And Operator are used whenever it is mandatory to satisfy all the conditions to be performed.

*) In Logical And Operator if the First Condition is returning us false, we can directly say result will be
false itself.

*) if the first condition is false then compiler will never check second condition.

ii)Logical OR(||):

*) It is a Binary operator.

*) The OR Operator are used whenever we can perform a task ,even if any one of the condition is
satisfied. It returns true itself.

iii)Logical Not(!):

*) It is a Unary operator.

*) The return type is boolean.

*) It is used to negate the literals passed to it.

*) Whenever we are working with Not Operator & if we are passing an expression to it, we must pass
that expression within parenthesis().

vi) Compound Assignment Operator:

*) Assignment Op: It is used to assign the value to the variable.

*) Compound Assignment Operator: (+= , -= , *= , /= , %=)

i) It is a Binary Operator.

ii) A compound Assignment op is a Combination of Arithmetic op

Along with Assignment Op.

iii) We use Compound assignment op whenever we need to update

a Variable by Performing Arithmetic Operator in the RHS.

vii) TypeCasting: The process of Converting one type of data into

another type is known as Typecasting .


In java we have following classification.

i) Primitive Typecasting-------( Widening and Narrowing)

ii) Non-Primitive Typecasting---( Upcasting and Downcasting)

i) Primitive TypeCasting: The Process of Converting One Primitive type

to Another Primitive type is known as Primitive typecasting.

In java we have 2 types of primitive Typecasting.

a.)Widening

b.)Narrowing

a.)Widening: The Process of Converting Smaller range datatype into

larger range datatype is known as widening.

*)In Widening there is no loss of data.

*)Hence the Compiler will do it implicitly(Internally).

*)It is Also refered as Autowidening.

b.) Narrowing: The Process of Converting Larger range datatype into

smaller range datatype is known as widening.

*)In Narrowing there is a loss of data.

*)Hence the Compiler will not do it implicitly, It has to be done

Explicitly by the Programmer, Using TypeCast Operator.

TypeCast Operator:

*) It is a Unary Operator.

*) It is Used to convert one type of data into another type of data.

*) Syntax: (Datatype to be Converted to)Value/exp/variable.

You might also like