Search This Blog

Loading...

Saturday, June 22, 2013

Git: The most commonly used git commands


On my daily bases working with git (DVCS), I found that the most common commands I am using every time are the following commands.

And I have made some aliases for some of them for eases of access and use; check this link on how to make aliases or shortcuts for your commands.

Command

Work description

add    

Add file contents to the index. When new or modified files are ready for the next commit, they must first be staged with the add command. Files can be staged one by one, by folder name, or by wildcard pattern.

bisect 

Find by binary search the change that introduced a bug

branch 

List, create, or delete branches

checkout

Checkout a branch or paths to the working tree

clone  

Clone a repository into a new directory

commit 

Once all desired files are added and staged, a commit command transactionally saves the pending additions to the local repository.

diff   

Show changes between commits, commit and working tree, etc

fetch  

Download objects and refs from another repository

grep   

Print lines matching a pattern

init

Create an empty Git repository or reinitialize an existing one

log    

Show commit logs

merge

Join two or more development histories together

mv

Move or rename a file, a directory, or a symlink

pull

Fetch from and merge with another repository or a local branch

push   

Update remote refs along with associated objects

rebase 

Rebasing is the rewinding of existing commits on a branch with the intent of moving the branch start point forward, then replaying the rewound commits. This allows developers to test their branch changes safely in isolation on their private branch just as if they were made on top of the mainline code, including any recent mainline bug fixes.

reset  

Reset current HEAD to the specified state

rm

Remove files from the working tree and from the index

show   

Show various types of objects

status 

Show the working tree status, and check the current status of a project’s local directories and files, such as modified, new, deleted, or untracked.

tag    

Git provides tagging to mark a specific commit in your timeline of changes, and serve as a useful identifier in history. A tag can be created for any commit in history by passing the commit hash. If no commit hash is provided, the most recent commit (i.e. HEAD) will be used by default.


For more information of each command and its related options, from command line on windows or terminal on Mac issue the following command

'git help ' to See more information on a specific command.

Friday, June 21, 2013

Mac: How to prevent your Mac from Sleeping !!!

While I am downloading, updating programs or even my Mac, after a while I found my Mac goes to sleep automatically even if it plugs to the power adapter.

The main problem here is that, the wireless network get interrupted and no more download in progress, unless I return it back from sleep mode.

There are 2 solutions for this issue:
  1. Changing the computer sleeping option from energy saving option under system preferences, as the following:
    From Mac general menu click on Mac icon → System preferences → Energy Saver → change your Computer sleep slider to “Never”, on battery and power adapter. (It doesn’t work for me). I will check and try other options I may miss.

  2. Use Caffeine program, it could be downloaded from Mac App store or from here, it's free application and very popular one.

I prefer the second option, mainly because there are times when I want my Mac book to sleep and don't want to keep changing the settings. Just one click of the coffee cup does it.
Caffeine

Caffeine is a tiny program that puts an icon in the right side of your menu bar. Click it to prevent your Mac from automatically going to sleep, dimming the screen or starting screen savers. Click it again to go back. Hold down the Command key while clicking to show the menu.

The menu now has a sub-menu for deactivating Caffeine automatically after a number of minutes.

Works just great. Computers need no sleep, people do.:)


Thursday, June 13, 2013

JEE: Java EE 7 (Glassfish v4.0) is out, putting the productivity at your hands.


My participation:

I am so proud of being part of Adopt-A-JSR program and my involvement in the testing, evaluating and evangelist JEE 7 JSRs and related technologies.
Alongside FishCAT program that target the enhancement and stabilizing Glassfish version 4.0.

Java EE 7 is out:

The most interesting and productive shipped with plumbing of cutting-edge (innovative) technology support; Java Enterprise Edition 7 (JEE 7) is out for public, as promised to be released in Q2 of 2013. The JSR 342 Java Platform, Enterprise Edition 7 could be downloaded from here.

Java EE 7 release is being designed with primary focus on the following features:

  1. Higher Productivity.
  2. HTML5 Support.

Alongside JEE 7 specification release, its modular and most efficient reference implementation application server Glassfish v4.0 is out for development of JEE 7 applications, and could be downloaded from glassfish.org web site. In addition, it is the world's first Java EE 7 Application Server.

Glassfish.org web site redesigned with new clear, fresh design as well. It looks very neat.

For release notes, it could be downloaded from here.

There are also many examples to get start, which could be found in documentation section.

Java EE 7 IDE is out:

For sake of development and get your hands dirt with JEE 7 specification that should be tested on Glassfish v4.0, there is a Netbeans 7.3.1 IDE, which includes support for JEE 7 full JSRs stack. It could be also downloaded from netbeans.org. Also, bear in mind that Netbeans JEE version includes Glassfish v4.0.

Consult the following page to see more IDEs (Integrated Development Environment) that supports Java EE 7 development: IDEs and plugins.

Try, Develop and have fun

As by now you have the JEE7 specification, Glassfish v4.0 and supported IDE Netbeans v7.3.1 (everything you need comes out-of-the-box without any plugin), so what are you waiting for, click to download and develop to get the feel of new smile of the technology.

Maven Development

For maven fans to develop a Java EE7 application here is the minimal POM pom.xml file:


For Java EE 7 Full Platform

For Java EE 7 Web Profile

For other Java EE 7 JSRs coordination, please visit Java EE 7 Maven Coordinates Wiki link.

Webcasts and Developer days

Besides the finished event "Java EE 7 Launch Webcast", there is another java developer day covering Java EE 7, SE, and Embedded named "Java Developer Day - June 25 - Java SE, Java EE & Java Embedded" that will be online at Tuesday, June 25, 2013, register here.

Tutorials and examples

Visit Java EE 7 Documentation: JEE 7 Tutorial, for full tutorials and examples on how to use the specification alongside its JSRs.

All my sessions, hacks and code contribution could be downloaded from this link under Adopt-A-JSR organization under Github Java EE 7 Hacks, codes and sessions.

Monday, June 10, 2013

Java: What is object deep copy and how it can be achieved in Java ?

If you need to copy and object, you can do it in Java using clone method that is member method of Object class, which is all objects parent class in Java. but wait, clone method performs a shallow copy not a deep copy.

In deep copy the object is copied along with the objects it refers to. Deep clone copies all the levels of the object from top to the bottom recursively.

When a deep copy of the object is done new references are created.

One solution is to simply implement your own custom method (e.g., deepCopy()) that returns a deep copy of an instance of one of your classes. This may be the best solution if you need a complex mixture of deep and shallow copies for different fields, but has a few significant drawbacks:
  1. You must be able to modify the class (i.e., have the source code) or implement a subclass.
  2. If you have a third-party class for which you do not have the source and which is marked final, you are out of luck.
  3. You must be able to access all of the fields of the classes superclasses. If significant parts of the objectes state are contained in private fields of a superclass, you will not be able to access them.
  4. You must have a way to make copies of instances of all of the other kinds of objects that the object references. This is particularly problematic if the exact classes of referenced objects cannot be known until runtime.

Disadvantages:
Custom deep copy methods are tedious to implement, easy to get wrong, and difficult to maintain. The method must be revisited any time a change is made to the class or to any of its superclasses.

Solution 2:

Other common solution to the deep copy problem is to use Java Object Serialization (JOS).
The idea is simple:
Write the object to an array using JOSes ObjectOutputStream and then use ObjectInputStream to reconsistute a copy of the object.

The result will be a completely distinct object, with completely distinct referenced objects.

Advantages
JOS takes care of all of the details: superclass fields, following object graphs, and handling repeated references to the same object within the graph.

Note:
It will only work when the object being copied, as well as all of the other objects references directly or indirectly by the object, are serializable. (In other words, they must implement java.io.Serializable.) Fortunately it is often sufficient to simply declare that a given class implements java.io.Serializable and let Javaes default serialization mechanisms do their thing.

Disadvantage:
Java Object Serialization is slow, and using it to make a deep copy requires both serializing and deserializing.

Enhancing JOS performance:
There are ways to speed it up (e.g., by pre-computing serial version ids and defining custom readObject() and writeObject() methods), but this will usually be the primary bottleneck. The byte array stream implementations included in the java.io package are designed to be general enough to perform reasonable well for data of different sizes and to be safe to use in a multi-threaded environment.

These characteristics, however, slow down ByteArrayOutputStream and (to a lesser extent) ByteArrayInputStream.

More References on this:
Deep Copy
Java Clone mechanism
Another "Deep copy" solutions and techniques.