0% found this document useful (0 votes)
13 views18 pages

Prelimmodule Lesson3

The document outlines the learning outcomes for a Java programming lesson, including interpreting Java structure, compiling, and running programs. It provides a detailed analysis of a sample Java program, explaining comments, class definitions, and the main method. Additionally, it includes step-by-step instructions for creating and running a Java project in the NetBeans IDE, emphasizing the importance of correct syntax and case sensitivity.
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)
13 views18 pages

Prelimmodule Lesson3

The document outlines the learning outcomes for a Java programming lesson, including interpreting Java structure, compiling, and running programs. It provides a detailed analysis of a sample Java program, explaining comments, class definitions, and the main method. Additionally, it includes step-by-step instructions for creating and running a Java project in the NetBeans IDE, emphasizing the importance of correct syntax and case sensitivity.
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/ 18

N 3

S O
E S
. L
E
UAL
DA V
O
MOF J
I MR E
E L U
R C
P TRU
T

S
LEARNING OUTCOMES
At the end of the lesson, the students are
expected to:
 Interpret the structure of Java programming
 Compile the Java Program
 Run the program in DOS and NetBeans
Environment
 Develop their own simple program
Structure of a Java Program

Class Name
Method name

1 /*MyFirstProgram implements an application that simply displays


“Welcome to the
World of Java Programming”*/
2 // to the standard output.
3 public class MyFirstProgram
4 {//begin of class
5 public static void main(String args[ ])
6 {//begin of main
7 System.out.println(“Welcome to the World of Java
Programming!”);
8 }//end of main
9 }//end of class
PROGRAM ANALYSIS:
Indentation is encouraged every time you are writing the program to make your program more
presentable and readable especially if you have complex program to be created.
Line 1- 2:
Comments embedded in the program. Programmers insert comments to document programs
and improve program readability. Comments also help other people read and understand
your program. Comments do not cause the computer to perform any action when the
program is run. Comments are ignored by the Java compiler:
A comment that begins with // is called a single-line comment because the comment
terminates at the end of the current line. Note that a // comment can begin in the middle of
a line and continue until the end of that line.
Two other comment notations facilitate writing multiple-line comments.
/* This an example of a multiple-line comment.
You can have as many lines of comments in you program
providing the reader the information about your code */
is a comment that can spread over several lines – called a multiple-line comment that begins
with delimiter /* and ends with delimiter */. All text between the delimiters of the comment
is ignored by the compiler. A similar form of comment called a documentation comment is
delimited with /** and */.
Line 3:
Class definition for classMyFirstProgram. Every program in Java
consists of at least one class definition that is defined by the
programmer. This line is also called class heading. When you write
public class MyFirstProgram, you are defining a class named
MyFirstProgram. The reserved word public is an access modifier.
An Access modifier defines the circumstances under which a class
can be accessed. Public access is the most liberal type of access.
Line 4:
Start the body of the program with the user of open curly brace {
Line 5:
The first method that Java program executes is the main ( ). In the
method header, static means showing little change or stationary.
Static also means unchanging and indicates that every member created
for the MyFirstProgram class will have an identical unchanging
main(). Within the method main(Stringargs [ ]) is an argument.
An argument consists of information that a method requires to perform
its task. String represents a Java class that can be used to represent
character strings. The identifier args used to hold any strings that
might be sent to main().
The main() method could do something with those arguments such as
printing them but in line 5, the main() method’s parenthesis. The
identifier need not be named args. it could be any legal Java
identifier but by convention, we use the args identifier.
Line 6:
Begins the body of the main( ) with the use of the symbol {.
Line 7:
This statement displays Welcome to the World of Java Programming on
the screen. Within the statement System.out.println(“Welcome to
the World of Java Programming), System is a class, out is an object.
The out object represents the screen. One of the System’s object is the
out object. Println is a method that prints a line of output on the
screen then positions the cursor on the next time. The dots in the
statement System.out.println are used to separate Class, object and
method.
Line 8:Ends method main ( ).
Line 9:Ends class MyFirstProgram
OUTPUT:
Welcome to the World of Java Programming
STEPS IN CREATING PROJECT IN JAVA USING
NETBEANS
1. Launch the NetBeans IDE.
 On Microsoft Windows systems, you can use the NetBeans IDE
item in the Start menu.
 On Solaris OS and Linux systems, you execute the IDE launcher
script by navigating to the IDE's bin directory and typing ./netbeans.
 On Mac OS X systems, click the NetBeans IDE application icon.
2. In the NetBeans IDE, choose File | New Project....
NetBeans IDE with the File | New Project menu item selected.
In the New Project wizard, expand the Java category and
select Java Application as shown in the following figure:
NetBeans IDE with the File | New Project menu item
selected
3. In the New Project wizard, expand the Java category and select Java
Application as shown in the following figure:

NetBeans IDE, New Project wizard, Choose Project page.


4. In the Name and Location page of the wizard, do the following (as shown in the figure
below):
 In the Project Name field, type Hello World App.
 In the Create Main Class field, type helloworldapp.HelloWorldApp.
NetBeans IDE, New Project wizard, Name and Location page.

5. Click Finish.
The project is created and opened in the IDE. You should see the
following components:
The Projects window, which contains a tree view of the components of
the project, including source files, libraries that your code depends
on, and so on.
The Source Editor window with a file called HelloWorldApp.java open.
The Navigator window, which you can use to quickly navigate between
elements within the selected class.

NetBeans IDE with the HelloWorldApp project open


Selecting the Java Platform Manager from the Tools Menu
If you don't see JDK 8 (which might appear as 1.8 or 1.8.0) in the list of
installed platforms, click Add Platform, navigate to your JDK 8 install
directory, and click Finish. You should now see this newly added
platform:
The Java Platform Manager
To set this JDK as the default for all projects, you can run the IDE with
the --jdkhome switch on the command line, or by entering the path
to the JDK in the netbeans_j2sdkhome property of
your INSTALLATION_DIRECTORY/etc/netbeans.conf file.
To specify this JDK for the current project only, select Hello World App in
the Projects pane, choose File | Project Properties (Hello World App),
click Libraries, then select JDK 1.8 in theJava Platform pulldown
menu. You should see a screen similar to the following:

The IDE is now configured for JDK 8.


Add Code to the Generated Source File
When you created this project, you left the Create Main Class checkbox selected in
the New Project wizard. The IDE has therefore created a skeleton class for you.
You can add the "Hello World!" message to the skeleton code by replacing the
line:
// TODO code application logic here with the line:
System.out.println("Hello World!"); // Display the string. Optionally, you can
replace these four lines of generated code:
/** * * @author */ with these lines:
/** * The HelloWorldApp class implements an application that * simply prints
"Hello World!" to standard output. */
Note:
These four lines are a code comment and do not affect how the
program runs. Later sections of this tutorial explain the use and
format of code comments.
Be Careful When You Type
Note: Type all code, commands, and file names exactly as shown. Both
the compiler (javac) and launcher (java) are case-sensitive, so you
must capitalize consistently.

HelloWorldApp is not the same as helloworldapp.


Save your changes by choosing File | Save.
The file should look something like the following:
/* * To change this template, choose Tools | Templates * and open the
template in the editor. */ packagehelloworldapp; /** * The
HelloWorldApp class implements an application that * simply prints
"Hello World!" to standard output. */public class HelloWorldApp
{ /** * @paramargs the command line arguments */public
static void main(String[] args) {System.out.println("Hello World!"); //
Display the string. } }
HOW TO RUN THE PROGRAM
IN NETBEANS ENVIRONMENT
From the IDE's menu bar, choose Run | Run Main Project.
The next figure shows what you should now see.

The program prints "Hello World!" to the Output window (along with other
output from the build script).

You might also like