0% found this document useful (0 votes)
19 views49 pages

CpEProg 1-Module 2a

This document covers the fundamentals of Java programming, including topics such as coding conventions, data types, and the use of the NetBeans IDE. It provides an overview of Java's characteristics, the Java Development Kit (JDK), and the process of programming. Additionally, it explains the syntax, structure, and input/output methods in Java, along with examples and exercises for better understanding.

Uploaded by

EDZ Channel
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)
19 views49 pages

CpEProg 1-Module 2a

This document covers the fundamentals of Java programming, including topics such as coding conventions, data types, and the use of the NetBeans IDE. It provides an overview of Java's characteristics, the Java Development Kit (JDK), and the process of programming. Additionally, it explains the syntax, structure, and input/output methods in Java, along with examples and exercises for better understanding.

Uploaded by

EDZ Channel
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
You are on page 1/ 49

PROGRAMMING

LANGUAGE FUNDAMENTALS
Java Programming
CPEPROG – MODULE 2A
TOPICS:

 Java Programming with Netbeans IDE


 Coding Conventions and Data Types
 Java Output and Input
 Java Operators
 Math Functions
 Control and Iterative Statement
 Characters and String
 Arrays
 Attributes, Methods and Constructions
FUNDAMENTAL CONCEPTS
Programming Terminologies

 PROGRAM
 Set of written instruction
 MACHINE LANGUAGE
 Most basic circuitry-level language
 HIGH-LEVEL PROGRAMMING LANGUAGE
 syntax are close to human language
 INTEGRATED DEVELOPMENT ENVIRONMENT (IDE)
 Software application that facilitates software development
FUNDAMENTAL CONCEPTS
Programming Terminologies

 SYNTAX
 Rules of language / Arrangement
 COMPILER OR INTERPRETER
 Translate language statements into machine code
 DEBUGGING
 Process of identifying and removing Errors
 Syntax Error and Logic Errors
JAVA PROGRAMMING

Java Programming
 isa computer programming language that allows
programmers to write computer instructions using English
based commands

 It’s known as a “high-level” language


JAVA PROGRAMMING

Java Programming
 Developed in early 1990s by James Gosling et. al. as the
programming language component of the Green Project
at Sun Microsystems ·
 launched in 1995 as a “programming language for the
Internet”; quickly gained popularity with the success of the
World Wide Web
JAVA PROGRAMMING

Characteristics
Simple: derived from C/C++, but easier to learn
Secure: built-in support for compile-time and run-
time security
Distributed: built to run over networks
Object-oriented: built with OO features
JAVA PROGRAMMING

Characteristics
Robust: featured memory management,
exception handling, etc.
Portable: “write once, run anywhere''
JAVA PROGRAMMING

JAVA DEVELOPMENT KIT(JDK)


is a software development environment used for
developing Java applications and applets.

- Java Runtime Environment (JRE) - Archiver (jar)


- Java Virtual Machine (JVM) - Compiler (javac)
- Document generator (Javadoc) - Java Development tools
JAVA PROGRAMMING

 JAVA DEVELOPMENT KIT(JDK)


 Examples of Java API Class Library Packages
java.lang : basic language functionality
java.io : input and output capabilities
java.util : utility classes, collection classes
java.net : network access
java.sql : database access
java.awt, javax.swing : graphical user interfaces
JAVA PROGRAMMING

Process of Programming
JAVA PROGRAMMING
Process of Programming
 Create

 Compile

 Run (or execute)


JAVA PROGRAMMING

 JAVA INTEGRATED DEVELOPMENT ENVIRONMENT


(java IDE)
JAVA PROGRAMMING WITH NETBEANS

NETBEANS
- an integrated development
environment for Java
- allows applications to be
developed from a set of modular
software components called
modules
JAVA PROGRAMMING WITH NETBEANS

NEW PROJECT (ctrl + shift + n)

1. Select Project Type 2. Set project name and drive location


JAVA PROGRAMMING WITH NETBEANS

NEW SOURCE FILE (ctrl + n)

1. Select file Type 2. Set file name and project


JAVA PROGRAMMING CONTROL AREA

REFERENCE AREA WORKING AREA

STATUS AREA
JAVA PROGRAMMING
CODING CONVENTION AND DATA TYPES

 Java programs are made up of one or more classes.

Byconvention, Java class names start with an


uppercase letter. Java programs are case-sensitive.

 A Java source code file usually contains one class


declaration, but two or more classes can be declared in
one source code file. The file is named after the class it
declares, and uses a .java filename extension.
CODING CONVENTION AND DATA TYPES

For a class to be executable, it must be declared public,


and must provide a public static method called main,
with an array argument of type String.

 If a file contains more than one class declaration, only


one of the classes can be declared public, and the file
must be named after the sole public class.
CODING CONVENTION AND DATA TYPES

Main rules regarding the usage of semicolon ( ; )

1. Statement Terminator: The semicolon is used to terminate


statements. Each statement in Java must end with a semicolon,
which tells the compiler that the statement is complete.
CODING CONVENTION AND DATA TYPES

Main rules regarding the usage of semicolon ( ; )

2. Multiple Statements: You can write multiple statements on a


single line, separating them with semicolons:
CODING CONVENTION AND DATA TYPES

Main rules regarding the usage of semicolon ( ; )

3. Control Structures: Do not use a semicolon after control


structure declarations like if, for, while, etc., unless it’s part of the
statement body.
CODING CONVENTION AND DATA TYPES

ELEMENTS
 Identifiers
 Data Types
 Main() method
 Comments
CODING CONVENTION AND DATA TYPES

IDENTIFIERS
• Are names given to a variable, class, or method
• Can start with a letter, underscore(_), or dollar sign($)
• Are case sensitive and have no maximum length

Examples:
 Identifier, username, user_name, _sys_var1 ,$change
CODING CONVENTION AND DATA TYPES

IDENTIFIERS
• Must not used a reserved word
CODING CONVENTION AND DATA TYPES

Class Names - For all class names the


first letter should be in Upper Case.

If several words are used to form a name of


the class, each inner word's first letter should
be in Upper Case.

Example class MyFirstJavaClass


CODING CONVENTION AND DATA TYPES

 Method Names - All method names should


start with a Lower Case letter.

If several words are used to form the name


of the method, then each inner word's first
letter should be in Upper Case.

Example public void myMethodName()


CODING CONVENTION AND DATA TYPES

Program File Name - Name of the


program file should exactly match the
class name.
CODING CONVENTION AND DATA TYPES

 DATA TYPE
- a set of values and a set of operations defined on them.
Characters (char)
an alphanumeric character or symbol
Strings (String)
a sequence of characters
CODING CONVENTION AND DATA TYPES

Integer (int)
is an integer (whole number) between -231 and 231 - 1
(-2,147,483,648 to 2,147,483,647)

Long (long)
can represent integers in a much larger ranger,
between -263 an 263 - 1.
CODING CONVENTION AND DATA TYPES

Short (short)
has a minimum value of -32,768 and a maximum
value of 32,767 (inclusive)

Byte (Byte)
Ithas a minimum value of -128 and a maximum
value of 127 (inclusive)
CODING CONVENTION AND DATA TYPES

Double (double)
for representing floating-point numbers, e.g., for use
in scientific applications.

Booleans (boolean)
two values: true or false.
CODING CONVENTION AND DATA TYPES

 EXCERCISE
 Identify what time of data are the following

1. 123 = Byte 6. “False” = String


2. 6744.66 = Double 7. @ = Character
3. 32455 = Short 8. -260 = Long
4. False = Boolean 9. 2,147,483,647 = Integer
5. ‘C’ = Character 10. “Engineer” = String
JAVA OUTPUT AND INPUT

JAVA OUTPUT (println)


JAVA OUTPUT AND INPUT

JAVA OUTPUT (print)


JAVA OUTPUT AND INPUT

JAVA OUTPUT (printf)


The printf command understands a series of characters
known as a format specification.
JAVA OUTPUT
AND INPUT
CODING CONVENTION AND DATA TYPES
CODING CONVENTION AND DATA TYPES

class Example {
public static void main(String args[]) {
System.out.println("First line\nSecond line");
System.out.println("A\tB\tC");
System.out.println("D\tE\tF") ;
}
}
Predicted Output:
First Line
Second Line
A B C
D E F
CODING CONVENTION AND DATA TYPES

EXAMPLE:
CODING CONVENTION AND DATA TYPES

JAVA INPUT (Using Scanner) To use scanner, you have to import it to


your program from JAVA UTILITY

To start using scanner, create


new scanner object
“input” is a variable

Syntax to get the input value


and save it to a variable
(ex. number)
CODING CONVENTION AND DATA TYPES

JAVA INPUT (Using Scanner)


Reading Multiple Inputs on the Same Line

space or next line (return key) as delimiter


CODING CONVENTION AND DATA TYPES

JAVA INPUT (Using JOptionPane)


CODING CONVENTION AND DATA TYPES

MAIN() METHOD
ACCESS SPECIFIER RETURN TYPE STRING ARRAY

public static void main(String[] args)


ACCESS MODIFIER METHOD NAME

• Java program processing starts from the main() method which is a mandatory
part of every Java program
CODING CONVENTION AND DATA TYPES

 Comments- must be included in the program.

• /* text */
• /** documentation */
• //
CODING CONVENTION AND DATA TYPES

public class MyFirstJavaProgram {


/* This is my first java program.
* This will print 'Hello World' as the output
*/
public static void main(String []args) {
System.out.println("Hello World"); //prints Hello World
}
}
End of Module 2a

You might also like