NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Prints the string to the console.
}
}

// OddEven.java
import javax.swing.JOptionPane;

public class OddEven {

private int userInput; // a whole number("int" means integer)

/**
* This is the constructor method. It gets called when an object of the OddEven type
* is being created.
*/
public OddEven() {
/*
* In most Java programs constructors can initialize objects with default values, or create
* other objects that this object might use to perform its functions. In some Java programs, the
* constructor may simply be an empty function if nothing needs to be initialized prior to the
* functioning of the object. In this program's case, an empty constructor would suffice.
* A constructor must exist; however, if the user doesn't put one in then the compiler
* will create an empty one.
*/
}

/**
* This is the main method. It gets called when this class is run through a Java interpreter.
* @param args command line arguments (unused)
*/
public static void main(final String[] args) {
/*
* This line of code creates a new instance of this class called "number" (also known as an
* Object) and initializes it by calling the constructor. The next line of code calls
* the "showDialog()" method, which brings up a prompt to ask you for a number.
*/
OddEven number = new OddEven();
number.showDialog();
}

public void showDialog() {
/*
* "try" makes sure nothing goes wrong. If something does,
* the interpreter skips to "catch" to see what it should do.
*/
try {
/*
* The code below brings up a JOptionPane, which is a dialog box
* The String returned by the "showInputDialog()" method is converted into
* an integer, making the program treat it as a number instead of a word.
* After that, this method calls a second method, calculate() that will
* display either "Even" or "Odd."
*/
userInput = Integer.parseInt(JOptionPane.showInputDialog("Please enter a number."));
calculate();
} catch (final NumberFormatException e) {
/*
* Getting in the catch block means that there was a problem with the format of
* the number. Probably some letters were typed in instead of a number.
*/
System.err.println("ERROR: Invalid input. Please type in a numerical value.");
}
}

/**
* When this gets called, it sends a message to the interpreter.
* The interpreter usually shows it on the command prompt (For Windows users)
* or the terminal (For *nix users).(Assuming it's open)
*/
private void calculate() {
if ((userInput % 2) == 0) {
JOptionPane.showMessageDialog(null, "Even");
} else {
JOptionPane.showMessageDialog(null, "Odd");
}
}
}

// Hello.java
import javax.swing.JApplet;
import java.awt.Graphics;

public class Hello extends JApplet {
public void paintComponent(final Graphics g) {
g.drawString("Hello, world!", 65, 95);
}
}

<html>
<head>
<title>Hello World Applet</title>
</head>
<body>
<applet code="Hello.class" width="200" height="200">
</applet>
</body>
</html>

// Hello.java
import java.io.*;
import javax.servlet.*;

public class Hello extends GenericServlet {
public void service(final ServletRequest request, final ServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
final PrintWriter pw = response.getWriter();
try {
pw.println("Hello, world!");
} finally {
pw.close();
}
}
}

// Hello.java (Java SE 5)
import javax.swing.*;

public class Hello extends JFrame {
public Hello() {
super("hello");
super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
super.add(new JLabel("Hello, world!"));
super.pack();
super.setVisible(true);
}

public static void main(final String[] args) {
new Hello();
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.