NEW 4″ Multi-Touch Android 4.0 Smart Phone Dual SIM WIFI Unlocked AT&T T-Mobile
Current Bid: $63.96
Lists of Simple Java Codes, Java Basic Program for beginners, Examples of Java sample programs and projects as well as other java Simple Programs for beginners.
This hub has the lists of Java simple codes for beginners. You can run and test it with the java compiler you have. As for me, I use netbeans and eclipse compilers, though I use netbeans more. I left some comments on few codes to be more clear. If you want to learn java more, feel free to check my other tutorials for beginners and other java source code examples. May you enjoy your coding on java.
Echoing words in Java
To output words in Java use the pre-defined function System.out.print().Here is the complete source codes for outputting word in Java.
public class Main
{
public static void main(String[] args)
{
System.out.print(“This is just an example…”);
}
}
Output:
This is just an example…
Inputting and Echoing integer and string entered by user
If the program prompt input from user their will be declaration of variables. See the source codes below:
import java.util.Scanner; //to be able to use scanner predefined function for input
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in); // input is an object and you can choose your own too.
int num1; //num1 is a variable of integer type you can change it
String word1; //word1 is a variable of string type you can change it
System.out.print(“Enter a number and I will echo it later: “);
num1=input.nextInt(); //read input for num1
System.out.print(“Enter a word and I will echo it later: “);
word1 = input.next(); //read input for word1
System.out.println(“Here is the echo of what you have entered:”);
System.out.println(“The number you have entered is: ” + num1); //echoing input to num1
System.out.println(“The word you have entered is: ” + word1); //echoing input to word1
}
}
See Also:
How to Run Java Code Online
Output:
Enter a number and I will echo it later: 88
Enter a word and I will echo it later:hello
Here is the echo of what you have entered:
The number you have entered is 88
The word you have entered is hello
These are just a very simple program in Java to view more codes I will upload more programming projects like basic arithmetic in java including addition, subtraction, multiplication, square root and some programs in OOP (Object Oriented Programming) using looping, array and function. Thanks for reading.
Updated:
Java Tutorials and Tips
Complete List of Java Tutorial Examples for Beginners
5 Important Tips to Learn Java Programming and Other Programming Languages
Basic Knowledge Required in Programming
How to Program in Java: Complete Simple Easy Steps
Java Tutorial for Beginners: A Beginners Guide on Learning Java Programming
Java Class: Learn More About Classes in Java
Java Video Tutorials
Java Programming Video Training tutorials CBT 30+ Hrs
Current Bid: $4.99
Advanced Java Programming Video Training tutorials CBT – 30+ Hrs – Master level
Current Bid: $4.99
Learn JAVA language -14h video & docs tutorials
Current Bid: $4.59
Java Books
Java Programming : From Problem Analysis to Program Design by D. S. Malik…
Current Bid: $2.99
Introduction to Java Programming, Comprehensive Version 9e by Y. Daniel Liang
Current Bid: $50.80
Other Java Source Codes
What is a Java Scanner Class and How to Use it?
What is a Static Method in Java?
Casting in Java
BufferedReader in Java
Fibonacci Java Program: Complete Program for Fibonacci Series
Count the Number of Vowels in Java String
Java Program: How to Use If Statement in Java Programming
Java Program: How to Use If-Else Statement in Java Programming
Java Program: Using Multi If and Else Statement in Java Programming
Java Source code on Adding Numbers inside the Array using For Loop
Java Program: How to Use Switch Statement in Java
Java Source codes on Adding numbers inside the Array Using Recursion
Java Program: How to Sort Numbers in Ascending Order
Java Program: How to Sort Numbers in an Array in a Descending Order
Java Program: How to Parse a String into Integer in Java Programming
Java Program: Count the Number of String Characters in Java
Java Program: Reverse String in Java Using For Loop
Java Program: Palindrome Test Java Source Code
Sample Java Program for String Tokenizer
Sample Program for JOptionpane and Java Source Code for Basic Calculator
Java Code Sample: Sort Numbers in Bubble Sort