Java Cheat Sheet Pdf Free Download

OOP

Encaps­ulation

Download Java Cheat Sheet app for Android. There is Java in your pocket! Learn Java gives you the basics of Java.

IMAP migration. /recover-my-file-with-serial-key.html.

The process of binding related classes, objects and operations together is called Encaps­ulationUsing access modifiers, packagesAbstra­ctionThe process of specifying what to do without specifying how to do itUsing abstract classes and interfacesInheri­tanceJava Cheat Sheet Pdf Free DownloadWhen one class inherits the properties of another classUsing Aggreg­ation, Compos­itionPolymo­rphismSame thing is done in different waysUsing compil­e-time and run-time polymo­rphism

Encaps­ulation

defaultaccessible to classes only in the same packagepublicaccessible to all classes in any packageprivateaccessible to only a specific method, or classprotectedaccessible to classes in the same package, and sub-cl­asses of this class

Abstra­ction

Abstract ClassWhen a class has one or more unimpl­emented methods, it should be declared abstract. The sub-cl­asses should provide implem­ent­ation for the unimpl­emented methods, else they should also be declared abstractUsed: When default implem­ent­ation is needed for some methods, and specific implem­ent­ations for other methods based on the class implem­enting themInterfaceBlueprint of a class. It contains only static, final variables and only unimpl­emented methods. Classes implement the interface should implement all methods of the interface, or be declared abstractUsed: to support multiple inheri­tanceAbstract classes don't support multiple inheri­tance, whereas interfaces do

Inheri­tance

Aggreg­ationWhen one class contains a reference of another classLoosely coupled classesAssoci­ationWhen one class is made up of another classTightly coupled classesJava does't support multiple inheri­tance directly, it supports it only via Interfaces

Polymo­rphism

Compil­e-timeAlso called overlo­ading. When methods have same name but different signature (retur­n-type, number of parame­ters, type of parameters etc)Run-timeAlso called overri­ding. When child-­classes over-write method implem­ent­ations of parent­-class.

static keyword

static fieldShared by all members of the class. It can be accessed before objects are created

Java Cheat Sheet Pdf Free Download 32-bit

static methodCan be accessed without creating an instance of the class. They can only access static variables and static methods. Cannot access this or superstatic blockUsed when some comput­ation is to be done to initialize the static variables. This block is executed once when the class is initially loaded into memorystatic classWe cannot declare top-level classes as static. Only inner classes can be static. A static class cannot access non-static members of the Outer class. It can access only static members of Outer class

final

fieldstreated as constantsmethodscannot be overridden by child classesclassesCheatcannot be inherited

finalize( )

finalize() method is a protected and non-static method of java.l­ang.Object class. This method will be available in all objects you create in java. This method is used to perform some final operations or clean up operations on an object before it is removed from the memory

String Creation

Literal : String s = ' 'Creates Strings in String pool, in JVM. Multiple strings can have same value. Only one copy of the word exists in the String pool, and the references of it are updated.Object: String s = new String( );Creates a string object in heap. The heap in-turn checks the JVM String Pool to see if there exists a string with same value.String s1 = '­abc­';
String s2 = '­abc­';
s1 s2 returns true;
­­­­
String s1 = new String­('ab­c');
String s2 = new String­('ab­c');
s1 s2 returns false;
But s1.equ­als(s2) returns true;

String Immuta­bility

Strings in java are immutable because changing the value of a String literal changes the value of other Strings that reference the literal, which leads to incons­istency in the program. To prevent this, strings in java are immutable.

Storing passwords in Strings

It is best to store passwords as char[ ] because if passwords are stored as Strings, the string tends to be in the JVM pool even after all references to it no longer exist. This causes a vulner­ability in the system. In case of Char[ ], once all the references to char[ ] are gone, the Java Garbage Collector deletes the char[ ] to preserve memory. So, it's safer.

String­Bui­lder, String­Buffer

String­BuilderTo create mutable strings in JavaString­BufferTo create thread­-safe mutable strings in Java

String methods

s.char­At(int index)s.comp­are­To(s2), s.comp­are­ToI­gno­reC­ase(s2)s.conc­at(s2)s.cont­ain­s(s­equence of charac­ters)s.equa­ls(s2), s.equa­lsI­gno­reC­ase(s2)s.length()s.repl­ace­(ch­ara­cter, replac­ement) )s.repl­ace­All­(ch­ara­cter, replac­ement)s.subS­tri­ng(int startI­ndex)s.subS­tri­ng(int startI­ndex, int endIndex)s.toUp­per­Case( ), s.toLo­wer­Case( )s.toCh­arA­rray()s.trim( )String s = String.va­lue­Of(int, or long or double)String[] s1 = s.split( String regex)String[] s1 = s.spli­t(S­tring regex, int limit )

String­Buffer, Stribg­Builder methods

s.appe­nd(s2)s.dele­teC­har­At(int index)s.inde­xOf­(string ), s.inde­xOf­(st­ring, fromIndex)s.inse­rt(int index, object­Value)s.repl­ace(int startI­ndex, int endIndex, String)

Java Cheat Sheet Pdf Free Download Version

s.reverse( )s.toSt­ring( )s.trim­ToSize( )s.setC­har­At(int index, charSe­quence)