0% found this document useful (0 votes)
14 views4 pages

Java Programming Basics and History

Uploaded by

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

Java Programming Basics and History

Uploaded by

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

IT112 COMPUTER PROGRAMMING 1

FIRST SEM_FIRST TERM BSIT 1A

Module I: Lesson 2 History of Java and Elements of a  JDK is a software development environment used
Java Program for making applets and Java applications. The full
form of JDK is Java Development Kit. Java
HISTORY OF JAVA developers can use it on Windows, macOS, Solaris,
and Linux. JDK helps them to code and run Java
 Java was created in 1991 by James Gosling,
programs. It is possible to install more than one JDK
[Link] of Sun Microsystems. Initially called Oak,
version on the same computer.
in honor of the tree outside Gosling's window, its
name was changed to Java because there was Why use JDK?
already a language called Oak.
 The original motivation for Java is the need for Here are the main reasons for using JDK:
platform- independent language that could be
embedded in various consumer electronic  JDK contains tools required to write Java programs
products like toasters and refrigerators. and JRE to execute them.
 One of the first projects developed using Java was  It includes a compiler, Java application launcher,
a personal hand-held remote control named Star Appletviewer, etc. Compiler converts code written
7. At about the same time, the World Wide Web in Java into byte code.
and the Internet were gaining popularity. Gosling  Java application launcher opens a JRE, loads the
et. al. realized that Java could be used for Internet necessary class, and executes its main method.
programming.
Java Virtual Machine (JVM):
 While Java is viewed as a programming language to
design applications for the Internet, it is, in reality,  Java Virtual Machine (JVM) is an engine that
a general all-purpose language that can be used provides a runtime environment to drive the Java
independently of the Internet. Code or applications. It converts Java bytecode into
machine language. JVM is a part of the Java Run
Uses of Java
Environment (JRE). In other programming
Here are some important Java applications: languages, the compiler produces machine code
for a particular system. However, the Java compiler
 It is used for developing Android Apps produces code for a Virtual Machine known as Java
 Helps you to create Enterprise Software Virtual Machine.
 Wide range of Mobile java Applications
 Scientific Computing Applications Why JVM?
 Use for Big Data Analytics
Here are the important reasons of using JVM:
 Java Programming of Hardware devices
 Used for Server-Side Technologies like Apache,  JVM provides a platform-independent way of
JBoss, GlassFish, etc. executing Java source code. It has numerous
libraries, tools, and frameworks.
Java Versions and Release Dates
 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.

Components Of Java Programming Language Why use JRE?

 A Java Programmer writes a program in a human- Here are the main reasons of using JRE:
readable language called source code. Therefore,
the CPU or chips never understand the source code  JRE contains class libraries, JVM, and other
written in any programming language. supporting files. It does not include any tool for
 These computers or chips understand only one Java development like a debugger, compiler, etc.
thing, which is called machine language or code.  It uses important package classes like math, swing,
These machine codes run at the CPU level. util, lang, awt, and runtime libraries.
Therefore, it would be different machine codes for  If you have to run Java applets, then JRE must be
other models of CPU. installed in your system.
 However, you need to worry about the machine Different Types of Java Platforms
code, as programming is all about the source code.
The machine understands this source code and There are four different types of Java programing
translates them into machine understandable code, language platforms:
which is an executable code.
1. Java Platform, Standard Edition (Java SE):
All these functionalities happen inside the following  Java SE's API offers the Java programming
3 Java platform components: language's core functionality. It defines all
the basis of types and objects to high-level
1. Java Development Kit (JDK) classes. It is used for networking, security,
2. Java Virtual Machine (JVM) database access, graphical user
3. Java Runtime Environment (JRE) interface (GUI) development, and XML
Java Development Kit (JDK) parsing.
2. Java Platform, Enterprise Edition (Java
EE):
IT112 COMPUTER PROGRAMMING 1
FIRST SEM_FIRST TERM BSIT 1A

 The Java EE platform offers an API and o All class names must start with a
runtime environment for developing and capital letter
running highly scalable, large-scale, multi-  {}
tiered, reliable, and secure network o Two curly brackets {...} are used to
applications. group all the commands, so it is known
3. Java Programming Language Platform, that the commands belong to that
Micro Edition (Java ME): class or method. We call it code block.
 The Java ME platform offers an API and a  /*This is a comment.*/
small-footprint virtual machine running o The compiler ignores the comment
Java programming language applications block. Comment can be used anywhere
on small devices, like mobile phones. in the program to add info about the
4. Java FX: program or code block, which will be
 JavaFX is a platform for developing rich internet helpful for developers to understand
applications using a lightweight user-interface API. the existing code in the future easily.
It user hardware-accelerated graphics and media o This is a C-Style comment or a
engines that help Java take advantage of higher- multiline comment.
performance clients and a modern look-and-feel  Public static void
and high-level APIs for connecting to networked o When the main method is declared
data sources. public, it means that it can also be
used by code outside of its class, due
PHASES OF A JAVA PROGRAM
to which the main method is declared
public.
o The word static is used when we want
to access a method without creating its
object, as we call the main method,
before creating any class objects.
o The word void indicates that a method
does not return a value. main() is
declared as void because it does not
return a value.
JAVA PROGRAM STRUCTURE  main()
o main is a method; this is a starting
It is necessary to know the exact structure of the Java point of a Java program.
program, and this lesson contains a detailed o You will notice that the main method
description of it. This lesson is essential for you before code has been moved to some spaces
proceeding to learn more advanced lessons of Java left. It is called indentation which is
programming. Here, in this chapter, you will study the used to make a program easier to read
structure of the Java program. Such as how to create a and understand.
simple Java program and what its different sections  //This is a comment.
mean. Java program structure means - the way to write o This is another comment and does not
a java program or general format. affect the flow of the program.
o C++ Style comments start with //
Basic Structure of Java Programs and all the text after
o // are treated as comments.
A Java program involves the following sections:
 String[] args
 Package Statement o It is an array where each element of it
 Import Statements is a string, which has been named as
 Class Definition "args". If your Java program is run
 Main Method Class through the console, you can pass the
input parameter, and main() method
Main Method Definition takes it as input.
 [Link] ("Hello Java");
o Statements contain one or more
lines of code terminated by a
semicolon.
o This statement is used to print text on
the screen as output, where the system
is a predefined class, and out is an
object of the PrintWriter class defined
in the system. The method println
prints the text on the screen with a
new line. You can also use the print()
method instead of println() method.
All Java statement ends with a
semicolon.

Java Identifiers
You have to keep in mind that, Java code is case
sensitive. To write a Java program, you must have to Java identifiers are tokens that represent names of
define class first. The name of the class in Java (which variables, methods, classes, etc. These are case-
holds the main method) is the name of the Java sensitive which means that the identifier Hello is not
program, and the same name will be given in the the same as hello.
filename. As mentioned above in the sample program;
The name of the class is "Hello" which the main Identifiers must begin with either a letter, an
method is, then this file will be named "[Link]". underscore "_", or a dollar sign "$". Letters may be
lower or upper case. Subsequent characters may use
 Public class Hello numbers O to 9.
o This creates a class called Hello.
IT112 COMPUTER PROGRAMMING 1
FIRST SEM_FIRST TERM BSIT 1A

Identifiers cannot use Java keywords like class, meaning like a class in Java, are highlighted with
public, void, etc. We will discuss more Java keywords different colors.
later.
The biggest benefit to using an IDE is that it allows
Examples: Hello, main, System, out you to code and run Java programs on your own
computer.
Java Keywords
Creating Your First Project in Netbeans IDE
 Java keywords are also known as reserved words.
Keywords are particular words that act as a key to 1. Let us start with the creation of the first
a code. These are predefined words by Java so they project. To start with the first project, either navigate
cannot be used as a variable or object name or to File -> New Project or simply press the New Project
class name. button as described above. It should open up a small
window as shown below.
List of Java Reserved Keywords

2. Select Java application in the right-side panel


Java Escape Characters and click Next.

A character preceded by a backslash (\) is an escape The next step asks for the selection of project name,
sequence and has a special meaning to the compiler. location, and folder. Select the necessary details and
click next. The below image shows these details filled
The following table shows the Java escape sequences. in.

Let us take a look at this example:

The output of the program is:

Netbeans IDE

Netbeans IDE started as a student project known as


Xelfi in the past, is a popular IDE developed with the
goal to create a Delphi-like IDE for Java. First developed
in 1996, it has grown into a full-fledged IDE for
Enterprise scaled software development. With its With on click of Finish, you should be able to see that
excellent integrated abilities like the connection your main class is automatically created. The project
manager, integrated Glassfish server, and resource shows up in the Projects window and the MainClass
managers, Netbeans IDE makes development quite shows up in the editor. A snapshot of how it appears is
easy for novice developers. This article has been shown below.
created with the goal to guide every developer on how
to make the most out of Netbeans IDE and its features.

An integrated development environment (IDE) is


software for building applications that combines
common developer tools into a single graphical user
interface (GUI).

IDEs increase programmer productivity by combining


common activities of writing software into a single
application: editing source code, building
executables, and debugging.

An IDE that knows the syntax of your language can


provide visual cues. Keywords, words that have special
3. Build the project.
IT112 COMPUTER PROGRAMMING 1
FIRST SEM_FIRST TERM BSIT 1A

Once the code is ready, the next step is to build and


execute the project. In the top bar, you would be able
to see two buttons to build the project. The buttons are
Build and Clean & Build respectively. To explain the
purpose of both the buttons, one needs to have a basic
understanding of what happens when a project is built.

Build: F11

Clean & Build: Shift+F11

You might also like