01 Intro To Java Programming

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

INTENDED LEARNING
OUTCOME
INTRODUCTION TO  Recall the basic concepts of programming.

JAVA  Identify the all about of Java


Programming Language.
PROGRAMMING  Distinguish the different part of Java
Source File.
 Knows how to use the NeatBeans IDE to
create a java program.

WHAT IS WHAT IS
PROGRAMMING? PROGRAM?
 Programming is the act or job of  Program is a sequence of coded
creating computer programs (Merriam- instructions that can be inserted into a
Webster Dictionary) mechanism such as a computer (Merriam-
 Programming is the act or process Webster Dictionary)
of writing a program so that data may be
 Program is a specific set of ordered
processed by a computer (Collins
Dictionary) operations for a computer to perform.
 Programming is the implementation of
(WhatIs.com)
logic to facilitate specified computing  Program is a set of instructions that a
operations and functionality computer follows in order to perform a
(techopedia.com) particular task (Collins Dictionary)

June Arreb C. Danila 1


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

WHAT IS WHAT IS

SOURCE CODE? PROGRAMMING LANGUAGE?


 Source code is the original form of  Programming Language is the language in
a computer program before it which a programmer writes the instructions
is converted into a machine- that the computer will ultimately execute
readable code(Collins Dictionary) (britannica.com)
 Source code referred to as simply the
 Programming Language is a vocabulary
"source" of a program, contains variable
declarations, instructions, functions, loops, and set of grammatical rules for instructing
and other statements that tell the program a computer or computing device to perform
how to function (techterms.com) specific tasks (webopedia.com)
 Source code is the set of instructions and  Programming Language is a set of
statements written by a programmer using a commands, instructions, and
computer programming language other syntax use to create a
(techopedia.com) software program (techterms.com)

WHAT ARE THE WHAT IS


TYPES OF PROG. LANGUAGES? COMPILED LANGUAGE?
 Compiled Language  Compiled Language is one where the
 Interpreted Language program, once compiled, is expressed in
 Bytecode Language
the instructions of the target machine;
this machine code is undecipherable by
humans

Source Object
Machine
Code Code

Source: thesocietea.org Source: thesocietea.org

June Arreb C. Danila 2


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

WHAT IS WHAT IS
INTERPETED LANGUAGE? BYTECODE LANGUAGE?
 Interpreted Language is one where the  Bytecode Language is a type of
instructions are not directly executed by programming language that fall under the
the target machine, but instead read and categories of both compiled and
executed by some other program (which interpreted languages because they
normally is written in the language of the employ both compilation and
native machine) interpretation to execute code
Virtual
Source Intermediate Source Machine
Interpreter ByteCode
Code Code Code
(Interpreter)

Source: thesocietea.org Source: thesocietea.org

 Bytecode is a form of instruction set that


is designed to be efficiently executed by an
interpreter and is composed of compact
numeric codes, constants, and memory
references JAVA
 Example of Bytecode Language: JAVA
TECHNOLOGY

Source: thesocietea.org

June Arreb C. Danila 3


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

 Java is the single most widely used


THE JAVA TECHNOLOGY development language in the world today
 Java is the global standard for developing  Over 9 million Java developers
and delivering embedded and mobile  Over 7 Billion devices used Java
applications, games, web-based content,  Desktops
and enterprise software
 Mobile Phones
 Java enables you to efficiently develop,
 Appliances
deploy, and use exciting applications and
services  Cards
 From laptops to data centers, game
 Clouds
consoles to scientific supercomputers, cell  AI & Analytics
phones to the Internet, JAVA IS
EVERYWHERE!
Source: Oracle Academy Source: Oracle Academy

JAVA TECHNOLOGY PRODUCT JAVA TARGET DEVICE TYPE


 Java Platform
 Standard Edition (Java SE)
 Enterprise Edition (Java EE)
 Micro Edition (Java ME)
 Java Card

Source: Oracle Academy Source: Oracle Academy

June Arreb C. Danila 4


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

JAVA SE JAVA EE
 Isused to develop applications that run on  Isused to create large enterprise, server-
desktop computers side, and client-side distributed
applications

Source: Oracle Academy Source: Oracle Academy

JAVA ME JAVA CARD


 Is used to create applications for devices 5 billion Java Cards are in use
with limited storage, display, and power  It’s used to create applications that can
capacities. run securely on smart cards and similar
 Is used to develop applications for mobile small-memory devices
phones, PDAs, TV set-top boxes, smart  Java Card is typically used in the
cards, Raspberry Pi, and many more. following areas (and many more):
 Identity
 Security
 Transactions
 Mobile phone SIMs
Source: Oracle Academy Source: Oracle Academy

June Arreb C. Danila 5


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

 The Green Team,


JAVA: BRIEF HISTORY a team of highly
 In 1990, Sun Microsystems began a skilled software
research project to extend the power of developers at Sun
network computing to consumer devices, under the
such as video cassette recorders leadership of
(VCRs) and televisions James Gosling,
 The belief was that the next wave in developed Java
computing was the union of digital (originally called
consumer devices and computers Oak) as their
 There were also frustrations with the
solution.
use of the C/C++ language at Sun
Source: Oracle Academy Source: Oracle Academy

 Devices with different central processing  Fortunately, the World Wide Web was
units (CPUs) could be connected and becoming popular and the Green Team
share the same software enhancements recognized that the Oak language was
through a single programming language perfect for developing web multimedia
 This initial concept was ahead of its time, components to enhance web pages
as several deals with consumer device  Initially, the Oak language was used for
companies were unsuccessful small applications, called applets, and
 The Green Team was forced to find programmers using the Internet adopted
another market for their new what eventually became the Java
programming language. Programming language

Source: Oracle Academy Source: Oracle Academy

June Arreb C. Danila 6


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

 The turning point for Java came in 1995,  Duke is Java’s


when Netscape incorporated Java into its official mascot
browser
 The original Duke
 Oracle acquired Sun Microsystems in
was created by the
2010 Green Team’s
graphic artist, Joe
Palrang

Source: Oracle Academy Source: Oracle Academy

Java Version Released


JDK Alpha & Beta 1995
JDK 1.0 1996
JDK 1.1 1997
JDK 1.2 1998
JDK 1.4 2000
JDK 5 2004
JDK 6 2006
JDK 7 2011
JDK 8 (LTS) March, 2014
JDK 9 September, 2017
JDK 10 March, 2018
JDK 11 (LTS) September, 2018
Source: Oracle Academy

June Arreb C. Danila 7


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

PURPOSE OF A
COMPUTER PROGRAM
JAVA A computer program is a set of
instructions that run on a computer or
ENVIRONMENT other digital device
 At the machine level, the program consists of
(JVM, JRE, JDK, IDE) binary instructions (1s and 0s), called
Machine code
 Most programs are written in high-level
code (readable), must be translated to
machine code

Source: Oracle Academy

TRANSLATING HIGH-LEVEL LINKED TO PLATFORM-


CODE TO MACHINE CODE SPECIFIC LIBRARIES

Source: Oracle Academy Source: Oracle Academy

June Arreb C. Danila 8


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

PLATFORM-DEPENDENT JAVA IS
PROGRAMS PLATFORM-INDEPENDENT

Source: Oracle Academy Source: Oracle Academy

JAVA PROGRAMS RUN IN A JAVA RUNTIME ENVIRONMENT


JVM (JRE)
 JVM – Java Virtual Machine  Includes:

 The Java Virtual Machine


(JVM)
 Java class libraries
 Purpose:

 Read bytecode (.class)


 Run the same bytecode
anywhere with a JVM

Source: Oracle Academy Source: Oracle Academy

June Arreb C. Danila 9


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

JAVA DEVELOPMENT KIT INTEGRATED DEVELOPMENT


(JDK) ENVIRONMENT (IDE)
 Includes:  Purpose:

JRE –  Provide a sophisticated text editor


 Java Compiler  Offer assistance debugging code
 Additional tools  Manage projects
 Purpose:  Write source code (.java)
 Compile bytecode  Examples:
(.java .class)  NetBeans
 Greenfoot and BlueJ
 Alice
Source: Oracle Academy Source: Oracle Academy

COMPILING AND RUNNING A


JAVA PROGRAM

JAVA PROGRAM
BASIC STRUCTURE

Source: Oracle Academy

June Arreb C. Danila 10


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

 Any Java programs can contain any


THE JAVA SOURCE FILE number of classes
package com.javafiledemo  At most one class can be declared as

Package Statement public


class Class1{  If there is a public class, the name of the

} source file of the program and the name of


the public class must be match or the
class Class2{ Class(es) same
}  If there is no public class then we can
class ClassN{ use any name for java source file
}

Source: Java Deep Learning (Awwalsoft) Source: Java Deep Learning (Awwalsoft)

package com.javafiledemo package com.javafiledemo

public class Class1{ class Class1{


} }
class Class2{ class Class2{
} }
class ClassN{ class ClassN{
} }
 Program Filename: Class1.java  ProgramFilename: Class1.java,
Class2.java, ClassN.java, or
JunAr.java
Source: Java Deep Learning (Awwalsoft) Source: Java Deep Learning (Awwalsoft)

June Arreb C. Danila 11


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

package com.javafiledemo  Toimproves readability and


understandability of the code:
public class Class1{  Take only one class for source file and
} name of the program (file) must be same
as class name
Public class Class2{
}
Program Filename: Class1.java
class ClassN{
package com.javafiledemo
}
 Program Filename: Class2.java public class Class1{

}
Source: Java Deep Learning (Awwalsoft) Source: Java Deep Learning (Awwalsoft)

KEEP IN MIND: THE PACKAGE STATEMENT


Class Names  It is an encapsulation mechanism to group
 Should be in a Pascal Case format (First related classes and interfaces into a single
letter should be in Upper Case. If several module.
words are used to form a name, each inner  The main objectives of packages are:
word's first letter should be in Upper 1. To resolve name confects
Case.) 2. To improve modularity of the
 Example: application
 MyFirstJavaProgram 3. To provide security
 HelloWorld
 Rectangle
Source: Oracle Academy

June Arreb C. Danila 12


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

 Universally accepted naming conversion for


packages that is to use internet domain name THE MAIN() METHOD
in reverse:
 The class may contain a required main()
 Example:
method or not
com.icicibank.loan.housingloan.Account  But the required main() method is the
method find by the JVM when running the
program
Client Module Sub module Class  The compiler is not responsible for
internet name name name checking the required main() methods
domain  At the runtime, JVM is the responsible for
name in checking the required main() methods
reverse
Source: Java Deep Learning (Awwalsoft) Source: Java Deep Learning (Awwalsoft)

 If JVM unable to find the required main() Acceptable changes to main() method
method the program will get a runtime syntax:
exception NoSuchMethodError: main 1. The order of modifiers (public, static) can be
 The required main() method has the change
following prototype: 2. Can declare string[] in any acceptable form:
String[] args, String []args, or String args[]
To call by JVM W/o existing object JVM
anywhere has to call this method 3. Can use any valid java identifier instead of args
4. Can replace string[] with var-arg parameter.
public static void main(String[] args) Ex: main(String… args)
5. main() method can be add the following
The main() method won’t Command line modifiers: final, synchronized, strictfp
return anything to JVM arguments

Source: Java Deep Learning (Awwalsoft) Source: Java Deep Learning (Awwalsoft)

June Arreb C. Danila 13


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

Tell valid or invalid main() methods


Tell valid or invalid main() methods
1. public static void main(String args){ } //invalid
1. public static void main(String args){ }
2. public [static] syncronized final strictfp void
2. public syncronized final strictfp void main(String[] args){ } //invalid, no static
main(String[] args){ } 3. public static void Main(String… args){ } //invalid
3. public static void main(String… args){ } 4. public static int main(String[] args){ } //invalid
4. public static int main(String[] args){ } 5. public static syncronized final strictfp void
5. public static syncronized final strictfp void main(String… args){ } //valid
main(String… args){ } 6. public static void main(String… args){ } //valid
6. public static void main(String… args){ } 7. public [static] void main(String args[]){ } //invalid,
7. public void main(String args[]){ } 8. static public void main(String[] args){ } //valid
8. static public void main(String[] args){ } 9. public static syncronized void main(String[] a){ }
//valid
9. public static syncronized void main(String[] a){ }
10. static public final [void] main(String []june){ }
10. static public final main(String []june){ } //invalid

Documentation comment

JAVA COMMENTS
 Single-line comment
 Starts with //
 Multiline comment
 Begins with /* and ends with */
 Documentation comment Single-line comment
 This type of comment is used to produce an
HTML file that documents your program
 Begins with a /** and ends with a */
Multiline comment

June Arreb C. Danila 14


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

CREATING NEW JAVA


APPLICATION PROGRAM
 Open the NetBeans IDE
USING NETBEANS  Click the New Project icon

IDE (BASICS)

1 – Enter your Project Name


1 - Click the Java folder

2 - Click the Java 2 – Browse for folder you want to


Application save the project

3 - Click the Next button 3 – Click the Finish button

June Arreb C. Danila 15


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

Click this to
TRY THIS: hide the
documentation

You can delete this

Program
Documentation

Package name
Source Code Filename
Class name

main() Method

Class name

June Arreb C. Danila 16


BIT212k - Object-oriented Programming 1 College of Computer Studies, University of Nueva Caceres

RUNNING THE PROGRAM


Program with Syntax Error
Click the Run Project
button or press the F6 key A Red line will appear if there’s an
syntax error in the statement.
 Mouse-over the statement with red line to
display the error hints tooltip
Error Hints

Output Window

June Arreb C. Danila 17

You might also like