Java Programming Practicum Report
Java Programming Practicum Report
TI - 5D SORE
JAVA PROGRAMMING LANGUAGE
DATE SIGNATURE
NAME OF ASSESSOR VALUE
CORRECTION LECTURER
Faculty of Engineering
Medan
2015
FOREWORD
Praise and gratitude I raise to the presence of Allah SWT, who has bestowed various blessings.
rahmat dan Karunia-Nya sehingga penulis masih diberi kesempatan untuk meyelesaikan tugas
laporan praktikum ini guna memenuhi tugas mata kuliah Bahasa Pemrograman Java ini.
Blessings and peace may always be bestowed upon our Prophet Muhammad SAW.
Family, Friends, and his loyal followers who continue to uphold and follow his sunnah.
until the end of time.
In preparing this practical report, the author faced several obstacles.
However, with great patience and especially with the help of Allah SWT, the report...
this internship can be completed, but the author realizes there are still many shortcomings and far
from perfection, therefore constructive suggestions and critiques from the supervising lecturer of the course
This lecture is very much hoped for by the author for improvement in the future. Hopefully, the report
this internship can be beneficial and useful for students, especially for myself
Personally, I thank you for your attention.
Binjai, 05 - 01 - 2015
Compiler :
NAMA : FIRMANSYAH
NPM : 1214370514
i
TABLE OF CONTENTS
FOREWORD... I
CHAPTER I: Introduction
a. General 1
b. Background 2
b. Operator 12
e. Object-Oriented Programming 20
a. Internship Module 2 25
b. Internship Module 3 27
c. Internship Module 4 29
d. Internship Module 5 32
e. Internship Module 6 37
f. Internship Module 7 41
g. Internship Module 8 45
ii
CHAPTER IV: ANALYSIS OF EXPERIMENT RESULTS
CHAPTER V: CONCLUSION 53
REFERENCE LIST 54
iii
Chapter I Introduction.
a. General
Language Java programming initially specifically for application
only web-based but has already expanded from desktop to mobile applications
using it. Java is portable, meaning it can run on various platforms, including Windows,
Linux, Unix, MacOS, or SymbianOS (mobile). The key to this portability is the output.
Java compilation is not an executable file but in the form of bytecode. It is this bytecode that
will be executed by the JRE (Java Runtime Environment) called JVM (Java Virtual Machine)
Machine) and has been installed on every operating system that will be used, so the JVM
The compilation of executables, then Sun provides the HotSpot technology that supplies a JIT compiler.
(Just In-Time) for bytecode and becoming part of the JVM to compile bytecode
Java language was first conceived by James Gosling, Patrick Naughton, Chris
Warth, Ed Frank, and Mike Sheridan at Sun Microsystems in 1991, with the name of the language
the program 'Oak'. In 1995, they visited a local coffee café and changed
its syntax is derived from C and its objects are adapted from C++, so Java has the characteristic
1
b. Background
Along with the development of time and technology, humans who live
They desire facilities that are all fast and instant. It cannot be denied that
the world. One of the programming languages that is often used to create and
This report is prepared with that background, the author intends to study
the Java programming language from the most basic by creating a visual application program
simple. By using the Java programming language, which has more advantages
2
CHAPTER II Theoretical Basis on the Java Programming Language
Java
studied, especially for programmers who are familiar with C/C++. Java is a
Java is also designed to run on all platforms, and is also designed for
Java. While Java has a neutral architecture, because the Java Compiler that
3
1. J2EE (Java 2 Enterprise Edition)
dari Java dan teknologi selain Java. J2EE dirancang untuk membuat aplikasi yang rumit.
information.
The J2EE implementation provides the basic classes and APIs from Java that
supporting the development and routine standards for both client and server applications,
including applications that run in web browsers. for web-based applications, applications
using the Java 2 Standard Edition-based programming language (more commonly known as
with J2SE). In this section, the author will explain the basics of J2SE, including
4
Java SE Runtime Environment (JRE)
Machine (JVM), and other components to run applets and applications that
ditulis dengan bahasa pemrograman Java. Selain itu, terdapat dua buah
the key technology that is part of the JRE is: d Plugin, which
that spreads independent applications through the network. JRE does not contain
application.
application.
The Java programming language provides standard libraries that have been ...
application. In the library, there are various types of classes that can be used and have been
5
Table 2.1 Package Table in J2SE
6
3. J2ME (Java 2 Micro Edition)
Java software for electronic goods along with its supporting devices.
J2ME, if the software framework functions well on a device, then it has not
computation other than desktop computer devices that are usually smaller in size
J2SE can be used on J2ME. However, J2ME has several specific libraries.
which is not possessed by J2SE. The architecture of J2ME can be seen as in Figure 2.2.
characteristics
according to what is owned by that class. The class provides the ability for
7
an overview of an object, while the actual form of the object in Java
building, then the instance is a building that has been constructed based on the design
Thus, there is actually no difference between Object and Instance, it's just that
In Java, classes are grouped based on their general functions, for example
Others. This group is called a class library. Programming doesn't need to be cumbersome.
create a class library, because the existing development kit has created a library
in such a way that it is easy to use. For example, the [Link] library for
will become easier, besides having a more attractive appearance. Some parts
1. JLabel
window.
2. JTextField
text on a frame.
8
3. JButton
4. JFrame
in creating a window.
5. JInternalFrame
6. JMenu
7. ActionListener
8. Container
9
The container will help organize the placement of objects such as text,
rows and columns according to what was entered during setLayout. And placement
the object starts from the top left and then to the right.
Java documentation.
[Link]. The containers that are often used are JFrame and
JDialog. For web-based programs, you can use the Applet container.
container, which is the base container that serves as the foundation for the component
and other containers. In addition to the three above, there are still several other containers.
like JPanel.
container, so the component can have its size and layout adjusted. In addition
the color and shape can also be adjusted. To arrange the layout, the object that
used is LayoutManager.
10
4. Handling events generated by components
move, and so on. Events are the result of user interaction and
2. Netbeans
writing, compiling, searching for errors, and distributing programs written in NetBeans
in Java language but can also support other programming languages. program
1. features in netbeans
• Error stripe: a feature that marks the rows with errors by highlighting them in red.
• Bookmarking: a feature used to mark lines that will be used at some point
we want to modify
11
3. Databases supported by NetBeans
• The JDBC API consists of a set of interfaces and classes written in the language
Java programming.
oracle
• JDBC-ODBC
• mySQL-server
[Link]
Operators are used to perform operations, calculation commands, and all actions.
that you want to include in the program. Okay, let’s go straight to the explanation below.
this.
1. Arithmetic Operator
12
Arithmetic operators are used to perform mathematical operations, such as
usage:
(+) Operator plus; indicates a positive value (any number without this sign will be considered
as positive)
(-) Operator minus; indicates a negative value, can also be used for
negating a number
This operator cannot be used for final variables, because final variables are of type.
a constant that cannot be changed. Several types of unary operators are provided on
13
++ Increase Adding a number to 1 number = ++number;
-- Decrease Reducing a number by 1 = --number;
! Opponent Invert the value of a boolean ok = !true
3. Operators of increase and decrease
or x = x-1. If the ++ operator is placed at the end (suffix), the value of "y" is the value of "x".
previously. Java will assign the value 'y' the value 'x' before the ++ operation is performed.
from its variable, in this case, the operation is performed on two operands. Operator
boolean is a conditional operator whose two operands are boolean values (true or false)
mathematics.
Note: In objects, such as String, comparison operations will compare the addresses.
the memory where the object is stored, not comparing its content. For
14
!= Not the same as b=(1!=2);
> Larger b=(1>2);
>= Greater than or equal to b=(1>=2);
< Smaller b=(1<2);
<= Less than or equal to b=(1<=2);
&& AND condition b=true&&false;
|| Operating Room Condition b=true||false;
! NOT condition b=!true;
?: Short form of "if then else"
5. Boolean AND Operator
The AND conditional operator produces 'true' if both of its operands are 'true'.
If either one or both are 'false', this operator produces 'false'. The following are
valued as "true". As seen from the table above, if Op1 (on the left) has a value of
"false", the result will always be "false" regardless of the content of Op2.
OR Condition Operator
The OR condition operator yields 'true' if at least one of its operands is 'true'. If
Both are 'false', this operator yields 'false'. Below is the truth table for the OR operation.
15
true true true
7. The operator || will evaluate Op2 (on the right) ONLY if operand 1 is true.
"false". As seen from the table above, if Op1 (on the left) has the value of "true",
8. Operator NOT
The NOT operator ('!') performs a boolean NOT operation on a single operand or expression.
This operator checks the boolean value of an operand or expression and then flips it.
the value changes (from true to false or false to true). The following is the truth table of the operator
NOT.
Op1 Result
True False
False True
9. Ternary Operator (?:)
Java has another conditional operator called ternary "?:", which essentially
if_false Basically, the operator '?:' will evaluate the 'condition'. If the condition
evaluates to "true", the operator will return "if_true", but when "condition"
16
c. Class, Object and Method
1. Class
2. Object
Example: From the Fruit class, we can create objects like Mango, Banana, Apple, and others.
.
3. Attributes/ Variable
It is the value of the data that exists on an object that comes from a class.
Attributes represent the characteristics of an object. For example: in the Fruit Class.
terdapat attribute : warna, berat pada object mangga : warna berisi kuning dan berat
for example, 0.24 kg on the apple object: color contains red and weight is 0.30 kg
4. Method/Behavior
An object. The method is defined in the class but is called through the object.
Example: on the mango object: there are methods getTaste, peelSkin, and others.
Method to determine the behavior of an object, namely what happens when the object is created.
as well as various operations that can be performed by an object throughout its lifetime.
17
2. Object type or primitive type returned by the method.
3. List of parameters.
The first three parts indicate important information about the method itself.
In other words, the name of the method is another method in the program. In Java we can
have different methods that have the same name but different return types
or the list of arguments, so the parts of the definition of this method become important. This
more than 1 object from subclasses and treated as objects of the superclass
single.
1. Looping
In Java, there are three types of loops, namely for, while, and do while.
Structure for
18
statement 1 ;
statement 2;
The looping process will continue as long as the condition evaluates to true.
in other words, the repetition process will only stop when the condition has a value of false or
is no longer fulfilled.
While structure
The while structure is a type of loop that defines the condition at the beginning of the block. This
that is, if the condition is not met (equals false) then the repetition process will not occur.
will be done. The initialization process of values in the while structure is written before we
write the structure of the while itself, while the iteration will be written inside the block.
do-while structure
The do while loop is similar to the while loop. The statements inside the do-while loop will
executed several times while the condition is true. The difference between while and do while
A loop is where the statements inside a do while loop are executed at least once.
2. Branching
The program will be interesting if certain requirements are needed to run it.
producing the setting of which part of the program runs, in the form of a statement
branching statements. There are several types of branching in Java, namely if, if-else, and
switch.
19
If branching
The if statement in Java indicates that the statement will be executed if the condition is met.
If(condition){
Statemen1;
Statement2;
If else branching
thus, the if else structure causes execution to run through a set of booleans,
only certain parts of the program are executed. Here is the general form of the if else statement:
If (condition)
Otherwise
Switch branching
based on the value of a variable or a single statement. The switch branching is intended
Object-Oriented Programming
20
with structured programming logic. Each object can receive messages, process
kemudahan mengubah program, dan digunakan luas dalamteknik piranti lunakskala besar.
beginners compared to the previous approach, and the OOP approach is easier
21
CHAPTER III Experimental / Practical Results
3. Create a new project by clicking the File menu --> new Project so that the display appears
as follows.
22
4. In the Category choose Java and in the Project choose Java Application, click next to
continuing
5. In the Project Name, enter your project name, for example, Module1 concept set as Main
In the project, uncheck Create Main Class and then click Finish.
6. The project has been created, now create a class by right-clicking on the project name then
click new --> JFrameForm. After clicking JFrameForm, it appears as shown in the following image.
23
7. Enter the class name in Class Name, for example, Module1, then click Finish. Project Ready
used
24
b. Internship Module 2 / Creating a Biodata project
25
After finishing, right-click on the source code and select Run File, then it will appear
like this:
After that, enter your biodata and then click process, the result will be as follows:
26
c. Internship Module 3 / Creating a simple calculator
27
After finishing, right-click on the source code and select Run File, then it will appear.
like this:
After that, enter the first value and the second value, then click the button next to it.
right, in this case, I will choose the addition button, so the result is as follows:
28
d. Internship Module 4 / Creating a sales project
29
After finishing, right-click on the source code and select Run File, then it will appear.
like this:
Enter the buyer's name, select status (general/member), select item type
(Ipad/Iphone/Ipod) and enter the quantity of items you want to purchase. Then click the button
pay.
30
First, I selected the status as general, so the result is as follows:
Then I chose the status as a member, with the same type of goods and quantity.
31
e. Internship Module 5 / Creating an employee salary calculation project
32
33
34
After finishing, right-click on the source code and select Run File, then it will appear
seperti ini :
35
After that, enter the NIP, Name, and select the position (Director / manager / head of section / secretary /
karyawan / office boy), pilih status (Menikah / Belum menikah), jumlah anak jika sudah
marriage.
I will try to enter the employee's position, status is unmarried, so the result will be as
the following:
If I enter the same position but the status is married and has 2
36
f. Internship Module 6 / multi document interface
37
38
Add JInternalFrame Form to the project by selecting the File menu. New File select Project
you, then in Categories select Swing GUI Forms and in File Types select
39
Fill in the Class name 'IFModul2' and Package 'MDI' then click Finish.
Open the previous Module 2 and then select the navigator item jDesktopPane1 right click
Copy.
rightPaste.
After finishing, right-click on the source code and select Run File, then it will appear.
like this:
40
g. Internship Module 7 / Creating customer data project
41
42
After finishing, right-click on the source code and select Run File, and it will display.
like this:
Then enter the name, phone number, and address, after that click save so that the data becomes
43
If the entered data is incomplete, a message will appear stating
44
h. Internship Module 8 /
45
46
47
Right-click on cbojenis, then select Events -> Action -> actionPerformed.
48
Right-click on btnbayar, then select Events -> Action -> actionPerformed.
Compile and run from the Run menu -> Run File or press Shift + F6.
49
CHAPTER IV Analysis of Experimental Results
a. Create a Java program using a text editor and console in the environment.
Module 3 is a practical exercise to create a simple calculator with the aim of:
b. Distinguishing several important aspects in Java such as Java literals, data types
branching (if, else, switch). The program will be interesting if certain requirements are needed.
50
d. Analysis of Practicum Module 5
A method is a part of the code that can be called by the main program or
2. It should accept several parameters that are needed or there are no parameters.
3. After the method has finished executing, it will return to the method
its name, the MDI (Multiple Document Interface) application is an application that can
Microsoft Word, Microsoft Excel and other application programs. In the MDI application, there is
another form.
• Child Form: The form displayed within the Parent Form. This form is installed.
51
f. Analysis of Practicum Module 7
Module 7 is a practical session on Creating Data Input Forms and Database Connections
using many connection classes. Each class will connect to the database
It must connect to different databases, so there are certainly many codes that need to be changed.
Just create a class and a connection method. Create the class objects repeatedly.
call the method repeatedly. Or if necessary, inherit the connection class to the classes
next.
using 2Packages, namely Package Gui and Package Connection, Package Connection
This is what connects the Java Netbeans IDE program to the MySQL Database.
52
CHAPTER V: CONCLUSION
Conclusion
with a series of advantages contained within it. With the API (Application) application program
This report is prepared with that background, the author intends to study
Java programming language from the most basic by creating a visual application program.
simple. By using the Java programming language, which has more advantages
Suggestion
Thus, this Java Practicum Report is presented by the author regarding the practicum materials that
becomes the main topic of this report, of course, there are still many shortcomings and
its weaknesses. The author sincerely hopes for feedback and suggestions from the Java study instructor for
better improvement.
53
Bibliography
[Link]
[Link]
[Link]
[Link]
[Link]
Learn Basic to Advanced Java with an Ebook in Indonesian | Learning and Sharing Place
[Link]
54
The ternary operator in Java is a shorthand for an if-then-else statement. It evaluates a boolean expression and returns one of two values based on whether the expression is true or false. The syntax is condition ? if_true : if_false. For example, the statement int result = (score > 60) ? 'pass' : 'fail'; checks if the variable score is greater than 60. If true, result is assigned 'pass'; otherwise, it is 'fail' . This operator provides a concise way to perform simple conditional logic within assignments.
The LayoutManager is responsible for arranging components within a Java container, controlling their sizes and positions. By specifying a particular layout, such as BorderLayout, FlowLayout, or GridLayout, developers can dictate how components will be displayed on the user interface, thus affecting the visual structure and usability of the application . The proper use of LayoutManager ensures efficient use of screen space and responsive design layout that adjusts with different screen sizes and resolutions.
Containers like JPanel and JDialog enhance the development of Java applications by providing structured environments to organize and display components. JPanel is often used as a generic lightweight container to group a set of components together within a specific area, enabling complex layouts and nested structures that promote modular design. JDialog, on the other hand, is used for creating pop-up dialogs or secondary windows, helping to separate and focus user interactions in an application. These containers facilitate better user interface management by making it easier to structure visual elements and control user input flow, thereby improving the overall user experience of Java applications .
JDBC (Java Database Connectivity) acts as an API that enables Java programs to connect to various database management systems (DBMS). It provides a standard interface for querying and updating databases, making Java applications database-agnostic . NetBeans supports drivers such as ojdbc for Oracle database connectivity and mysql-connector-java for MySQL. These drivers enable seamless database access from within Java applications developed in NetBeans . This set of APIs simplifies the database interaction process by ensuring that Java applications can connect to, and communicate with, the database in a standard manner.
Arithmetic operators in Java are used to perform mathematical operations, such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). For example, int result = 3 + 2; uses the addition operator to yield 5. Similarly, division is performed as int divisionResult = 10 / 2; giving 5. Java also allows for string concatenation using the addition operator: String greeting = "Hello " + "World!"; combines the two strings into "Hello World!" . These operators facilitate numerical calculations and string manipulations within Java applications.
Methods in Java classes are crucial as they define the behavior that objects instantiated from those classes can exhibit. A method is essentially a block of code that performs a specific operation or task and may return a value. When an object is created, its methods can be called to execute these operations, allowing the object to interact with other objects and perform calculations or actions. This encapsulation of behavior within methods contributes to maintaining the object-oriented principles of encapsulation, ensuring that internal states can only be accessed and modified through defined interfaces . Methods thus form the core functional aspects of an object, enabling dynamic interactions and operations within a Java application.
NetBeans offers several features that benefit Java developers by enhancing code management and error detection. The smart code completion feature assists programmers by suggesting variable names and keywords, thereby speeding up development time. The error stripe highlights lines of code with errors, making it easier for developers to identify and fix mistakes promptly. Furthermore, features like bookmark lines for quick access and the 'Go to' command for navigation within the project improve code management significantly . This combination of tools within NetBeans streamlines Java programming, allowing more focus on development rather than on repetitive error checking.
Unary operators, such as the increment (++) and decrement (--) operators, modify a single operand directly by either adding or subtracting one from the operand's value. For instance, the increment operator ++ can be used as ++x to increase the value of x by one before its value is used, or as x++ to increase it after its current value is used. However, unary operators cannot be used on final variables because final variables are constants, meaning their values cannot be changed once they are initialized .
Branching statements in Java are used to control program flow by executing specific code blocks based on conditional statements. The 'if' statement executes a block of code when a defined condition is true. An 'if-else' statement allows for a binary choice, executing one block if the condition is true and another if it is false, thereby providing an alternative path. The 'switch' statement is used when there are multiple potential execution paths based on the value of a variable or expression. It allows a program to execute different parts of code depending on the specific value it compares against multiple cases . These branching mechanisms allow developers to implement complex logic flows efficiently.
Object-oriented programming (OOP) in Java enhances software flexibility and scalability by encapsulating data and behavior within objects, allowing for modular design. Each object can operate independently and interact with other objects through well-defined interfaces. This leads to greater flexibility in terms of modifying and extending systems since new functionalities can be added with minimal impact on existing structures. OOP also facilitates code reuse through inheritance and polymorphism, making codebases more scalable as new classes can extend existing ones to expand capabilities without duplicating code . Proponents claim that OOP is easier to learn and adapt, thus supporting more efficient development for large-scale software projects.