0% found this document useful (0 votes)
24 views13 pages

Java

Uploaded by

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

Java

Uploaded by

Pramodh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

What is Java?

• Java is a general-purpose, class-based, object-oriented programming


language designed for having lesser implementation dependencies.
• It is a computing platform for application development.
• Java is fast, secure, and reliable, therefore.
• It is widely used for developing Java applications in laptops, data
centers, game consoles, scientific supercomputers, cell phones, etc.
Java used for?
 It is used for developing Android Apps
 Helps you to create Enterprise Software
 Wide range of Mobile java Applications
 Scientific Computing Applications
 Use for Big Data Analytics
 Java Programming of Hardware devices
 Used for Server-Side Technologies like Apache, JBoss, GlassFish, etc.
Java Features
 It is one of the easy-to-use programming languages to learn.
 Write code once and run it on almost any computing platform.
 Java is platform-independent. Some programs developed in one machine can
be executed in another machine.
 It is designed for building object-oriented applications.
 It is a multithreaded language with automatic memory management.
 It is created for the distributed environment of the Internet.
 Facilitates distributed computing as its network-centric.
Components Of Java Programming
Language
 A Java Programmer writes a program in a human-readable language called
Source Code. Therefore, the CPU or Chips never understand the source code
written in any programming language.
 These computers or chips understand only one thing, which is called machine
language or code. These machine codes run at the CPU level. Therefore, it
would be different machine codes for other models of CPU.
 . The machine understands this source code and translates them into machine
understandable code, which is an executable code.
 All these functionalities happen inside the following 3 Java platform
components:
Java Development kit (JDK)
 JDK is a software development environment used for making applets and Java
applications.
 The full form of JDK is Java Development Kit. Java developers can use it on
Windows, macOS, Solaris, and Linux.
 JDK helps them to code and run Java programs. It is possible to install more
than one JDK version on the same computer.
Why use JDK?
 Here are the main reasons for using JDK:
 JDK contains tools required to write Java programs and JRE to execute them.
 It includes a compiler, Java application launcher, Appletviewer, etc.
 Compiler converts code written in Java into byte code.
 Java application launcher opens a JRE, loads the necessary class, and
executes its main method.
Java Virtual Machine (JVM):
 Java Virtual Machine (JVM) is an engine that provides a runtime environment to drive
the Java Code or applications.
 It converts Java bytecode into machine language. JVM is a part of the Java Run
Environment (JRE).
 In other programming languages, the compiler produces machine code for a
particular system.
 However, the Java compiler produces code for a Virtual Machine known as Java Virtual
Machine.
 Why JVM?
 Here are the important reasons of using JVM:
 JVM provides a platform-independent way of executing Java source code.
 It has numerous libraries, tools, and frameworks.
 Once you run a Java program, you can run on any platform and save lots of time.
 JVM comes with JIT (Just-in-Time) compiler that converts Java source code into low-
level machine language. Hence, it runs faster than a regular application.
Java Runtime Environment (JRE)
 JRE is a piece of software that is designed to run other software. It contains
the class libraries, loader class, and JVM.
 In simple terms, if you want to run a Java program, you need JRE. If you are
not a programmer, you don’t need to install JDK, but just JRE to run Java
programs.
Why use JRE?
 Here are the main reasons of using JRE:
 JRE contains class libraries, JVM, and other supporting files. It does not
include any tool for Java development like a debugger, compiler, etc.
 It uses important package classes like math, swing, util, lang, awt, and
runtime libraries.
 If you have to run Java applets, then JRE must be installed in your system.
Simple Java Program:
 class Simple{
 public static void main(String args[]){
 System.out.println("Hello Java");
 }
 }
Parameters used in First Java Program
 class keyword is used to declare a class in Java.
 public keyword is an access modifier that represents visibility. It means it is visible
to all.
 static is a keyword. If we declare any method as static, it is known as the static
method. The core advantage of the static method is that there is no need to create
an object to invoke the static method. The main() method is executed by the JVM,
so it doesn't require creating an object to invoke the main() method. So, it saves
memory.
 void is the return type of the method. It means it doesn't return any value.
 main represents the starting point of the program.
 String[] args or String args[] is used for command line argument. We will discuss it
in coming section.
 System.out.println() is used to print statement. Here, System is a class, out is an
object of the PrintStream class, println() is a method of the PrintStream class. We
will discuss the internal working of System.out.println() statement in the coming
section.
Java Variables
 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.

Variable
 A variable is the name of a reserved area allocated in memory. In other
words, it is a name of the memory location. It is a combination of "vary +
able" which means its value can be changed.

int data=50;//Here data is variable


Types of Variables
 There are three types of variables in Java:
 local variable
 instance variable
 static variable
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.
2) Instance Variable
 A variable declared inside the class but outside the body of the method, is
called an instance variable. It is not declared as static.
 It is called an instance variable because its value is instance-specific and is
not shared among instances.
3) Static variable
 A variable that is declared as static is called a static variable. It cannot be
local. You can create a single copy of the static variable and share it among
all the instances of the class. Memory allocation for static variables happens
only once when the class is loaded in the memory.
example

 public class Simple{


 public static void main(String[] args){
 int a=10;
 int b=10;
 int c=a+b;
 System.out.println(c);
 }
 }

You might also like