Free Essay

Hello World Java Program

In:

Submitted By stombock
Words 251
Pages 2
Description of Code:
This code will generate a pop up box that will include the text “Hello, World!” and will also include a JButton that says “Exit”. On mouse clicking the JButton, the box will terminate from the screen.

Pseudocode:

Import Java API's

Create public class HelloWorld

Create main function (String[] args) new JFrame frame "Week 1 Assignment" frame Set default close operation new JLabel label "Hello World" label set preferred size 325,100 label set to CENTER add label to frame pack frame new JPanel panel add frame to panel new JButton button “Exit” set label alignment to CENTER set button alignment to CENTER set Layout to BoxLayout set frame to visible set frame visible set frame size 350,200 add ActionListener to button

public void actionPerformed System.exit (0) – Close program upon clicking Exit button

Actual Code portion of paper:

import javax.swing.*; import java.awt.Component; import java.awt.event.*; import javax.swing.JFrame;

public class HelloWorld
{

public static void main(String[] args) { JFrame frame = new JFrame("Week 1 Assignment"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Hello, World!"); JPanel panel = new JPanel (); JButton button = new JButton("Exit"); label.setAlignmentX(Component.CENTER_ALIGNMENT); label.setAlignmentY(Component.CENTER_ALIGNMENT); button.setAlignmentX(Component.CENTER_ALIGNMENT); button.setAlignmentY(Component.CENTER_ALIGNMENT); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(Box.createVerticalGlue()); panel.add(label); panel.add(Box.createVerticalGlue()); panel.add(button); frame.add(panel); frame.setVisible(true); frame.setSize(350,200); button.addActionListener(new ActionListener()

{ public void actionPerformed(ActionEvent e) { System.exit(0); } }); }
}

Similar Documents

Premium Essay

Asdsada

...UNIVERSITY College of Computer Studies Introduction to Programming Activity Book Compiled by: Mark Godfrey D. Torres 2012 Introduction to Programming ii Table of Contents Weeks 1 to 3 – Creating Your First Java Classes ....................................................................................... 1 Objectives ........................................................................................................................................... 1 Summary ............................................................................................................................................ 1 The Don’ts........................................................................................................................................... 2 Key Terms ........................................................................................................................................... 3 Seatwork............................................................................................................................................. 6 Where to Save Your Files ................................................................................................................. 6 Configuring Windows to Work with the Java SE Development Kit................................................... 6 Your First Application ...................................................................................................................... 8 Adding...

Words: 4647 - Pages: 19

Premium Essay

Java

...Software Design Introduction to the Java Programming Language Material drawn from [JDK99,Sun96,Mitchell99,Mancoridis00] Software Design (Java Tutorial) © SERG Java Features • “Write Once, Run Anywhere.” • Portability is possible because of Java virtual machine technology: – Interpreted – JIT Compilers • Similar to C++, but “cleaner”: – No pointers, typedef, preprocessor, structs, unions, multiple inheritance, goto, operator overloading, automatic coercions, free. Software Design (Java Tutorial) © SERG Java Subset for this Course • We will focus on a subset of the language that will allow us to develop a distributed application using CORBA. • Input and output will be character (terminal) based. • For detailed treatment of Java visit: – http://java.sun.com/docs/books/tutorial/index.html Software Design (Java Tutorial) © SERG Java Virtual Machine • Java programs run on a Java Virtual Machine. • Features: – – – – – Security Portability Superior dynamic resource management Resource location transparency Automatic garbage collection Software Design (Java Tutorial) © SERG The Java Environment Java Source File (*.java) Java Compiler (javac) Java Bytecode File (*.class) Java Virtual Machine (java) Software Design (Java Tutorial) © SERG Program Organization Source Files (.java) Running Application Running Applet JAVA BYTECODE COMPILER Class Files (.class) JAVA VIRTUAL MACHINE WEB BROWSER Software Design (Java Tutorial) © SERG Program Organization Standards • Each class...

Words: 5230 - Pages: 21

Premium Essay

Bout This

...Pasig campus pangilinan DSITI-AI Oct 27 15 Java Programming java programming Introduction in java programming Objectives * Object-Oriented Programming Language * Object-Oriented Programming Principle * Benefits Of Object-Oriented Programming * Introduction To Java Programming * Resources Used To Create a Java Programming *Structures Of a Java Programming * Result Of Executing The Java Programing Object Oriented Programming Language (OOPL) OOPL Is An Extension Of Procedural Language. Involves Creating Program Components as Object Related To The Real Word. Writing Object-Oriented Programs Involves Creating Object And Application That Uses Those Objects. An Object Contains Both Data Procedures Can be packaged Into a Single Unit. Based On Three Concepts Encapsulation Ability To Bind Data And Procedures Into an Object. Inheritance Ability Of Objects To Acquire The Attributes Or Behavior Of Other Objects Or Classes. Polymorphism Ability of An Object To Take Many Forms Or Identities. Benefits Of Object-Oriented Programming *Reusability -Able To Reuse The Defined Objects. *Adaptability –Able to fit in different environment. *maintainability –Able to change easily. *reliability –Able to operate...

Words: 1445 - Pages: 6

Premium Essay

Unit 2 Research Assignment

...Research Assignment Java is a general-purpose, concurrent, class-based, object-oriented computer programming language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. Strengths:WORA, popularity Weaknesses: Slower than natively compiled languages Sample syntax: class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); } } C++ is a programming language that is general purpose, statically typed, free form, multi-paradigm and compiled. It is regarded as an intermediate-level language, as it comprises both high-level and low-level language features. Developed by Bjarne Stroustrup starting in 1979 at Bell Labs, C++ was originally named C with Classes, adding object oriented features, such as classes, and other enhancements to the C programming language. The language was renamed C++ in 1983, as a pun involving the increment operator. Strengths:Speed Weaknesses: Older and considered clumsy if compared to Java Sample syntax: #include using namespace std; void main(){ cout << "Hello World!"; } C# is a multi-paradigm programming language encompassing...

Words: 477 - Pages: 2

Premium Essay

Report

...By : Aniket Pataskar INDEX 1. Hello World example 3 2. Add two matrices 4 3. Armstrong number 7 4. Binary Search 11 5. Bubble sort 14 6. Command line arguments 17 7. Find Odd or Even 18 8. Convert Fahrenheit to Celsius 21 9. Display Date and Time 23 10.Largest of three integers 26 11. Java Programs part 1 28 12. Java Programs part 2 49 13. Java Programs part 3 74 14. Java Programs part 4 102 15. Java Programs part 5 120 16. Java Programs part 6 134 17. Java Interview Questions part 1 161 18. Java Interview Questions part 2 178 “Hello World” is passed as an argument to println method, you can print whatever you want. There is also a print method which doesn’t takes the cursor to beginning of next line as println does. System is a class, out is object of PrintStream class and println is the method. Output of program: Output of program: This code adds two matrix, you can modify it to add any number of matrices. You can create a Matrix class and create it’s objects and then create an add method which sum the objects, then you can add any number of matrices by repeatedly calling the method using a loop. Output of program: Other methods of searching are Linear search and Hashing. There is a binarySearch method in Arrays class which can also be used. binarySearch method returns the location if a match occurs otherwise - (x+1) where x is the no. of elements in the array, For example in the second case above when p is not present...

Words: 1056 - Pages: 5

Free Essay

Java Outlines

...NJE VESHTRIM MBI JAVA JAVA eshte nje gjuhe programimi e orientuar ne objekte e cila eshte projektuar dhe zhvilluar nga ekipi i drejtuar nga James Gosling ne Sun Microsystems. Prezantohet zyrtarisht ne fund te vitit 1995. Ne ditet e sotme eshte nje nga gjuhet me te perdorura ne fushen e zhvillimit te software. Gjate projektimit te JAVA-s, qellimet kryesore ishin: Perdorimi i metodologjise se programimit te orientuar ne objekte. Te beje te mundur qe i njejti program te ekzekutohet ne sisteme operative te ndryshme. Te mbeshtese ne stilin “built-in” rrjetat kompjuterike. Te mundesoje ekzekutimin ne menyre te sigurt kodin nga kompjutera te ndodhur larg (secure remote execution ). Te mundesoje perdorimin e pjeseve nga gjuhe me te vjetra te programimit si C++ etj. Programet ne JAVA perbehen nga pjese te cilat quhen klasa (class). Klasat perbehen nga pjese qe quhen metoda (methods) te cilat kryejne detyra te caktuara dhe kthejne informacion kur i perfundojne ato. JAVA te jep mundesine te programosh çfaredo pjese qe mund te ju nevojitet kur ju formoni nje program. Gjithsesi te gjithe programuesit ne JAVA preferojne te mos e programojne gjithçka nga zeroja, por te shfrytezojne koleksionin e pasur te klasave ekzistuese ne Java Class Libraries (Bibliotekat e klasave te Javas), qe njihen gjeresisht si Java API’s (Application Programming Interfaces). Mund te themi qe programimi ne Java perbehet nga dy pjese te rendesishme: Programimi i klasave te projektuara nga vete programuesi. Perdorimi...

Words: 4563 - Pages: 19

Free Essay

Software Testing Tools Survey

...Concordion 1. Who (company or individual) developed the tool? What is the cost to the tool user? How do you acquire it? Concordion was developed by David Peterson, an agile consultant from London, UK. While working at Easynet in 2006, the idea was formed with testers and developers Nat Pryce and Steve Freeman. Concordion was then later ported and improved upon by several developers, specifically Nigel Charman, the designer of the Concordion Extensions API. The Concordion tool is available for free at concordion.org/Download.html. 2. What testing purpose does the tool serve? (i.e., what problem does it attempt to solve? How does it improve productivity?) Concordion is an open source tool that is used for the automation of Specification by Example. Using simple HTML, developers can create concrete examples in any specifications with certain commands. This allows for Concordion to check the examples against a real-life system. The specifications allow for complete cover of any behavior important to a customer. Based on this, specifications can be used as unit tests. Concordion specifications are also clear and readable so they can also serve as system documentation. This means a project’s specifications can be easy to understand for the development team, as well as anyone outside it. This would ultimately allow for a better maintenance of software quality as the software can be reviewed as a group effort. 5. What do you need to do in order to use the tool? There...

Words: 1393 - Pages: 6

Free Essay

Java Applet

...Applet Java Applets were created when the Internet was becoming popular with educational institutions, businesses and consumers. Java Applets were originally meant to be part of products from the cable company, but developers of Java Applets could not convince the cable industry to use their invention. Java Applets were created by programmers at Sun in 1995. They were James Gosig, Patrick Naughton and Mike Sheridan who called themselves the Green Team. Java Applets share some similarities with the java programming language. Java is text and characters that is written as instructions. A programmer is the person who writes the instructions on the computer. The computer will not perform an action without getting instructions from the person who writes the instructions. The java programming language allows a programmer to use the same code on both a personal computer and a Macintosh. The same rule applies to a Web browser. The programmer who creates web pages is called the web master. The web master uses hypertext markup language to create a webpage. In order for the webpage images to move an applet is added. An applet is a small application that is placed inside the hypertext markup language. The most popular web browsers in the 1990s were Netscape and Mosaic. Both browsers displayed still images and text. Java applets allowed the programmer to write applications for the web. For the first time, using Java Applets, images could move. Animation allowed webpages to come alive....

Words: 2297 - Pages: 10

Premium Essay

Hello World

..."Hello World" redirects here. For the Iamus (computer) composition, see Hello World! (composition). For the 2009 compilation album by Michael Jackson, see Hello World: The Motown Solo Collection. For the song by Lady Antebellum, see Hello World (song). A GUI "Hello World" program, written in Perl It is possible to execute unsigned code on Sony's PlayStation Portable. A light-programmable biofilm displaying the Hello World message CNC machining test in Perspex A "Hello world" program is a computer program that outputs "Hello, world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to verify that a language or system is operating correctly. In a device that does not display text, a simple program to produce a signal, such as turning on an LED, is often substituted for "Hello world" as the introductory program. Contents [hide] 1 Purpose 2 History 3 Variations 4 See also 5 References 6 External links [edit]Purpose A "Hello World" program has become the traditional first program that many people learn. In general, it is simple enough so that people who have no experience with computer programming can easily understand it, especially with the guidance of a teacher or a written guide. Using this simple program as a basis, computer science principles or elements of a specific programming...

Words: 863 - Pages: 4

Free Essay

Khan

...distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher. 0-07-159989-4 The material in this eBook also appears in the print version of this title: 0-07-159988-6. All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps. McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. For more information, please contact George Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 904-4069. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior...

Words: 43266 - Pages: 174

Premium Essay

Java Programming Language Sl-275

...Sun Educational Services Java Programming Language SL-275 Sun Educational Services Java Programming Language September 1999 Copyright 1999 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California 94303, U.S.A. All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun Logo, Solstice, Java, JavaBeans, JDK, and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. The OPEN LOOK and Sun Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the...

Words: 6064 - Pages: 25

Free Essay

Analiza I Dizajn

...JAVA – PRIRUČNIK ZA PROGRAMIRANJE Da biste pisali i izvršavali Java programe, potreban vam je Java Software Development Kit (Java SDK). To je besplatan proizvod koji možete preuzeti preko Interneta. To jednostavno znači da ćete iskopirati tzv. instalacionu datoteku na svoj računar, pokrenuti instalaciju i zatim početi sa radom. Ovaj proizvod možete naći na adresi http://java.sun.com. Proces pravljenja i izvršavanja Java programa ima tri jasno razdvojene etape: • Pisanje programa • Kompajliranje (prevođenje) programa (generiše se datoteka koju računar može da razume) • Izvršavanje programa. Za sada, ne brinite se mnogo oko toga šta se tačno dešava u svakoj od ovih etapa. Jedan od načina da kompletirate ove tri etape je da prvo pišete program koristeći neki osnovni editor teksta i snimite dobijeni tekst u datoteku. Potom, etape kompajliranja i izvršavanja mogu se obaviti kucajući u komandnoj liniji posebnih komandi predviđenih za te etape. Mali broj Java programera piše programe na taj način. Skoro svi programeri razvijaju svoje programe koristeći tzv. Integrisano razvojno okruženje (Integrated Development Environment – IDE). Postoji više IDE proizvoda za razvoj Java programa., neki su veoma složeni, a neki veoma prosti. Mi ćemo koristiti verziju koja je besplatna. Radi se o kruženju koje se naziva JCreator. Radi se o interfejsu koji se lako koristi a može besplatno (verzija Lite) da se preuzme preko Interneta. Preporučujem da koristite ovaj softver zato...

Words: 19482 - Pages: 78

Premium Essay

Developer

...Programming--Malone Basics of Java Programming (A Work In Progress) What Constitutes a Java Program? A Java program consists of one or more source files. Each source file is called .java, where is the name of the class contained in that source file and .java is the extension that identifies the file as a Java source code file. In general, each source file contains one class. The name of the class must match the name of the file (without the extension) exactly. To execute a Java program, you first need to compile the source code into byte code. Byte code files have the name .class. If you’re working from the shell, this is done using the javac command (where “c” is for compiler). Usually we will be compiling using the Xcode IDE. Once compiled, the program is executed using the Java interpreter (a.k.a. the Java Virtual Machine or JVM). From the shell, the JVM is invoked with the “java” command. Again we will usually be doing this with the Build and Go or Debug options of the Xcode IDE. A Java program must have a routine called main(), which is the starting point for program execution. main() will always look something like this: public static void main (String args[]) { // insert code here... System.out.println("Hello World!"); } Source Code Formatting Keep in mind the following when writing Java source code: Java is case sensitive (“foo”, “Foo”, and “fOO” are all considered to be different in Java). • Every line of code in Java must end in a semi-colon (“;”). • Java doesn’t care about white...

Words: 968 - Pages: 4

Free Essay

Sample

...Java Server Faces (JSF) Tutorial JAVA SERVER FACES TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Java Server Faces Tutorial JavaServer Faces (JSF) is a Java-based web application framework intended to simplify development integration of webbased user interfaces. JavaServer Faces is a standardized display technology which was formalized in a specification through the Java Community Process. This tutorial will teach you basic JSF concepts and will also take you through various advance concepts related to JSF framework. Audience This tutorial has been prepared for the beginners to help them understand basic JSF programming. After completing this tutorial you will find yourself at a moderate level of expertise in JSF programming from where you can take yourself to next levels. Prerequisites Before proceeding with this tutorial you should have a basic understanding of Java programming language, text editor and execution of programs etc. Because we are going to develop web based applications using JSF, so it will be good if you have understanding on other web technologies like, HTML, CSS, AJAX etc. Copyright & Disclaimer Notice  All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation...

Words: 11815 - Pages: 48

Free Essay

Gwt Tutorial

...tutorial content contains some errors, please contact us at webmaster@tutorialspoint.com ii ABOUT THE TUTORIAL GWT Tutorial Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. GWT is used by many products at Google, including Google AdWords and Orkut. GWT is open source, completely free, and used by thousands of developers around the world. It is licensed under the Apache License version 2.0. This tutorial will give you great understanding on GWT concepts needed to get a web application up and running. Audience This tutorial is designed for Software Professionals who are willing to learn GWT Programming in simple and easy steps. This tutorial will give you great understanding on GWT Programming concepts and after completing this tutorial you will be at intermediate level of experties from where you can take yourself at higher level of expertise. Prerequisites Before proceeding with this tutorial you should have a basic understanding of Java programming language, text editor and execution of programs etc. Because we are going to develop web based applications usin GWT, so it will be good if you have...

Words: 14136 - Pages: 57