[Go to site: main page, start]

0% found this document useful (0 votes)
2 views36 pages

Core Java - Module 1: Introduction To Java

The document is a syllabus for a Core Java module, outlining objectives such as understanding OOP concepts, data types, and Java program execution. It provides an introduction to Java, its applications, and the differences between JDK, JRE, and JVM. Additionally, it covers Java variables, data types, operators, and includes programming examples and assignments.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views36 pages

Core Java - Module 1: Introduction To Java

The document is a syllabus for a Core Java module, outlining objectives such as understanding OOP concepts, data types, and Java program execution. It provides an introduction to Java, its applications, and the differences between JDK, JRE, and JVM. Additionally, it covers Java variables, data types, operators, and includes programming examples and assignments.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AIIT

Core Java

Module-1

1
SYLLABUS AIIT

2
AIIT

3
AIIT

4
AIIT

5
AIIT

6
AIIT

7
AIIT

8
AIIT
Books & References

nlp-ai@[Link]
OBJECTIVES AIIT

After completing this section, you will be able to

▪ Understand the OOP concepts and difference in C++ and Java languages

▪ Understand data types, variables, operators and their use

▪ Differentiate among
- JDK,
- J𝑅𝐸 𝑎𝑛𝑑
- 𝐽𝑉𝑀

▪ Understand the steps for creating, compiling and executing a Java program

10
Introduction AIIT

• Java is a high-level programming language originally developed


by Sun Microsystems and released in 1995.
• Java runs on a variety of platforms, such as Windows, Mac OS,
and the various versions of UNIX.
• Java is a programming language and a platform.
• James Gosling is known as the father of Java.
• Before Java, its name was Oak.
• Since Oak was already a registered company, so James
Gosling and his team changed the Oak name to Java.

11
Platform? AIIT

Any hardware or software environment in which a program


runs, is known as a platform.

Since Java has a runtime environment (JRE) and API, it is


called a platform.

12
Java: Applications AIIT

According to Sun, 3 billion devices run Java.

Desktop Applications such as acrobat reader, media player, antivirus, etc.

Web Applications such as [Link] etc.

Enterprise Applications such as banking applications.

• Mobile
• Embedded System
• Smart Card
• Robotics
• Games, etc.

13
Why Java? AIIT

Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on the Object model.

Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not
compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web
and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.

Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.

Secure − With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based
on public-key encryption.

Architecture-neutral − Java compiler generates an architecture-neutral object file format, which makes the compiled code
executable on many processors, with the presence of Java runtime system.

Portable − Being architecture-neutral and having no implementation dependent aspects of the specification makes Java
portable. Compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.

Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and
runtime checking.

14
AIIT

Multithreaded − With Java's multithreaded feature it is possible to write programs that can
perform many tasks simultaneously. This design feature allows the developers to construct
interactive applications that can run smoothly.

Interpreted − Java byte code is translated on the fly to native machine instructions and is
not stored anywhere. The development process is more rapid and analytical since the
linking is an incremental and light-weight process.

High Performance − With the use of Just-In-Time compilers, Java enables high
performance.

Distributed − Java is designed for the distributed environment of the internet.

Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to


adapt to an evolving environment. Java programs can carry extensive amount of run-time
information that can be used to verify and resolve accesses to objects on run-time.

15
Java SE Vs. Java EE Vs. Java ME AIIT

Java SE

Java EE

Java ME

The latest release of the Java Standard Edition is Java SE


8.
16
Types of Java Applications AIIT

There are mainly 4 types of applications that can be created using Java programming:

1) Standalone Application- Standalone applications are also known as desktop applications


or window-based applications. These are traditional software that we need to install on every
machine. Examples of standalone application are Media player, antivirus, etc. AWT and
Swing are used in Java for creating standalone applications.

2) Web Application- An application that runs on the server side and creates a dynamic page
is called a web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc.
technologies are used for creating web applications in Java.

3) Enterprise Application- An application that is distributed in nature, such as banking


applications, etc. is called enterprise application. It has advantages of the high-level security,
load balancing, and clustering. In Java, EJB is used for creating enterprise applications.

4) Mobile Application- An application which is created for mobile devices is called a mobile
application. Currently, Android and Java ME are used for creating mobile applications.

17
Program 1: AIIT

public class MyFirstJavaProgram {

/* This is my first java program.


* This will print 'Hello World' as the output
*/

public static void main(String []args) {


[Link]("Hello World"); // prints Hello World
}
}
18
Steps to create a Java Program AIIT

For executing any java program:

S1: Install the JDK


S2: Set path of the jdk/bin directory.
S3: Create the java program Using Notepad editor or some other editor.
S4: Save this file as [Link]
S5: Compile and run the java program.

To compile: javac [Link]

java Simple
To execute:

Output: Hello World


19
AIIT

Difference among JDK, JRE, and JVM

20
JVM AIIT

• JVM (Java Virtual Machine) is an abstract machine.


• It is called a virtual machine because it doesn't physically exist.
• It is a specification that provides a runtime environment in which
Java bytecode can be executed.
• It can also run those programs which are written in other
languages and compiled to Java bytecode.
• JVMs are available for many hardware and software platforms.
JVM, JRE, and JDK are platform dependent because the
configuration of each OS is different from each other. However,
Java is platform independent. There are three notions of the
JVM: specification, implementation, and instance.
21
JRE AIIT

22
JDK AIIT

23
JDK AIIT

24
AIIT

Q) Can you save a java source file by other name than


the class name?
Yes, if the class is not public.

To compile: javac [Link]


To execute: java Simple
25
Can you have multiple classes AIIT

in a java source file?

Yes

26
Java Variables AIIT

A variable is a container which holds the value while the Java program is
executed. A variable is assigned with a data type.

Variable is a name of memory location.

There are three types of variables in java: local, instance and static.

There are two types of data types in Java: primitive and non-primitive.

1) Local Variable
A variable declared inside the body of the method is called local variable. You can
use this variable only within that method and the other methods in the class aren't
even aware that the variable exists.
A local variable cannot be defined with "static" keyword.

27
AIIT

2) Instance Variable
A variable declared inside the class but outside the body of the
method, is called instance variable. It is not declared as static.
It is called instance variable because its value is instance specific
and is not shared among instances.

3) Static variable
A variable which is declared as static is called static variable. It
cannot be local. You can create a single copy of static variable
and share among all the instances of the class. Memory allocation
for static variable happens only once when the class is loaded in
the memory.

28
Example: AIIT

class A{
int data=50;//instance variable
static int m=100;//static variable
void method(){
int n=90;//local variable
}
}//end of class
29
Data Types in Java AIIT

Data types specify the different sizes and values that


can be stored in the variable.
There are two types of data types in Java:
Primitive data types: The primitive data types include
boolean, char, byte, short, int, long, float and double.
Non-primitive data types: The non-primitive data types
include Classes, Interfaces, and Arrays.

Primitive Data Types- These are the most basic data


types available in Java language.
30
AIIT

Data Type Default Value Default size

boolean false 1 bit

char '\u0000' 2 byte

byte 0 1 byte

short 0 2 byte

int 0 4 byte

long 0L 8 byte

float 0.0f 4 byte

double 0.0d 8 byte

31
Operators in Java AIIT

Operator in Java is a symbol which is used to perform


operations. For example: +, -, *, / etc.

There are many types of operators in Java which are


given below:

32
AIIT

Operator Type Category Precedence


Unary postfix expr++ expr--
prefix ++expr --expr +expr -expr ~ !

Arithmetic multiplicative */%


additive +-
Shift shift << >> >>>
Relational comparison < > <= >= instanceof

equality == !=
Bitwise bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
Logical logical AND &&
logical OR ||
Ternary ternary ?:
Assignment assignment = += -= *= /= %= &= ^= |= <<=
>>= >>>=
33
ASET
Some Assignments ☺
1. Write a program which prints the following information
about at least 5 persons:
NAME MAIL-ID EMPLOYEE-CODE PHONE
Eg. Umesh umesh@cse p03161 25764728
Salil salil@cse p03160 25764728
Each entry should be on a separate line.

2. Write a program that prints the following line on the screen


along with quotes.
“Can we print ‘\’ with [Link]() statement?”

nlp-ai@[Link]
ASET
End

Thank you…

nlp-ai@[Link]
REFRENCES AIIT

1. Java : The Complete Reference , Patrick Naughton, Herbert Schildt

2. Thinking in Java ([Link] , Bruce Eckel


3. [Link]
4. [Link]

36

You might also like