Java Programming Cheat Sheet For Beginners - Edureka
Java Programming Cheat Sheet For Beginners - Edureka
Swatee Chand
Research Analyst at Edureka. A techno freak who likes to explore di erent...
Are you an aspiring Java developer? Well, if you are, then I bet you can make use of this Java Cheat Sheet. Java is known for its
pre-built classes and libraries and sometimes, keeping a track of them becomes a little tricky. So, here I bring you the Core Java
Cheat Sheet.
This cheat sheet will act as a crash course for Java beginners and help you with various fundamentals of Java.
javac className
public class Demo{ Finally, execute the program using below code:
public static void main(String[] args)
java className
{ System.out.println("Hello from
edureka!");}
}
Flow Of Control
Iterative Statements Decisive Statements
Iterative statements are used when you need to repeat a set Selection statements used when you need to choose
of statements until the condition for termination is not met. between alternative actions during execution of the program.
// for loop //if statement
for (condition) {expression} if (condition) {expression}
// for each loop //if-else statement
for (int i: someArray) {} if (condition) {expression} else {expression}
// while loop //switch statement
while (condition) {expression} switch (var)
// do while loop { case 1: expression; break; default:
do {expression} while(condition) expression; break; }
k = 2*n - 2; int factorial(int n)
for(i=0; i<n; i++) {
{ for(j=0; j<k; j++){System.out.print(" ");} if (n == 0)
k = k - 1; {return 1;}
for(j=0; j<=i; j++ ){System.out.print("* ");} else
System.out.println(); } {return(n * factorial(n-1));}
}
Java Arrays
Single Dimensional (1-D) Multi Dimensional (2-D)
Single Dimensional or 1-D array is a type of linear array in Two Dimensional or 2-D array is an array of an array where
which elements are stored in a continuous row. elements are stored in rows and columns.
// Initializing // Initializing
type[] varName= new type[size]; datatype[][] varName = new dataType[row]
[col];
// Declaring
type[] varName= new type[]{values1, // Declaring
value2,...}; datatype[][] varName = {{value1,
value2....},{value1, value2....}..};
Creating an array with random values.
Transposing a matrix.
double[] arr = new double[n];
for (int i=0; i<n; i++) for(i = 0; i < row; i++)
{a[i] = Math.random();} { for(j = 0; j < column; j++)
{ System.out.print(array[i][j]+" "); }
Searching the max value in the array. System.out.println(" ");
}
double max = 0;
for(int i=0; i<arr.length(); i++)
{ if(a[i] > max) max = a[i]; } Multiplying two matrices.
for (i = 0; i < row1; i++)
Reversing an array.
{ for (j = 0; j < col2; j++)
for(int i=0; i<(arr.length())/2; i++) { for (k = 0; k < row2; k++)
{ double temp = a[i]; { sum = sum + first[i][k]*second[k][j];
a[i] = a[n-1-i]; }
a[n-1-i] = temp; multiply[i][j] = sum;
} sum = 0;
}
}
Java Strings
Creating a String String Methods
String in Java is an object that represents a sequence of char Few of the most important and frequently used String
values. A String can be created in two ways: methods are listed below:
1. Using a literal
2. Using ‘new’ keyword str1==str2 //compares address;
String newStr = str1.equals(str2); //compares
String str1 = “Welcome”; // Using literal the values
String newStr = str1.equalsIgnoreCase()
String str2 = new String(”Edureka”); // Using //compares the values ignoring the case
new keyword newStr = str1.length() //calculates length
newStr = str1.charAt(i) //extract i'th
character
The java.lang.String class implements Serializable,
newStr = str1.toUpperCase() //returns string
Comparable and CharSequence interfaces. Since the String in ALL CAPS
object is immutable in nature Java provides two utility classes: newStr = str1.toLowerCase() //returns string
in ALL LOWERvCASE
1. StringBu er: It is a mutable class that is thread-safe and
newStr = str1.replace(oldVal, newVal)
synchronized.
//search and replace
2. StringBuilder: It is a mutable class that is not thread-safe
newStr = str1.trim() //trims surrounding
but is faster and is used in a single threaded
whitespace
environment.
newStr = str1.contains("value"); //check for
the values
newStr = str1.toCharArray(); // convert
String to character type array
newStr = str1.IsEmpty(); //Check for empty
String
newStr = str1.endsWith(); //Checks if string
ends with the given suffix
Hibernate Mapping on the Fly PHP and MySQL : Server Side Scripting Microsoft Sharepoint 2013 : The
For Web Development Ultimate Enterprise Collaboration
Platform
How To Implement Static Variable In Top Data Structures & Algorithms in How To Implement Java Composition
C? Java That You Need to Know In Depth?
2 Comments https://www.edureka.co/blog/
1 Login
Name
Ulan Yisaev
2 months ago
− ⚑
Thanks a lot!
△ ▽ Reply
Sunil Poudel
− ⚑
a year ago edited
I am searching this kind of stuff for years.... Now I found it. Many thanks.
△ ▽ Reply
ALSO ON HTTPS://WWW.EDUREKA.CO/BLOG/
AWS Snowball and Snowmobile Tutorial Cybersecurity Firewall: How Application Security Works?
1 comment • 3 months ago 1 comment • 3 months ago
Excelanto Cloud Systems — Excellent information with unique Hackers Guru — Before launching any app, the develop should
Avatarcontent and it is very useful to know about the information based Avatarconduct a penetration test to find vulnerabilites.
on blogs.
Top 75 Digital Marketing Interview Questions and … Android Services Tutorial : How to run an application in the …
2 comments • 3 months ago 1 comment • 3 months ago
Sam — Great content, very beneficial for me. Julia Johnson — It’s a Nice Blog and also Gets Complete
AvatarAlso read this blog for more such questions with answers Avatarinformation about android app. https://www.iqlance.com/new...
https://treehack.com/digita...
✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Disqus' Privacy PolicyPrivacy PolicyPrivacy
Java, J2EE & SOA Certi cation Training Python Scripting Certi cation Training
34k Enrolled Learners 8k Enrolled Learners Python Django Training and
Weekend Weekend
Certi cation
Live Class Self Paced 4k Enrolled Learners
Reviews Reviews Weekend
Live Class
4 (13500) 5 (2850)
Reviews
5 (1250)
Browse Categories
Arti cial Intelligence BI and Visualization Big Data Blockchain Cloud Computing Cyber Security Data Science
Data Warehousing and ETL Databases DevOps Digital Marketing Front End Web Development Mobile Development
Operating Systems Project Management and Methodologies Robotic Process Automation Software Testing Systems & Architecture
TRENDING CERTIFICATION COURSES TRENDING MASTERS COURSES
Big Data Hadoop Certi cation Training Cloud Architect Masters Program
Tableau Training & Certi cation Big Data Architect Masters Program
Python Certi cation Training for Data Science Machine Learning Engineer Masters Program
Selenium Certi cation Training Full Stack Web Developer Masters Program
Robotic Process Automation Training using UiPath Data Analyst Masters Program
Apache Spark and Scala Certi cation Training Test Automation Engineer Masters Program
Microsoft Power BI Training Post-Graduate Program in Arti cial Intelligence & Machine Learning
Online Java Course and Training Post-Graduate Program in Big Data Engineering
About us Careers
Community
DOWNLOAD APP
Sitemap
Blog Sitemap
Community Sitemap
Webinars
CATEGORIES
© 2019 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved. Terms & Conditions
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of
MongoDB, Inc.