141 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for DavidKroukamp

I have seen many people struggling with Reading files and writing files in java, also a great problem is how to edit a file too. So in this code snippet I have put all these problems into one small program in hopes to help others. So this code snippet will …

Member Avatar for Bdill7
5
23K
Member Avatar for jnbgames.dev

The program below is written in **Java** and is used to develop a Web Server that supports these status codes: **200** OK, **302** Moved Temporarily, and **404** NOT FOUND. The code can emulate an **HTTP** server in your local machine. Let me know if you find the code below helpful …

Member Avatar for JamesCherrill
1
164
Member Avatar for tinstaafl

Basically this scheme uses variable offsets, but it generates the bytes on the fly. They aren't truly random, but there aren't any obvious patterns and the output passes all the NIST tests. Since a simple password can be used to do the de/encryption it is much easier to hand off …

Member Avatar for JamesCherrill
2
328
Member Avatar for thomasdoejr

Write a program using for loops to produce an R by C rectangle, where R and C are provided by the user. The following are the triangles for different values of R and C. R is the number of rows and C is the number of columns

Member Avatar for rproffitt
0
342
Member Avatar for Craig_11

The Action Driver Class when it runs it just brings up a small box with java logo and close and minimize options thats all...... I have reviewd the code over and over and my instuctor said to just review my work... I am so lost....

Member Avatar for JamesCherrill
0
128
Member Avatar for Dave Ryan

this is the task given to me guix i hope you can help me Create a program that will read the data from a file and save the output in another file 1.Create an input file named **CS122Grades**. 2.The contents of the input file should be the **names**,**midterm grades** and …

Member Avatar for rproffitt
-1
339
Member Avatar for Tom_46
Member Avatar for tinstaafl

There are times when you need to make sure your counter starts at an odd or even number. Even is pretty simple - `counter = counter + modulus(counter)`. If counter is even it stays, if it's odd it gets incremented by 1. Odd is a bit more complicated - `counter …

Member Avatar for holisticgroup19
3
4K
Member Avatar for Jose_21

[Pulsating Spirograph (Processing)](https://www.ktbyte.com/projects/project/93961/pulsating-spirograph?ref=20181212daniweb2)

Member Avatar for Reverend Jim
-1
427
Member Avatar for Jose_21

[[Depths (Made with Processing)](https://www.ktbyte.com/projects/project/94051/depths?ref=20181210daniweb)](null)

1
2K
Member Avatar for Reverend Jim

Here's an interesting little scenario. You get challenged to a game of coin toss. Both players pick a sequence of coin toss results (heads or tails). The coin is repeatedly tossed until the sequence for one of the players occurs. The loser pays the winner a dollar. You'd assume that …

Member Avatar for xrjf
0
2K
Member Avatar for JamesCherrill

This is a little discussion/example of design for modularity and re-use, inspired by javaAddict and Orlando Augusto posts in their thread “Dynamic Multidimensional Array Printing” https://www.daniweb.com/programming/software-development/code/305580/dynamic-multidimensional-array-printing That thread has 3 solutions to printing the contents of a multi-dimensional array of arbitrary dimensions - although in fact all the solutions will …

Member Avatar for JamesCherrill
1
460
Member Avatar for javaAddict

Hi All. This is my first code snippet. I don't know how practical it is, but I came up with the idea, so I wanted to do it. Assuming you have an array. You use a for loop to display its data. For 2D arrays you use 2 for loops. …

Member Avatar for JamesCherrill
0
922
Member Avatar for JamesCherrill

This class is intended as a small and simple alternative to java.util.Scanner for people in the early stages of learning Java. Unlike Scanner it has built-in error handling and retry, it throws no checked exceptions, is as tolerant as possible of variations in the format of user input, and avoids …

Member Avatar for sam_30
3
6K
Member Avatar for Trevor_5

i have to write a code that has a random number generated between 1-100 and the user has the choice to keep the number, discard the number and quit the program. and when the user quits the program displays the numbers kept and discarded, but i dont know how to …

Member Avatar for JamesCherrill
0
313
Member Avatar for james6754

Hi everyone this is my first code snippet so be gentle.. I have written a basic client/server chat program that uses multithreading for listening and sending. I welcome any improvements or discussion... Thanks James

Member Avatar for Arpit_1
2
12K
Member Avatar for JorgeM

When users interact with your web page and processes, it is important to provide them with continuous feedback. Without the feedback, a user is left wondering if you page is actually processing work, frozen, or just not working. This is especially true when incorporating Ajax requests that take more than …

2
1K
Member Avatar for himanjim

The code simply captures your working window as jpeg image and stores it in the same directory as where your java class after compiling by javac is being stored

Member Avatar for Ashan_1
0
2K
Member Avatar for mrabrar09

here where am doing mistake and program is showing error non static method cannot be refferenced to static context

Member Avatar for mrabrar09
0
218
Member Avatar for jwenting

Similarly, you can add more fields to an enum and simply provide accessor methods to retrieve them. For example you could change it to have an extra field indicating an output directory to write specific types of data to, and a getter method to return that directory.

Member Avatar for jwenting
0
245
Member Avatar for Szabi Zsoldos

**This is intented for learning purposes, feel free to study the code** Create a drawing that looks like this (pyramid) The number should be incremented with the modulus.

Member Avatar for Szabi Zsoldos
-1
526
Member Avatar for Graphix

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for Java! It uses a words file, on the bottom of this post you will see a small example of a few words. The source …

Member Avatar for JamesCherrill
2
4K
Member Avatar for sciwizeh

I made this minesweeper game earlier this summer. It shows many things, including: array use, 1D array to 2D array, gridlayout, changing the way a JButton works depending on mouse button used, floodfill, loops, GUI. slightly long, 382 lines, can probably be condensed. There is one known bug that i …

Member Avatar for sciwizeh
2
846
Member Avatar for seanbp

The server only does the basics. TODOs: The header method needs expanding. The file send method can't handle too large files. Maybe write custom buffer class since some buffering is done. Keep cache of recent files.

Member Avatar for JamesCherrill
0
1K
Member Avatar for DavidKroukamp

I have recently been interested in Java Swing and Game development, so naturally I began creating many different 2D games. During them I found myself having to rewrite much code, but eventually I decided to write some classes that would help me whenever I wanted to make a game. Here …

Member Avatar for JamesCherrill
3
2K
Member Avatar for riahc3

Hello This is a demo showing Java interacting with Daniweb's new API ( http://www.daniweb.com/api/documentation ) You introduce a member's name and it should show you the total number of posts he has made. Demo is a proof of concept: No bug checking, error checking, etc is in this code. In …

Member Avatar for peter_budo
4
875
Member Avatar for DavidKroukamp

I have seen many questions on autocompeletion for *java text components* like `JTextField` `JTextArea` `JTextEditorPane` etc. There are not many options either: 1) 3rd party library (like SwingX) 2) DIY (i.e using `DocumentListener`, `JWindow` with `JLabel` etc and a few requestFocusInWindow calls) I chose number 2 and put the code …

Member Avatar for bguild
1
1K
Member Avatar for Arman Majumder

A temperature converter GUI. Converts from Celsius to Fahrenheit and vise versa. Tests JLabels, JButtons and JTextFields. *Two separate programs, Converter and Thermometer (Thermometer Class)*

Member Avatar for robinlrandall
0
735
Member Avatar for delta_frost

The above code computes the value of a mathematical expression supplied at command line by using the concept of converting infix to postfix,then evaluating the postfix expression. Any comments are appreciated.

Member Avatar for delta_frost
0
465
Member Avatar for vegaseat
3
601

The End.