0% found this document useful (0 votes)
9 views5 pages

Introduction to Java Programming

Uploaded by

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

Introduction to Java Programming

Uploaded by

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

introduction of java:

program-set of instruction
coading-cummunicate
java is a high level language with support oops .java is case sensitive.

3 types of programming language:


low level programming language
mechine level programming language
high level proramming language-c++,java,python,.net

history:
popular programming language
gree team

james goslimg
mike sheritan
patrick naughton

founder:james gosling
year:1991-implement
publish:1995

1990-sun micro system decided for aspecial software consumer eletronic devices
1991-named as language as oak
1992-deal with touch sensitive screens
1993-support with web application
1994-web browser
1995-oak renamed as java
1996-java establised as-leader of internet programming
-general purpose programming language

application:
desktop application
mobile application
web application
web server and application servers
games
database connections
banking applicatins

features of java:

simple
compiled and interpreted
portable
object oriented
secure
high performance
dynamic

platform dependent:-
Any application which are developed in one platform able to run a similar platform
only such application is called as platform dependent.
MAC--os update---x
WIN32--HLPL--COMPILER--LLPL--WIN 32--os ----
LINUX--system based
operating system--x

platform independent

Any application which are developed in one platform capale of running different
multiple platform are known as platform independent application

MAC--os update
WIN32--HLPL--COMPILER--LLPL--WIN 32--os
LINUX--system based
operating system

how java is platform independent:-

Any application which are developed using java language are platform indepent
application because they undergo 2 stage of convertion
in 1 st stage the compiler will convert source file into class file (or)compiler
will convert java language to byte code.
in 2 nd stage the jvm converts byte code into binary and excutes this program
hence java application can be used as any platform with the help of jvm.

note:java is platform independent language for depends on jvm

step to create an excute java program

[Link] source file


[Link] class file
[Link] of program

JDK
JRE JVM

it is java development kit java runtime envirnment


java virtual machine

it provides tools for devloping it provides neccessary tools


converts byte code into binary code and excutes the
and excuting java program required excute the program
program
2

[Link]();
it is used to print whatever the data given and move the cursor to initial postion
to next line.

[Link]();
it is used to print whatever the data given and move the cursor to immediate next
position in the same line

java first program:

public class programname


{
public static void main(string args[])
{
[Link]("cadpoint");
}
}

comment:
single line comment-\\
multi line comment-\* *\

tokens:-
The smallest elements of any programs is called as tokens.
In java we have following tokens:-
1)keyword
2)identifier
3)literal
4)separated

keywords:-predefined words ex:-public static void


50 keywords
int,float,char,double,break,case,static,strig,public,.......
reserved words
note:-keyword must be return in lower case

identifier:-
the name given to the members of java is known as identifier
ex:-name given to class ,method and variables.
rules:-

idendifier should not start with numeric value


ex:-123demo//cte
demo123//cts
special charcters are not allowed other than _and $
ex:-@demo//cte
$_demo//cts
space b/w the charcters are not allowed
ex:-My home//cte
MyHome//cts
keywords cannot be used as identifier

literals:-
the data are the user input
in java we have following literals
[Link]
[Link]
[Link]
[Link]

number:-In java numeric values can be used directly


ex:-[Link](10);//10
[Link](10.5);//10.5
character:-
In java characters are represented using single code
*'a'to'z'
*'0'to'9'
*'A'to 'Z'
*special characters
ex:-
[Link]('a');//a
[Link]('4');//4
[Link]('$');//$

note:- Any Character are data that we passed inside single code is considered as
character but the length of the character must be 1 else we get compile time error

whenever we pass character 1 unique code will be considered to be stored the data
in the memory known as ASCII(American Standard Code for Information Interchange)
'A'==>65 'Z'==>90
'a'==>97 'z'==>122
'0'==>48 '9'==>57

string:-
string is the group of character
string are represented using double quotes
ex:-[Link]("cad point);//cadpoint

boolean:-
in java boolean literls are also keywords
they are:
true
false
we can passed directly
ex:-
[Link](true);//true
[Link](false);//false

Separators:-
separators are used to separate one instruction from another instruction
ex:-()," ",;,{}
note:-in java every instruction must end with block (or)semicolan

Type casting:-
converting one data type into another data type is known as typecasting
in java we have classified into two types
*primitive typecasting
*non primitive typecasting
primitivetypecasting:-
converting one primitive datatype into another primitive datatype is known as
primitive typecasting.
primitive type casting consist of two process
widening
narrowing
widening process:-
the process of converting smaller range data type into larger data type is known as
widening process.
There is no loss in Widening process it will be done compiler implecitly .
Hence it is also called as auto widening .
Narrowing process:-
The process of conveting larger range data type into smaller range data type is
known as Narrowing process.
There might be data loss in narrowing compiler will not do it implicitly so
programer asked to explicitly by using type caste operator .

Type Caste Operator:-


It is a unary operator
It is used to convert higher range data type into smaller range data type.
Syntax:-
datatype Identifier =(LHS Data type) value/Expression .

Example :-
int a=(int)10.5;
int b=(int)10L;
1 2 4 8 4 8
byte -> short ->int->long->float->double

Operator :-
` A pre define symbol used for particular task is known as Operator .Input or
data that we passed to an Operator are known as operands.
[Link] Operator.(Binary)(+,-,*,/,%)
[Link] Operator.(Binary)
[Link] Operator.
[Link] Operator.(Ternary Operator)
[Link] Operator.
[Link] Operator.(Increment,Decrement).
[Link] Operator.

Conditional Operator.(Ternary Operator)


public class Main
{
public static void main(String [] args)
{
int mark=35;

[Link]((mark>=35)?"pass":"fail");
}
}

Assignment Operator.
public class Main
{
public static void main(String [] args)
{
int a=10;
a+=10;
[Link](a);
a-=5;
[Link](a);
a*=2;
[Link](a);
a/=3;
[Link](a);
}

Common questions

Powered by AI

The Java Development Kit (JDK) provides the necessary tools for developing Java applications, including compilers and debuggers. The Java Runtime Environment (JRE), in contrast, provides the libraries and JVM necessary to execute Java programs. While the JDK is required for writing and compiling Java code, the JRE is essential primarily for running applications .

Arithmetic operators in Java perform binary operations, as they require two operands to operate on, such as addition, subtraction, multiplication, division, and modulus (e.g., +, -, *, /, %). This binary nature implies that each operation can be performed between two numeric data types, affecting how calculations and data manipulations are structured and handled within algorithms .

The ternary operator in Java is used as a shorthand for an if-else statement, which allows for simpler syntax when performing conditional assignments. It is particularly advantageous in scenarios requiring conditional value assignment in a single line, improving code readability and efficiency. For example, checking if a score meets a passing threshold and assigning 'pass' or 'fail' can be accomplished in one line, reducing the need for multiple lines of if-else blocks .

'System.out.println()' is used in Java to print text to the console followed by a newline, which means the cursor moves to the next line after printing. In contrast, 'System.out.print()' displays text but keeps the cursor on the same line, allowing subsequent text to appear immediately after the printed content, facilitating more controlled layout management in console outputs .

Primitive typecasting in Java involves converting one primitive data type into another, like int to float. It includes widening (automatic conversion from a smaller to a larger type) and narrowing conversions (manual conversion from a larger to a smaller type), where data loss might occur because the compiler does not handle it implicitly . Non-primitive typecasting, on the other hand, involves casting object references, which is typically realized using inheritance or interface implementations, affecting a program's object hierarchy and polymorphic behavior.

Java achieves platform independence through the use of the Java Virtual Machine (JVM), which converts compiled bytecode (from Java source code) into machine code that can run on any operating system that has the appropriate JVM implementation. This allows Java applications to be executed on multiple platforms without requiring modification to the source code, providing ease of deployment and development across diverse environments .

Widening type casting in Java automatically converts a smaller primitive type (like byte) to a larger data type (like int), with no data loss, as handled by the compiler. An example is converting an int to a double. Narrowing type casting requires manual conversion of a larger type to a smaller type using a type cast operator, which could result in data loss, such as converting a double to an int, thus truncating the decimal part .

Keywords in Java are predefined, reserved words with specific meanings that the Java compiler understands as instructions. They cannot be used for naming identifiers because this would cause syntactic conflicts. The correct usage of keywords ensures the structural integrity of programs, facilitating clear instruction interpretation by the compiler and thereby preventing errors or ambiguities .

Identifiers in Java are names given to classes, methods, variables, etc., to label them uniquely within a program. Java identifiers cannot start with a digit and can only contain alphanumeric characters, underscores (_), and dollar signs ($). Keywords cannot be used as identifiers, and spaces are not allowed within them, ensuring code clarity and consistency .

Java began as a project by Sun Microsystems in 1990 to create software for consumer electronic devices. By 1991, it was named Oak and aimed at dealing with touch-sensitive screens. In 1993, it started supporting web applications, leading to the development of a web browser by 1994. By 1995, Oak was renamed Java, and its capability to operate across platforms without modification—thanks to the JVM—made it a strong candidate for internet programming, ultimately establishing it as a leader in that field by 1996 .

You might also like