Java ProgrammingJava Cheat Sheets

Java Cheat Sheets

In this article we will study the Java Cheat_Sheets that will help to review, recollect and memorize the syntaxes of Java, key aspects of Java like formatted output, collections, regular expressions, etc..

To study the cheat sheets of java go through the syntax’s given below:

    1. Writing packages:
Package package_path.package_name;
    1. What are different types of Java Extension Packages:
Import <class>

 

      • Java Packages are given below:

 

        1. java.applet : Applets (Consists of Java program’s that runs inside a webpage)

 

        1. java.awt : It supports graphics and graphical user interfaces

 

        1. java.beans : Support for JavaBeans components i.e. classes with properties and event listeners.

 

        1. java.io : Supports Input and Output

 

        1. java.lang : It provides Language support.

 

        1. java.net : Networking

 

        1. java.rmi : Allows Remote method Invocations

 

        1. java.sql : Provides database support

 

        1. java.text : Supports internationalized formatting of text and numbers

 

        1. java.util : Provides Utilities which includes data structures, concurrency,etc..

 

 

    1. Writting comments in java

 

      • // is used for writing Single Line Comment.

 

      • /* is used for multiple line comment */

 

    1. Data types in Java

 

      • int -> consists of integer set of values.

 

      • double -> consists of floating – point numbers

 

      • boolean -> Boolean values like && || ! true false

 

      • char – > It is character set of values

 

      • String -> It has sequence of characters like “AB” “Hello” “2.5”

 

    1. Comparison operators in Java

 

comparison

 

    1. Creating new object instance
StringBuffer buffer = new StringBuffer(130);
    1. Printing a String to standard output
System.out.println("Some string");
    1. Creating a new object using generic types (array list that holds strings)
ArrayList<String> list = new ArrayList<String>();
    1. Sample code structure in Java
public class HelloWorld                       // HelloWorld class name
{
	Public static void main(String[] args)    // main() method
{
	System.out.println(“Hello,World”);    //Statement 
}
}
    1. Input and Output functioning in java

 

compiling process

 

    1. Incremental / Decremental Operators

 

      • ++X = PreIncrement Operator

 

      • X++ = PostIncrement Operator

 

      • –X = PreDecrement Operator

 

      • X– = PostDecrement Operator

 

    1. Escapes Sequences in java

 

      • \n = is used for new line

 

      • \t = is used for horizontal tab

 

      • \r = It is for carriage return

 

      • \\ = It is backslash

 

    1. If Else syntax in java
If(<Condition>)
{
	<statement(s)>;
}
else
{
	<statement(s)>;
}
    1. Implementing Switch Case in java
Switch(<expression>)
{
	case <option 1>: <statement>;
				break;
	case <option 2>: <statement>;
				break;
	[default: <statement>;]
}
    1. Loops in java

 

      • For Loop
for(<initial value>;<condition>;<increment / decrement>)
{
	<statement(s)>;
}
      • While Loop
while(<condition>)
{
	<statement(s)>;
}
      • Do While Loop
do
{
	<statement(s)>;
}while(<condition>);

 

    1. Writing class in java
<access modifier> <return data type> <class name> [extends <superclass name>][implements <interface name>]
{
	<declarations>
<methods>
}
    1. Exception handling in java
try
{
	// Code,can include method calls
}
catch(Exception e)
{
	//if error is caught what is to be done is written here.  
}
finally
{
	// this code is executed with or without an error	
}
    1. Arrays in Java

 

      • Declaring and allocating an array in one
int a[] = new int[4];
      • Declaring and allocating in two
int yourArray[]; 

//Initialization of array:
yourArray = {10,20,30,40};

//Accessing the second element from it :
YourArray[1] = var;

 

    1. File IO in Java

 

      • Read in a Text File
//should be contained in a try catch block
BufferedReader in  = new BufferedReader(new FileReader(directory.getPath()));
//directory is a file object
String nextLine = in.readLine();  //reads first line, repeat for the next line
in.close();
      • Write to Text File
//Should be contained in try catch block
DataOutputStream out = new DataOutputStream(new FileOutputStream(yourfile.dat));
// creates yourfile.dat, can add directory
out.writeUTF(theText); // write string object theText
out.close();

Thus, these are the basic Java Cheat_Sheets which will help and guide you as a quick references of Java syntax’s. It will be effective in many different ways if you master it right. If you are given any Java assignment and if you are not familiar with the Java syntax’s it will prove very beneficial and a quick guide for beginners.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article

21,501FansLike
4,106FollowersFollow
106,000SubscribersSubscribe

More article

- Advertisement -