Sunteți pe pagina 1din 21

JAVA

Java is a high-level programming language (User-friendly) 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.

APPLICATION OF JAVA

• Desktop Application(Media player, Anti Virus etc.,)


• Web Application (Flipkart, Facebook etc.,)
• Enterprise Applications (Colleges, Schools, Banking etc.,)
• Mobile Application (Paytm, Swiggy etc.,)
• Games.

Features of Java

• Simple
• Object-Oriented
• Portable
• Platform Independent
• Secured
• Robust
• High Performance
• Multithreaded
• Dynamic

Simple
Java is simple, it is easy to read and write.

Object-Oriented
Everything is an object in this world the same thing that applies to java programming.

Portable
Java is platform independent because it facilitates to carry the Java bytecode to any platform.

Platform Independent
Java is a platform independent because there are many platforms like Mac Os, Windows, and Linux.
Source Code cannot run in the different platform but when source code is converted into bytecode.
Bytecode can be run in a different platform. Simply we can say that the source code is platform
dependent and bytecode is platform independent.

Secured
Java is secured because there is no explicit pointer and java programs run in Virtual Machine. JVM
plays a role between the OS and Java Application.

Robust
• It uses strong memory management.
• Garbage collection is used to collect the unused objects.
• There is automatic garbage collection in java which runs on the Java Virtual Machine to get rid
of objects which are not being used by a Java application anymore.
High Performance

Java enabled High performance by introducing JIT- Just In Time compiler, JIT helps the
compiler to compile the code On demand basis i.e whichever method is called only that
method block will get compiled making compilation fast and time-efficient. This makes the
java delivering high performance.

How JIT Works?

• JIT - If we are calling one method for multiple times, one time that method is compiled and
multiple times reference are invoked.

Multi-threaded
The main purpose of multi-threading is to provide simultaneous execution of two or more parts of a
program to maximum utilize the CPU time.

Dynamic

Classes are loaded dynamically and automatic memory management (Garbage collection).

How to Install Java in Machine?

The Java Development Kit (JDK) is a software development environment used for developing Java
applications and applets.
• Use below link to download JDK/
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
• Based on your machine configuration download JDK.
• Install JDK-8u191-windows-x64.exe file.
• You will find a java folder where you installed your JDK on your machine.

• Copy this path C:\Program Files\Java\jdk1.8.0_181\bin


• Right click on My Computer and choose properties.
• Click on Advanced system settings.
• you will find a below screenshot
• Click on Environment variables. You will find a below screenshot.

• Give your variable name as path and variable name as C:\Program


Files\Java\jdk1.8.0_181\bin
• Click Ok.
• Now your Java is installed successfully on your system.
JDK–Java Development Kit(in short JDK) is Kit which provides the environment to develop and
execute(run)the Java program. JDK is a kit(or package) which includes two things.

• Development Tools(to provide an environment to develop your java programs)


• JRE (to execute your java program).Note :JDK is only used by Java Developer

JRE - Java Runtime Environment(to say JRE) is an installation package which provides environment
to only run(not develop) the java program(or application)onto your machine. JRE is only used by them
who only wants to run the Java Programs i.e. end users of your system.

JVM - Java Virtual machine(JVM) is a very important part of both JDK and JRE because it is
contained or inbuilt in both. Whatever Java program you run using JRE or JDK goes into JVM and
JVM is responsible for executing the java program line by line hence it is also known as interpreter.

Why we need Eclipse?


As of now, we ran the program in a command prompt. While running programs in command prompt its
very difficult to find compile time error and more features are not available in this so we are moving to
Eclipse.

Versions of Eclipse

Mars 24 June 4.5


2015
Neon 22 June 4.6
2016
Oxyge 28 June 4.7
n 2017
Photon 27 June 4.8
2018

Let's see the steps for installing eclipse Mars 2,

• Go to https://www.eclipse.org/downloads/packages/release/mars/2
• Download Mars 2 depends on your machine configuration.
• Extract this file eclipse-jee-mars-2-win32.
• Go to this folder structure eclipse-jee-mars-2-win32 → Eclipse → Launch Application.
• Choose a workspace where you want to save your projects.

• We have many features in eclipse and also we can create web application here.

Short Cut Keys in Eclipse

CTRL + D

To delete a row.

ALT + Up/Down Arrow

Moving the row up and down with the content.

ALT + Left/Right Arrow


This is to move one class to another class. We can use this shortcut for comparing one class file with
another.

CTRL+SHIFT+O

To Organize imports.

CTRL+SHIFT+T

This is very useful shortcut to find a class file in the workspace.

CTRL+E

Shows you a list of all open editors.

CTRL+F6

Use to move between open editors.

CTRL+F7

Move between views like package explorer, editor, task list, outline, problem, javadoc,
declaration,console,server.

CTRL+F8

Move between perspectives like Java EE, Debug, Java. The same as Ctrl+F7.

CTRL + F11

Runs the application.

CTL + N

To create a new class, JSP, XML, or something else as much as in faster way.

CTRL + M

Maximize or maximize your current tab.

CTRL + I

Corrects indentation.

CTRL + SHIFT + F

Formats code. You can make a beautiful looking code out of a mess with this.
CTRL + SHIFT + L

Shows you a list of your currently defined shortcut keys.

CTRL+SHIFT+G

Bind this to "Generate getters and setters." This is a "must have."

CTRL+SHIFT+/
To comment the lines.

CTRL+L
To find a line

CTRL + Q
To last edited place.

CTRL + F
To find the words.

RUN JAVA CORE IN COMMAND PROMPT WITHOUT PACKAGE:

• Open a new file in notepad.


• Type the java program Eg: Hellowjava program.
• Then save the file .
• The file name should be same as class name.
• Here we declare class name as Sample. So we can save the file name as Sample.java in the
directory D:.

• Open command prompt by Search → cmd.


There are two steps for run the java code in command prompt:
• Compile the program
• Run the program.
• First go to the directory. Then compile the java code by using javac space filename.java.
• For the above code the class file is stored in same location as source code saved.
• After compilation if there is any error . It will show the number of errors. if not then we have to run
the program.
• Run the java program in command prompt by java space filename.
• The output will display.
• Here our example code output is “HELLOW JAVA”.
RUN JAVA CORE IN COMMAND PROMPT WITH PACKAGE:

1.Select any directory, Here we select “D” drive.


2.We create a folder ”test”.

3.Create two folders inside the test folder. Those names are like “Classes” and “Src”.
• Create a new folder name like “com” in Src folder.

5)Create a “myclass” folder inside the com.


• Open a new file in notepad.
• Type the java program Eg: Hellowjava program.
• Here we can implement in package so should the package .
• Then save the file .
• The file name should be same as class name.
There are two steps for run the java code in command prompt:
• Compile the program
• Run the program.

• First go to the directory. Then compile the java code by using javac space filename.java.
• For the above code the class file is stored in same location as source code saved.
• After compilation if there is any error . It will show the number of errors. if not then we have to run
the program.
• Run the java program in command prompt by java space filename.
• The output will display.
• Here our example code output is “HELLOW JAVA”.

RUN THE JAVA PROGRAM IN ECLIPSE(INTEGRATED DEVELOPMENT ENVIRONMENT)

• Perform the java operations in ECLIPSE is more easier than command prompt.
• We can create java program only in class so we should follow some procedure below.
• To creating a new java program we can follow some steps.
• Open ECLIPSE tool , goto file menu click New.
• List of options are available. we select java project.
• Name the java project. Here we named as Hellow.
• Project name must start with captial letter or it should follow PASCAL.
• We can create n number of projects.
• Under each project we can create n number of packages.
• Every package may have number of clssses.
• Left side on desktop , under the package explorer the newly created project will display.

• Then right click on the project. select new-> package.

.
• The package name should be in small.
• Here we created a package names as "hello".
• Click finish option to create new package.

• Then create a class under specified package by right click on project , select class.
• Name the class. Here we named as "HelloWorld".
• Class name must start with captial letter or it should follow PASCAL.
• We have some basic options like modifiers , which method stubs would you like to create? etc..
• Choose any of those options based on requirement.
• Here we select main method option. so that it will create automatically.
• Click finish option to create new java class.
• Below slide show the new java class.

• Inside the main method, we write the required logic.


• Example: System.out.println("Hellow World")"; this is print statement . output will display on
console.

S-ar putea să vă placă și