The sample test is modeled on the Sun Certification for JavaTM 2 Programmer exam. The test has 59 questions and needs to be executed in 2 hours. The real exam may be a little tougher than this. You need to score 36 correct answers to clear the real exam. The first 50 questions of the mock exam are valid for both 1.2 and 1.4 versions of the exam. The remaining 9 questions are only useful if you are taking the SCJP 1.2 exam. Please let me know if you find any issues with the test. The site also offers another mock exam. The remaining questions are related to AWT, event classes, and layout managers. These topics are not included in 1.4 version of the exam.
public class xyz {
public static void main(String args[]) {
for(int i = 0; i < 2; i++) {
for(int j = 2; j>= 0; j--) {
if(i == j) break;
System.out.println("i=" + i + " j="+j);
}
}
}
}
java test 2
Select the one correct answer. public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();
if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}
public class test {
public static void main(String args[]) {
int i, j=1;
i = (j>1)?2:1;
switch(i) {
case 0:
System.out.println(0);
break;
case 1:
System.out.println(1);
case 2:
System.out.println(2);
break;
case 3:
System.out.println(3);
break;
}
}
}
public class test {
public static void main(String args[]) {
int i=0, j=2;
do
{
i=++i;
j--;
}
while(j>0);
System.out.println(i);
}
}
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally
{
System.out.println(3);
}
System.out.println(4);
}
}
public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i == j)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = new String("abc");
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
public class test {
public static void main(String args[]) {
int i = 1;
do {
i--;
}
while (i > 2);
System.out.println(i);
}
}
void method X() {
String r = new String("abc");
String s = new String("abc");
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
Assuming the above declaration, which of the following statements would compile. Select the one correct answer.
void method() { }
Which of the following are legal prototypes in a derived class of this class. Select the two correct answers.
int i = 0, j = 1;
public class test {
public static void main(String args[]) {
int i;
float f = 2.3f;
double d = 2.7;
i = ((int)Math.ceil(f)) * ((int)Math.round(d));
System.out.println(i);
}
}
public class test {
public static void main(String args[]) {
String str1="abc";
String str2="def";
String str3=str1.concat(str2);
str1.concat(str2);
System.out.println(str1);
}
}
Answers to Sample Test 1
Making Http Simple Server With Java
by Son Rokhaniawan Perdata, S.T | 12:16 AM in Java, Tutorial | comments (2)
Praktikum's task Network and Apparatus Mathematics moves secondly be make one http simple server at localhost. With utilize SocketServer's function, therefore gets to be made one server which will wait “panggilan†on port 80 (HTTP). And will send html's code while called.
SocketServer works in one looping that perpetual to wait marks sense connection to go to port 80 on localhost. There is 4 constructor on SocketServer for example:
- public ServerSocket(int port) throws BindException, IOException
- public ServerSocket(int port, int queueLength) throws BindException, IOException
- public ServerSocket(int port, int queueLength, InetAddress bindAddress) throws IOException
- public ServerSocket( ) throws IOException // Java 1.4
n Java, to make one server gets to be done by trick as follows:
- One serverSocket a new one is made deep one given port (in this case port 80) utilizing constructor of one SocketServer.
- Then serverSocket waits until mark sense coming connection through port has already is determined previous utilize accept's function().
- Then depends from server type, well utilize getInputStream's function(), getOutputStream's function(), or both of ala function goes together to get input and output stream in order to gets communication with client.
- Server and client gets communication / get interaction until its time hang up connection.
- Server, Client or both hangs up connection
- Server returns to to step 2 and waiting until marks sense succeeding connections.
And attachment source's following code that I takes from praktikum's module meagrely modifies to be able to qualify as one http server.
Perusal and File Writing with Java
by Son Rokhaniawan Perdata, S.T | 12:03 AM in Netbeans, Tutorial | comments (0)
A few days ago, my friend asks for to help her works PR its Programming. PR's problem terminologicals i am goodly difficult also, since I newbie in programming. Programming languages who may be utilized is C,C++, Java. And since i am java person, therefore I choose to utilize Java.hehe.. Since I really be intend to study Java language.
Problem PR is we make program who will read one input file “indata.txt”, one that meaty word which will at test do correspond to order, if accords therefore that diwrite will into one file “legalwords.txt”, conversely if incorrectly will at write into file “badwords.txt”. Among word one by another word in file “indata.txt” came to pieces by one tabulator, on my program, I utilize tabulator tab(\t). Order that is utilized for mengetest to say is
a. first syllable may not as numeral as.
b. say has less than 8 characters.
c. say just may lap over of letter (a..z, A..Z), number (0..9), atau simbol underscore(’_').
Since I newbie in Java,and was wonted utilizes it, requiring time rather long time to think up syntax syntax that is used. On progam I, its program path is as follows:
a. Make one BufferedReader for FileReader(”indata.txt”). Make PrintWritter for FileWriter legalwords.txt and badwords.txt.
b. Then by use of StringTokenizer to account word amount in file indata.txt.
c. After knows total token / says, therefore then with looping to check about word / token, what appropriate ruling or not.
d. Then afters is sorted, therefore word suitably at write goes to legalwords.txt, and unsuitably diwrite goes to badwords.txt
And this is result running programs my version:
1. Input File
2. Legal Words
3. Bad Words
On Compile NetBeans
And this following is source code programs what do I make. Its correction appeal if available fault.
DOWNLOAD
Tips Java : Getting Address's IP and Host Name
by Son Rokhaniawan Perdata, S.T | 11:35 PM in Java, Tutorial | comments (0)
Java provides InetAddress's function to get host's internet protocol address and also name a computer. host's internet protocol address and also name that is gotten don't cling to host's internet protocol address and name local computer only, but can also be utilized for mengecek host's internet protocol address and name at Internet, obviously by condition of computer we most link with Internet. This logistic purpose also relates hand in glove with setting DNS on computer that we utilizes.
Following is sample program that points out fungsionalitas that:- Make one project is Netbeans new
- Add one JFrame Form
- Provede with 2 tags, 2 numbers TextField (txtIPAddress dan txtNamaHost) and 3 Button (btnCheckIPAddress, btnCheckHostName dan btnCheckLokal). See example on pictured following:
- Following code cannikin type on btnCheckHostName, event actionPerformed
- private void btnCheckHostNameActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- String strHostName = InetAddress.getByName(txtIPAddress.getText()).getHostName();
- JOptionPane.showMessageDialog(null, "Host name dari IP Address '" + txtIPAddress.getText() +"' =
"+ strHostName); - } catch (UnknownHostException ex) {
- JOptionPane.showMessageDialog(null, ex);
- Logger.getLogger(frmIpAddress.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- Do import library that needful (import java.net.InetAddress; import javax.swing.JOptionPane;)
- Following code cannikin type on btnCheckIPAddress, event actionPerformed
- private void btnCheckIPAddressActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- String strIPAddress = InetAddress.getByName(txtHostName.getText()).getHostAddress() ;
- JOptionPane.showMessageDialog(null, "Alamat IP dari '"+txtHostName.getText() +"' ="+ strIPAddress);
- } catch (UnknownHostException ex) {
- JOptionPane.showMessageDialog(null, ex);
- Logger.getLogger(frmIpAddress.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- Following code cannikin type on btnCheckLokal event actionPerformed
- private void btnCheckLocalActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- InetAddress AlamatInternet = InetAddress.getLocalHost();
- JOptionPane.showMessageDialog(null, "Host name lokal : " +AlamatInternet.getHostName());
- JOptionPane.showMessageDialog(null, "IP Address lokal : " +AlamatInternet.getHostAddress() );
- } catch (UnknownHostException ex) {
- JOptionPane.showMessageDialog(null, ex);
- Logger.getLogger(frmIpAddress.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- Save and runs application (SHIFT + F6). Insert IP Address and click on “Check Host Name” or insert host name and click “Check IP Address”. Check IP and Host Local don't need entry. Following is umpteen screenshot message one that performs:
This program not smart's ala detect entry what that internet protocol address or host name. To easy, I utilize 2 numbers TextField for example. On terapan's application, input IP Address or Host Name can thru get variable.
Creating an AJAX-Enabled Calendar Control
by Son Rokhaniawan Perdata, S.T | 12:08 AM in Ajax | comments (0)
Introduction
Go to any travel or event booking website and you'll find the same user interface for collecting date information: the Calendar. Providing such an interface in an ASP.NET application is a breeze, thanks to the built-in Calendar Web control. There are two downsides to ASP.NET's Calendar control: first, it is not very useful when selecting dates far into the future or past, as you can only navigate to the next or previous month; and, second, the Calendar does not use AJAX techniques, so each click, be it selecting a date or moving to the next or previous month, requires a full postback.
Mehmet Genc addressed this first shortcoming in Extending the Calendar Control's Date Navigation by showing how to add month and year drop-down lists. But Mehmet's article was written in 2004 and since then AJAX-enabled websites have become all the rage. I decided it was high time to update Mehmet's custom Calendar control to support AJAX. Specifically, I implemented the AJAX-enabled Calendar control as a User Control. The User Control renders a TextBox control that, when clicked, displays a Calendar control from which the user can select the date. Like with Mehmet's Calendar, users can quickly jump to a particular month or year by using two drop-down lists. And best of all, the user experience is very responsive.
First Things First: Ensuring Your Environment Supports ASP.NET AJAX
To use this AJAX-enabled Calendar control, make sure your development environment supports the ASP.NET AJAX framework. If you are using Visual Studio 2008, then this framework is already present. If, however, you are using Visual Studio 2005, then you need to download and install the ASP.NET AJAX framework from Microsoft's site, http://www.asp.net/ajax/. For more information on this process, refer to Scott Mitchell's article, AJAX Basics and Getting Started with Microsoft's ASP.NET AJAX Framework.
My AJAX-enabled Calendar control uses the UpdatePanel and PopupControlExtender controls. While the UpdatePanel is part of the framework's "Essential Components," the PopupControlExtender is part of the ASP.NET AJAX Control Toolkit, which is a separate download (even for Visual Studio 2008). If you check out the Control Toolkit samples you'll notice that there's an AJAX Calendar control in the Toolkit. I built my own AJAX-enabled Calendar control instead of using the one in the Control Toolkit because I wanted to add the month/year drop-down lists. Also, there have been a variety of display bugs with the Calendar control (see the AJAX Control Toolkit work item list). I invite you to try out mine and the AJAX Control Toolkit's Calendar and use the one that's best suited for your needs.
Getting Started with My AJAX-Enabled Calendar Control
The complete code for this User Control, along with a sample web page, is available at the end of this article. You should be able to open the folder as a website in either Visual Studio 2005 or Visual Studio 2008.
The Calendar is implemented in the CoolCalendar.ascx file as a User Control. Take a moment to examine the markup in this page. You'll find the following key controls:
1. The DateTextFrom TextBox
2. A RequiredFieldValidator named DateTextFromRequired
3. A Panel control
4. An UpdatePanel control
5. The month and year DropDownList controls
6. The Calendar control
7. An AJAX PopupControlExtender control
There are a few of these controls that warrant further discussion. Take note of the markup for the DateTextFrom
TextBox control (item 1):
onfocus="javascript:this.blur();"
. This bit of client-side script ensures that whenever the user clicks on the DateTextFrom
TextBox, focus is immediately taken away from the control. The idea here - as we'll see shortly - is that whenever the user focuses on the TextBox it is immediately taken away and the Calendar control is displayed. This forces the user to select a date from the calendar. If you remove the onfocus
script, the user could enter the date into the TextBox via the keyboard. I find this option undesirable due to the possibility of user entry errors.
The RequiredFieldValidator (item 2) is used to optionally ensure that a date value has been supplied. The User Control contains a Boolean public property named DateTextRequired
. Setting this value to True enables the RequiredFieldValidator; setting it to False disables it. By default, the RequiredFieldValidator is enabled.
The AJAX PopupControlExtender control pops up a particular Panel on the page in response to a certain client-side action. The Panel control (item 3) defines the region that is popped up, and includes the UpdatePanel (item 4), the month/year DropDownLists (item 5), and the Calendar control (item 6).
The final piece in the markup page is the PopupControlExtender control (item 7) and is configured to display the Panel (item 3) whenever the DateTextFrom
TextBox receives focus. This behavior is dictated entirely through the PopupControlExtender control's properties, there's no need to write any JavaScript or code!
|
, Displaying Extended Details in a GridView Using an Ajax Pop-Up.
Examining the AJAX-Enabled Calendar Control's Code
The User Control's code-behind class defines a couple of properties and includes the code to populate the month/year DropDownLists and the user's interactions with the Calendar. The most important property is the DateTextFromValue
, which sets or gets the selected date. This property simply reads and writes its value to the DateTextFrom
TextBox.
public string DateTextFromValue |
Note: The code available for download at the end of this article includes a VB and C# version of the User Control...
Two additional properties are defined for specifying whether the RequiredFieldValidator should be enabled (DateTextRequired
) and the error message to display if the required date value is not supplied (DateTextRequiredText
).
The month and year DropDownLists are populated by the Populate_MonthList
and Populate_YearList
methods, which are called on the first page visit. These methods were taken directly from Mehmet's article. Populate_MonthList
returns a list of month names (January, February, ...) while Populate_YearList
populates the DropDownList with years from 20 years ago to one year in the future.
When the month or year DropDownList is changed, a partial page postback occurs and the Set_Calendar
method is executed. The Set_Calendar
method sets the Calendar control's TodaysDate
property to the first of the selected month/year.
public void Set_Calendar(object Sender, EventArgs E) |
Whenever the user selects a date within the Calendar, a partial page postback transpires and the Calendar's SelectionChanged
event is fired. The Calendar1_SelectionChanged
event handler calls the PopupControlExtender control's Commit
method, passing in the Calendar's SelectedDate
property. The net effect is that the Calendar popup disappears and the selected date is display in the TextBox.
protected void Calendar1_SelectionChanged(object sender, EventArgs e) |
My AJAX-Enabled Calendar Web Control In Action
The download at the end of this article includes a simple demo page, TestCoolCalendar.aspx
. The demo illustrates how to use the User Control's DateTextRequired
and DateTextRequiredText
properties to require a date and show a custom error message. In addition to the User Control, the TestCoolCalendar.aspx
includes a Save button that, when clicked, displays the value selected from the Calendar control. This value is retrieved via the User Control's DateTextFromValue
property.
Conclusion
In this article we saw how to use the ASP.NET AJAX framework's UpdatePanel and the AJAX Control Toolkit's PopupControlExtender to turn the built-in Calendar control into a richer, AJAX-enabled version. This control is implemented as a User Control, making it a cinch to add to your projects. Thanks again to Mehmet Genc for the initial inspiration and to Scott Mitchell for publishing this article.
Happy Programming!
package testing; Then remakes one class at same package
Swing is one of technology in Java to make one application desktop. This following I load one simple example with swing. One calculator plain. I utilize two numbers class. Class first is that of penampil frame and class second is program from that calculator is alone.
Its example following:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* @author bagus
*/
public class SwingCalculator {
public static void main(String[] args) {
JFrame frame = new Calculator();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
*
* @author bagus
*/
class Calculator extends JFrame {
private final Font BIGGER_FONT = new Font("monspaced", Font.PLAIN, 20);
private JTextField textfield;
private boolean number = true;
private String equalOp = "=";
private CalculatorOp op = new CalculatorOp();
public Calculator() {
textfield = new JTextField("0", 12);
textfield.setHorizontalAlignment(JTextField.RIGHT);
textfield.setFont(BIGGER_FONT);
ActionListener numberListener = new NumberListener();
String buttonOrder = "1234567890 ";
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 4, 4, 4));
for (int i = 0; i < buttonOrder.length(); i++) {
String key = buttonOrder.substring(i, i+1);
if (key.equals(" ")) {
buttonPanel.add(new JLabel(""));
} else {
JButton button = new JButton(key);
button.addActionListener(numberListener);
button.setFont(BIGGER_FONT);
buttonPanel.add(button);
}
}
ActionListener operatorListener = new OperatorListener();
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 4, 4, 4));
String[] opOrder = {"+", "-", "*", "/","=","C"};
for (int i = 0; i < opOrder.length; i++) {
JButton button = new JButton(opOrder[i]);
button.addActionListener(operatorListener);
button.setFont(BIGGER_FONT);
panel.add(button);
}
JPanel pan = new JPanel();
pan.setLayout(new BorderLayout(4, 4));
pan.add(textfield, BorderLayout.NORTH );
pan.add(buttonPanel , BorderLayout.CENTER);
pan.add(panel , BorderLayout.EAST );
this.setContentPane(pan);
this.pack();
this.setTitle("Calculator");
this.setResizable(false);
}
private void action() {
number = true;
textfield.setText("0");
equalOp = "=";
op.setTotal("0");
}
class OperatorListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (number) {
action();
textfield.setText("0");
} else {
number = true;
String displayText = textfield.getText();
if (equalOp.equals("=")) {
op.setTotal(displayText);
} else if (equalOp.equals("+")) {
op.add(displayText);
} else if (equalOp.equals("-")) {
op.subtract(displayText);
} else if (equalOp.equals("*")) {
op.multiply(displayText);
} else if (equalOp.equals("/")) {
op.divide(displayText);
}
textfield.setText("" + op.getTotalString());
equalOp = e.getActionCommand();
}
}
}
class NumberListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
String digit = event.getActionCommand();
if (number) {
textfield.setText(digit);
number = false;
} else {
textfield.setText(textfield.getText() + digit);
}
}
}
public class CalculatorOp {
private int total;
public CalculatorOp() {
total = 0;
}
public String getTotalString() {
return ""+total;
}
public void setTotal(String n) {
total = convertToNumber(n);
}
public void add(String n) {
total += convertToNumber(n);
}
public void subtract(String n) {
total -= convertToNumber(n);
}
public void multiply(String n) {
total *= convertToNumber(n);
}
public void divide(String n) {
total /= convertToNumber(n);
}
private int convertToNumber(String n) {
return Integer.parseInt(n);
}
}
}
Its output result is as follows:
Create Database with Netbeans Program and Ms.Access
by Son Rokhaniawan Perdata, S.T | 11:32 PM in Database, Project | comments (0)
Hi all readers, this project we will create a database program using Netbeans IDE 6.5 Database and Ms.Access. Software may Netbeans is new for us. Yes the actual program Netbeans is a software used to create a program based on JAVA. We still use the first appearance of white Notepad to create JAVA applications. Akan NotePad but parallel development is replaced by slow start because TEXTPAD facilities provided by this TEXTPAD seems more complete and informative than the notepad. But when we look kebelakang shortages have appeared TEXTPAD again, that is we still have to type the script to make the program components. And that lack is covered by the Netbeans this. Namely to provide component parts without having to type the script to make the withdrawal other GUI Programming Languages. You can create our new project, we:
Here the view that the program will be created:
The Steps:
***> Create database tables and cooperation with the Member as follows:
==================================================================
Noang - Text - 5
Nama - Text - 25
Alamat - Text - 30
Jkel - Yes/no
Agama - Text - 1
NoKTP - Text - 15
NoTelp - Text - 12
Simpanan - Number - LongInt
============================================================1. Create a design form as shown in the picture. In the form there is a component JTextField, JComboBox, JRadioButton, JPanel, JButton.
2. Change the name of the components that we have entered, especially for components JTextField, JComboBox, JButton, JRadioButton engan way and conditions as follows:
Component Component Name Changes
JTextField No Anggota — no
JTextField Nama — nama
JTextField Alamat — alamat
JComboBox Agama — agama
JRadioButton Jkel — RPria dan RWanita
JTextField No KTP — noktp
JTextField No. Telp — notelp
JTextField Simpanan — simpanan
JButton Simpan — bsimpan
JButton Data Baru — bbaru
JButton Keluar — bkeluar
3. After you change the name of each component so it's time to process incoming Coding.
Program Code:
- Below the tab name of your project, click the source:
Under the package type you import the following command to retrieve the sql commands.
=======================================================
import java.sql;
=======================================================
- The declaration of a variable connection, resultset, statement and the other variables that are required
Public under the following class type variables;
=======================================================
//deklarasi variabel global
Connection Con;
ResultSet RsAng;
Statement StatAng;
//variabel for agama
String sagm = “1″;
//variabel for jenis kelamin
Boolean bjkel = true;
//variabel global where data ditemukan
Boolean ada = false;
- Then, under public nama_project (under the introduction of a variable) type the command database connection and table below:
//connection
try
{
String fdata = “z:\\java1\\NetBeans\\Koperasi.mdb”;
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
// direct connection to the database without dsn
Con= DriverManager.getConnection(”jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=” + fdata);
//shows the search process can be in the resultset update
StatAng= Con.createStatement( RsAng.TYPE_SCROLL_SENSITIVE, RsAng.CONCUR_UPDATABLE );
RsAng = StatAng.executeQuery(”Select* from Anggota”);
}
catch(Exception e)
{ System.err.println(”Conection error !” + e.getMessage()); } //getMessage to display the message
- After the connection is successful then the time we go to the key store. Type the following code:
================================================== ====
private void bsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
RsAng.updateString(”Noang”, no.getText());
RsAng.updateString(”Nama”, nama.getText());
RsAng.updateString(”Alamat”, alamat.getText());
RsAng.updateString(”Agama”, sagm);
RsAng.updateBoolean(”Jkel”, bjkel);
RsAng.updateString(”NoKTP”, noktp.getText());
RsAng.updateString(”NoTelp”, notelp.getText());
RsAng.updateDouble(”Simpanan”, Double.parseDouble(simpanan.getText()));
if(ada)
{
//mengedit data yang sudah ada
RsAng.updateRow();
javax.swing.JOptionPane.showMessageDialog(null, “Data Telah Diedit !”);
}
else
//menyisipkan record baru
RsAng.insertRow();
javax.swing.JOptionPane.showMessageDialog(null, “Data Telah Tersimpan !”);
}
catch(Exception e)
{
javax.swing.JOptionPane.showMessageDialog(null, “Data Belum Tersimpan !” + e.getMessage());
}
}
======================================================- Code Programs for RadioButton Male:
======================================================
private void RPriaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bjkel = true;
}
======================================================- Code Programs for Women's RadioButton:
======================================================
private void RWanitaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bjkel = false;
}
=====================================================- To type a ComboBox in the code the program:
=====================================================
private void agamaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Baca Source objectnya masih JcomboBox
javax.swing.JComboBox soagama = (javax.swing.JComboBox)evt.getSource();
//Membaca Item Yang Terpilih — > String
String sagama = (String)soagama.getSelectedItem();
//pengujian sagama
if (sagama.equals(”Islam”))
sagm = “1″;
else if (sagama.equals(”Kristen”))
sagm = “2″;
else if (sagama.equals(”Hindhu”))
sagm = “3″;
else if (sagama.equals(”Budha”))
sagm = “4″;
else if (sagama.equals(”Konghu Chu”))
sagm = “5″;
}
==========================================================================================================
private void bbaruActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no.setText(”");
nama.setText(”");
alamat.setText(”");
noktp.setText(”");
notelp.setText(”");
simpanan.setText(”");
}
=====================================================- To Exit Button component type in the code the program:
=====================================================
private void bkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Tutup Koneksi
try
{
Con.close();
RsAng.close();
StatAng.close();
Con = null; RsAng = null; StatAng = null;
}
catch (Exception e){}
System.exit(0);
}
====================================================Additional notes (rusted Bos)
- To fill the ComboBox religion you click on the ComboBox component on the properties and religious search model, then click the dialog box will appear as follows:
NetBeans IDE Java Quick Start Tutorial (Hello Word)
by Son Rokhaniawan Perdata, S.T | 11:10 AM in Netbeans, Project, Tutorial | comments (0)
This tutorial provides a very simple and quick introduction to the NetBeans IDE workflow by walking you through the creation of a simple "Hello World" Java console application. Once you are done with this tutorial, you will have a general knowledge of how to create and run applications in the IDE.
This tutorial takes less than 10 minutes to complete.
After you finish this tutorial, you can move on to the learning trails, which are linked from the Documentation, Training & Support page. The learning trails provide comprehensive tutorials that highlight a wider range of IDE features and programming techniques for a variety of application types. If you do not want to do a "Hello World" application, you can skip this tutorial and jump straight to the learning trails.
To complete this tutorial, you need the following software and resources.
Software or Resource | Version Required |
---|---|
NetBeans IDE | version 6.5 |
Java Development Kit (JDK) | version 6 or version 5 |
Setting Up the Project
To create an IDE project:
- Start NetBeans IDE.
- In the IDE, choose File > New Project (Ctrl-Shift-N), as shown in the figure below.
New Project menu item selected." class="margin-around" height="85" width="199">
- In the New Project wizard, expand the Java category and select Java Application as shown in the figure below. Then click Next.
- In the Name and Location page of the wizard, do the following (as shown in the figure below):
- In the Project Name field, type
HelloWorldApp
. - Leave the Use Dedicated Folder for Storing Libraries checkbox unselected.
- In the Create Main Class field, type
helloworldapp.HelloWorldApp
. - Leave the Set as Main Project checkbox selected.
- In the Project Name field, type
- 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
open. - The Navigator window, which you can use to quickly navigate between elements within the selected class.
- The Tasks window, which lists compilation errors as well other tasks that are marked with keywords such as XXX and TODO.
Adding Code to the Generated Source File
Because you have left the Create Main Class checkbox selected in the New Project wizard, the IDE has 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 herewith the line:
System.out.println("Hello World!");
Save the change by choosing File > Save.
The file should look something like the following code sample.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package helloworldapp;
/**
*
* @author Patrick Keegan
*/
public class HelloWorldApp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Compiling and Running the Program
Because of the IDE's Compile on Save feature, you do not have to manually compile your project in order to run it in the IDE. When you save a Java source file, the IDE automatically compiles it.
To run the program:
- Choose Run > Run Main Project (F6).
The next figure shows what you should now see.
Congratulations! Your program works!
If there are compilation errors, they are marked with red glyphs in the left and right margins of the Source Editor. The glyphs in the left margin indicate errors for the corresponding lines. The glyphs in the right margin show all of the areas of the file that have errors, including errors in lines that are not visible. You can mouse over an error mark to get a description of the error. You can click a glyph in the right margin to jump to the line with the error.
Building and Deploying the Application
Once you have written and test run your application, you can use the Clean and Build command to build your application for deployment. When you use the Clean and Build command, the IDE runs a build script that performs the following tasks:
- Deletes any previously compiled files and other build outputs.
- Recompiles the application and builds a JAR file containing the compiled files.
To build your application:
- Choose Run > Clean and Build Main Project (Shift-F11).
You can view the build outputs by opening the Files window and expanding the HelloWorldApp node. The compiled bytecode file HelloWorldApp.class
is within the build/classes/helloworldapp
subnode. A deployable JAR file that contains the HelloWorldApp.class
is within the dist
node.
NetBeans IDE Installation Guide
by Son Rokhaniawan Perdata, S.T | 10:58 AM in Guide, Netbeans | comments (0)
Windows
On Microsoft Windows platforms, you can pick from one of the following downloads:
- Self-extracting installer
- Archive distribution
Once you have downloaded the installer file, double-click the file to start the installation wizard. The installer enables you to specify:
- the Java™ 2 Software Development Kit to run the IDE on.
- which directory to install NetBeans IDE into.
- whether to associate .java and .nbm (NetBeans module files) with the IDE.
- Double-click the NetBeans IDE icon on your desktop.
- Select NetBeans IDE | NetBeans IDE 3.6 | NetBeans IDE from the Start menu.
While the installer described above is the preferred method of installation on Microsoft Windows machines, you can also install NetBeans IDE using a tar.gz or zip file. Common archive utilities like Winzip can work with both of these file types.
To install NetBeans IDE:
- Locate the archive that you have downloaded and double-click it to open your archive file tool.
- Using your archive tool, extract all files to an empty directory, such as C:\NetBeans IDE 3.6.
- Navigate to the bin subdirectory of your NetBeans IDE installation.
- Double-click runide.exe to start NetBeans IDE.
On the Solaris and Linux platforms, you can pick from one of the following downloads:
- Binary installer
- Archive distribution
To install NetBeans IDE:
- From a command prompt, navigate to the directory that contains the installer.
- If necessary, change the permissions to make the binary executable by typing $ chmod +x NetBeans.bin (replacing NetBeans.bin with the actual filename of the distribution that you downloaded).
- Start the installer by typing $ ./NetBeans.bin (replacing NetBeans.bin with the actual filename of the distribution that you downloaded).
$ ./NetBeans.bin -is:javahome path_to_your_jdk
Using Archive Installations on UNIX® platforms
To install NetBeans IDE:, use the appropriate tools on your platform to untar or unzip the archive distribution to a clean directory. For example, type the following from a command prompt:
$ gzip -d NetBeans.tar.gz
$ tar xf NetBeans.tar
(replacing NetBeans.tar.gz and NetBeans.tar with the actual file names).
Note: Solaris users should use GNU tar for tar.gz files to ensure that the whole archive is unpacked.
To launch NetBeans IDE, change directories to the bin subdirectory of your installation and execute the runide.sh launcher script.
Macintosh OS X
On the Macintosh OS X platform, you can pick from one of the following downloads:
- Disk image format (.dmg) file
- Archive distribution
Using the disk image format (.dmg) file
Once you have downloaded the image file, double-click the file to mount the file in your system.
To launch NetBeans IDE, run the NetBeansLauncher application.
Using Archive Installations on the Mac OS platform
To install NetBeans IDE:
- Open the Terminal application and change directories to where you would like to install the IDE. On the command line type:
gnutar -xvzf netbeans.tar.gz
(replacing NetBeans.tar.gz with the actual filename of the distribution that you downloaded).
To launch NetBeans IDE, change directories to the bin subdirectory of your installation and execute the runide.sh launcher script.
Other Operating Systems
Using Archive Installations
Unpack your archive using the utilities appropriate for your system.
To launch NetBeans IDE, navigate to the bin subdirectory of your NetBeans IDE installation and execute the launcher that is appropriate for your system. The following launchers are available:
runide.exe - Windows
runidew.exe - Windows (no console window)
runide.sh - UNIX
runideos2.cmd - OS/2
runideopenvms.com - OpenVMS
If there is no launcher for your specific operating system, you might need to try to create one by modifying whatever script is most appropriate. If your machine supports JDK 1.4 or greater, you should be able to run the IDE.
Note: If you create a launcher, you could contribute it to the project.
Installing on beta versions of Java™ 2 Software Development Kit (J2SDK), v. 1.5
You can run the IDE on betas of J2SDK v. 1.5, but the installer will not run if that is the only J2SDK that you have on your system. You must also have J2SDK v. 1.4.1 or compatible installed to run the installer. Once the installer is running, you can specify that the IDE should run on J2SDK v. 1.5 beta.
1. What is NetBeans?
NetBeans is an open-source Integrated Development Environment (IDE) you can download and use for free. NetBeans is also an extensible platform which you can use to build OS-independent applications. Finally, NetBeans is a thriving open-source community with hundreds of thousands of experienced developers located all around the world. More information.
2. How Do I Get Started?
Download the NetBeans IDE. It has everything you need develop world-class applications. NetBeans software is a 100% Java-based IDE and platform, so it works on every OS where the JDK is available. NetBeans supports a wide range of Java technologies, but is not limited to Java - other languages are supported as well. The NetBeans tools have so much functionality, you can choose which download is best for you. Learn more about supported technologies and features on the features page. You can add more functionality with plug-in modules (in the IDE, choose Tools > Plugins).
3. Where Can I Get Involved?
There is a thriving worldwide community of NetBeans users out there, ranging from new users to gurus. Join them to discuss tips and tricks, NetBeans features, problem solving and much more. Sign up now!
4. How Do I Learn More?
There is a wealth of knowledge here on netbeans.org to get your teeth into, with new content being posted weekly. Tutorials, articles, guides, demos and screencasts.
Welcome! We hope your visit is pleasant.
Java technology is both a programming language and a platform.
The Java Programming Language
The Java programming language is a high-level language that can be characterized by all of the following buzzwords:
- Simple
- Architecture neutral
- Object oriented
- Portable
- Distributed
- High performance
- Multithreaded
- Robust
- Dynamic
- Secure
In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes — the machine language of the Java Virtual Machine1 (Java VM). The java launcher tool then runs your application with an instance of the Java Virtual Machine.
Figure showing MyProgram.java, compiler, MyProgram.class, Java VM, and My Program running on a computer.
An overview of the software development process.
Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris TM Operating System (Solaris OS), Linux, or Mac OS. Some virtual machines, such as the Java HotSpot virtual machine, perform additional steps at runtime to give your application a performance boost. This include various tasks such as finding performance bottlenecks and recompiling (to native code) frequently used sections of code.
Figure showing source code, compiler, and Java VM's for Win32, Solaris OS/Linux, and Mac OS
Through the Java VM, the same application is capable of running on multiple platforms.
The Java Platform
A platform is the hardware or software environment in which a program runs. We've already mentioned some of the most popular platforms like Microsoft Windows, Linux, Solaris OS, and Mac OS. Most platforms can be described as a combination of the operating system and underlying hardware. The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms.
The Java platform has two components:
- The Java Virtual Machine
- The Java Application Programming Interface (API)
The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages. The next section, What Can Java Technology Do? highlights some of the functionality provided by the API.
Figure showing MyProgram.java, API, Java Virtual Machine, and Hardware-Based Platform
The API and Java Virtual Machine insulate the program from the underlying hardware.
As a platform-independent environment, the Java platform can be a bit slower than native code. However, advances in compiler and virtual machine technologies are bringing performance close to that of native code without threatening portability.
The terms"Java Virtual Machine" and "JVM" mean a Virtual Machine for the Java platform.